Skip to content

Commit 4e30a22

Browse files
Merge pull request #1720 from goblint/issue_1719
`IsMultiple` in `MallocWrapper`: Check uniqueness of allocating(!) thread
2 parents 215cb1d + 72149dd commit 4e30a22

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/analyses/wrapperFunctionAnalysis.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ module MallocWrapper : MCPSpec = struct
171171
NodeVarinfoMap.mem_varinfo v
172172
| Q.IsMultiple v ->
173173
begin match NodeVarinfoMap.from_varinfo v with
174-
| Some (_, _, c) -> UniqueCount.is_top c || not (man.ask Q.MustBeUniqueThread)
174+
| Some (t, _, c) -> UniqueCount.is_top c ||
175+
(match t with
176+
| `Lifted tid -> not (Thread.is_unique tid)
177+
| _ -> true)
175178
| None -> false
176179
end
177180
| _ -> Queries.Result.top q
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// PARAM: --set ana.malloc.unique_address_count 3
2+
#include<pthread.h>
3+
static int iRThreads = 1;
4+
static int data1Value = 0;
5+
pthread_mutex_t *data1Lock;
6+
7+
void *funcA(void *param) {
8+
pthread_mutex_lock(data1Lock);
9+
data1Value = 1; //NORACE
10+
pthread_mutex_unlock(data1Lock);
11+
}
12+
13+
int main(int argc, char *argv[]) {
14+
data1Lock = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
15+
16+
pthread_t one;
17+
pthread_t other[3];
18+
19+
pthread_create(&one, ((void *)0), &funcA, ((void *)0));
20+
21+
for (int i = 0; i < 3; i++) {
22+
pthread_create(&other[i], ((void *)0), &funcA, ((void *)0));
23+
}
24+
25+
return 0;
26+
}

0 commit comments

Comments
 (0)