Skip to content

Commit 0c19762

Browse files
protection-atomic: Properly handle unlock of atomicity mutex
1 parent 48007a8 commit 0c19762

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
@@ -980,7 +980,7 @@ struct
980980
let atomic = Param.handle_atomic && LockDomain.MustLock.equal m (LockDomain.MustLock.of_var LibraryFunctions.verifier_atomic_var) in
981981
(* TODO: what about G_m globals in cpa that weren't actually written? *)
982982
CPA.fold (fun x v (st: BaseComponents (D).t) ->
983-
if is_protected_by ask m x then ( (* is_in_Gm *)
983+
if (atomic && is_global ask x && not (VD.is_immediate_type x.vtype)) || is_protected_by ask m x then ( (* is_in_Gm *)
984984
(* Only apply sides for values that were actually written to globals!
985985
This excludes invariants inferred through guards. *)
986986
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)