Skip to content

Commit 63a8c09

Browse files
authored
Merge pull request #2026 from goblint/issue-2025
`protection-atomic`: Properly handle unlock of atomicity mutex
2 parents 7af6964 + fa03a19 commit 63a8c09

2 files changed

Lines changed: 29 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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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(void* arg) {
11+
g = 1;
12+
return NULL;
13+
}
14+
15+
int main(void) {
16+
pthread_t thread;
17+
pthread_create(&thread, NULL, fun, NULL);
18+
19+
__VERIFIER_atomic_begin();
20+
g = 1;
21+
__VERIFIER_atomic_end();
22+
23+
g = 5;
24+
__goblint_check(g <= 1); //UNKNOWN!
25+
26+
27+
return 0;
28+
}

0 commit comments

Comments
 (0)