Skip to content

IsMultiple in MallocWrapper: Check uniqueness of allocating(!) thread #1720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/analyses/wrapperFunctionAnalysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ module MallocWrapper : MCPSpec = struct
NodeVarinfoMap.mem_varinfo v
| Q.IsMultiple v ->
begin match NodeVarinfoMap.from_varinfo v with
| Some (_, _, c) -> UniqueCount.is_top c || not (man.ask Q.MustBeUniqueThread)
| Some (t, _, c) -> UniqueCount.is_top c ||
(match t with
| `Lifted tid -> not (Thread.is_unique tid)
| _ -> true)
| None -> false
end
| _ -> Queries.Result.top q
Expand Down
26 changes: 26 additions & 0 deletions tests/regression/11-heap/17-unique-mt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// PARAM: --set ana.malloc.unique_address_count 3
#include<pthread.h>
static int iRThreads = 1;
static int data1Value = 0;
pthread_mutex_t *data1Lock;

void *funcA(void *param) {
pthread_mutex_lock(data1Lock);
data1Value = 1; //NORACE
pthread_mutex_unlock(data1Lock);
}

int main(int argc, char *argv[]) {
data1Lock = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));

pthread_t one;
pthread_t other[3];

pthread_create(&one, ((void *)0), &funcA, ((void *)0));

for (int i = 0; i < 3; i++) {
pthread_create(&other[i], ((void *)0), &funcA, ((void *)0));
}

return 0;
}
Loading