Skip to content

Commit 4ceb035

Browse files
Merge pull request #984 from goblint/issue-939
Handle escaping in `varEq` analysis
2 parents 5b9a130 + 50f26f8 commit 4ceb035

3 files changed

Lines changed: 63 additions & 1 deletion

File tree

src/analyses/varEq.ml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ struct
336336
| Imag _ -> None
337337
| Const _ -> Some false
338338
| Lval (Var v,_) ->
339-
Some (v.vglob || (ask.f (Queries.IsMultiple v)))
339+
Some (v.vglob || (ask.f (Queries.IsMultiple v) || BaseUtil.is_global ask v))
340340
| Lval (Mem e, _) ->
341341
begin match ask.f (Queries.MayPointTo e) with
342342
| ls when not (Queries.LS.is_top ls) && not (Queries.LS.mem (dummyFunDec.svar, `NoOffset) ls) ->
@@ -558,6 +558,15 @@ struct
558558
|> List.fold_left (fun st lv ->
559559
remove (Analyses.ask_of_ctx ctx) lv st
560560
) ctx.local
561+
| Events.Escape vars ->
562+
if EscapeDomain.EscapedVars.is_top vars then
563+
D.top ()
564+
else
565+
let ask = Analyses.ask_of_ctx ctx in
566+
let remove_var st v =
567+
remove ask (Cil.var v) st
568+
in
569+
List.fold_left remove_var ctx.local (EscapeDomain.EscapedVars.elements vars)
561570
| _ ->
562571
ctx.local
563572
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//PARAM: --set ana.activated[+] var_eq
2+
#include <goblint.h>
3+
#include <pthread.h>
4+
#include <unistd.h>
5+
int g;
6+
7+
void *t_fun1(void *arg) {
8+
int *zptr = (int*) arg;
9+
int* gptr = &g;
10+
11+
*zptr = 42;
12+
*gptr = 42;
13+
sleep(10);
14+
// here the other thread (id2) could potentially change *zptr, as it is linked to the same int z
15+
__goblint_check(*zptr == 42); //UNKNOWN!
16+
__goblint_check(*gptr == 42); //UNKNOWN!
17+
return NULL;
18+
}
19+
20+
int main() {
21+
pthread_t id1;
22+
int z = 8;
23+
24+
pthread_create(&id1, NULL, t_fun1, &z);
25+
z = 8;
26+
g = 8;
27+
pthread_join (id1, NULL);
28+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//PARAM: --set ana.activated[+] var_eq
2+
#include <goblint.h>
3+
#include <pthread.h>
4+
#include <unistd.h>
5+
int g;
6+
7+
void *t_fun1(void *arg) {
8+
int** ptrptr = (int**) arg;
9+
int* iptr = *ptrptr;
10+
11+
*iptr = 12;
12+
}
13+
14+
int main() {
15+
pthread_t id1;
16+
int z = 8;
17+
int i;
18+
int* zptr = &z;
19+
20+
int j = i;
21+
pthread_create(&id1, NULL, t_fun1, &zptr);
22+
zptr = &i;
23+
__goblint_check(i == j); //UNKNOWN!
24+
pthread_join (id1, NULL);
25+
}

0 commit comments

Comments
 (0)