Skip to content

Commit 8ef160f

Browse files
protection-atomic: Properly handle unlock of atomicity mutex
1 parent 4b5a654 commit 8ef160f

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/analyses/basePriv.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ struct
996996
let atomic = Param.handle_atomic && LockDomain.MustLock.equal m (LockDomain.MustLock.of_var LibraryFunctions.verifier_atomic_var) in
997997
(* TODO: what about G_m globals in cpa that weren't actually written? *)
998998
CPA.fold (fun x v (st: BaseComponents (D).t) ->
999-
if is_protected_by ask m x then ( (* is_in_Gm *)
999+
if (atomic && is_global ask x && not (VD.is_immediate_type x.vtype)) || is_protected_by ask m x then ( (* is_in_Gm *)
10001000
(* Only apply sides for values that were actually written to globals!
10011001
This excludes invariants inferred through guards. *)
10021002
begin match D.precise_side x v st.priv with
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// PARAM: --disable warn.race --enable ana.sv-comp.functions --set ana.path_sens[+] threadflag --set lib.activated[+] sv-comp --set ana.base.privatization protection-atomic
2+
#include<pthread.h>
3+
#include<stdlib.h>
4+
#include<goblint.h>
5+
extern void __VERIFIER_atomic_begin();
6+
extern void __VERIFIER_atomic_end();
7+
8+
int g;
9+
10+
void fun() {
11+
g = 1;
12+
}
13+
14+
int main(void) {
15+
pthread_t thread;
16+
pthread_create(&thread, NULL, (void*)fun, NULL);
17+
18+
__VERIFIER_atomic_begin();
19+
g = 1;
20+
__VERIFIER_atomic_end();
21+
22+
g = 5;
23+
__goblint_check(g <= 1); //UNKNOWN!
24+
25+
26+
return 0;
27+
}

0 commit comments

Comments
 (0)