Skip to content

Commit a3bd48a

Browse files
author
Simon Tietz
committed
tests
1 parent c1fa1f5 commit a3bd48a

File tree

9 files changed

+98
-20
lines changed

9 files changed

+98
-20
lines changed

src/analyses/accessAnalysis.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ struct
2525

2626
let collect_local = ref false
2727
let emit_single_threaded = ref false
28-
let ignore_asm = get_bool "asm_is_nop"
28+
let ignore_asm = ref true
2929

3030
let init _ =
31+
ignore_asm := get_bool "asm_is_nop";
3132
collect_local := get_bool "witness.yaml.enabled" && get_bool "witness.invariant.accessed";
3233
let activated = get_string_list "ana.activated" in
3334
emit_single_threaded := List.mem (ModifiedSinceSetjmp.Spec.name ()) activated || List.mem (PoisonVariables.Spec.name ()) activated
@@ -75,7 +76,7 @@ struct
7576
end
7677

7778
let asm ctx =
78-
if not ignore_asm then begin
79+
if not !ignore_asm then begin
7980
let ins, outs = Analyses.asm_extract_ins_outs ctx in
8081
let handle_in exp = access_one_top ctx Read false exp in
8182
List.iter handle_in ins;

src/analyses/base.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct
8282
let name () = "base"
8383
let startstate v: store = { cpa = CPA.bot (); deps = Dep.bot (); weak = WeakUpdates.bot (); priv = Priv.startstate ()}
8484
let exitstate v: store = { cpa = CPA.bot (); deps = Dep.bot (); weak = WeakUpdates.bot (); priv = Priv.startstate ()}
85+
let ignore_asm = ref true
8586

8687
(**************************************************************************
8788
* Helpers
@@ -160,6 +161,7 @@ struct
160161
end;
161162
return_varstore := Cilfacade.create_var @@ makeVarinfo false "RETURN" voidType;
162163
longjmp_return := Cilfacade.create_var @@ makeVarinfo false "LONGJMP_RETURN" intType;
164+
ignore_asm := get_bool "asm_is_nop";
163165
Priv.init ()
164166

165167
let finalize () =
@@ -2889,10 +2891,8 @@ struct
28892891
in
28902892
D.join ctx.local e_d'
28912893

2892-
let ignore_asm = get_bool "asm_is_nop"
2893-
28942894
let asm ctx =
2895-
if not ignore_asm then begin
2895+
if not !ignore_asm then begin
28962896
let _, outs = Analyses.asm_extract_ins_outs ctx in
28972897
ctx.emit (Events.Invalidate {lvals=outs});
28982898
end;

src/analyses/malloc_null.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ struct
1717
module C = ValueDomain.AddrSetDomain
1818
module P = IdentityP (D)
1919

20-
let ignore_asm = get_bool "asm_is_nop"
20+
let ignore_asm = ref true
21+
22+
let init _ =
23+
ignore_asm := get_bool "asm_is_nop"
2124

2225
(*
2326
Addr set functions:
@@ -157,7 +160,7 @@ struct
157160
| _ -> ctx.local
158161

159162
let asm ctx =
160-
if not ignore_asm then begin
163+
if not !ignore_asm then begin
161164
let ins, outs = Analyses.asm_extract_ins_outs ctx in
162165
let handle_in exp = warn_deref_exp (Analyses.ask_of_ctx ctx) ctx.local exp in
163166
List.iter handle_in ins;

src/analyses/uninit.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ struct
3030
let threadspawn ctx ~multiple lval f args fctx = ctx.local
3131
let exitstate v : D.t = D.empty ()
3232

33-
let ignore_asm = get_bool "asm_is_nop"
33+
let ignore_asm = ref true
34+
35+
let init _ =
36+
ignore_asm := get_bool "asm_is_nop"
3437

3538
let access_address (ask: Queries.ask) write lv =
3639
match ask.f (Queries.MayPointTo (AddrOf lv)) with
@@ -227,7 +230,7 @@ struct
227230
init_lval (Analyses.ask_of_ctx ctx) lval ctx.local
228231

229232
let asm ctx =
230-
if not ignore_asm then begin
233+
if not !ignore_asm then begin
231234
let ins, outs = Analyses.asm_extract_ins_outs ctx in
232235
let handle_in exp = ignore (is_expr_initd (Analyses.ask_of_ctx ctx) exp ctx.local) in
233236
List.iter handle_in ins;

src/analyses/useAfterFree.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ struct
2525
module G = ThreadIdToJoinedThreadsMap
2626
module V = VarinfoV
2727

28-
let ignore_asm = get_bool "asm_is_nop"
28+
let ignore_asm = ref true
29+
30+
let init _ =
31+
ignore_asm := get_bool "asm_is_nop"
2932

3033
let context _ _ = ()
3134
(* HELPER FUNCTIONS *)
@@ -173,7 +176,7 @@ struct
173176
ctx.local
174177

175178
let asm ctx =
176-
if not ignore_asm then begin
179+
if not !ignore_asm then begin
177180
let ins, outs = Analyses.asm_extract_ins_outs ctx in
178181
let handle_out lval = warn_lval_might_contain_freed "asm" ctx lval in
179182
List.iter handle_out outs;

src/common/framework/cfgTools.ml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,16 @@ let createCFG (file: file) =
379379
| [] -> failwith "MyCFG.createCFG: 0 Asm succ"
380380
| [succ, skippedStatements] -> begin
381381
addEdge ~skippedStatements (Statement stmt) (loc, ASM(tmpls, outs, ins, false)) (Statement succ);
382-
let unique_dests = List.fold_left (fun acc label ->
383-
let succ, skippedStatements = find_real_stmt ~parent:stmt !label in
384-
match List.assoc_opt succ acc with
385-
| Some _ -> acc
386-
| None -> (succ, skippedStatements) :: acc
387-
) [] labels in
388-
List.iter (fun (succ, skippedStatements) ->
389-
addEdge ~skippedStatements (Statement stmt) (loc, ASM(tmpls, outs, ins, true)) (Statement succ)
390-
) unique_dests;
382+
if not (get_bool "asm_is_nop") then
383+
let unique_dests = List.fold_left (fun acc label ->
384+
let succ, skippedStatements = find_real_stmt ~parent:stmt !label in
385+
match List.assoc_opt succ acc with
386+
| Some _ -> acc
387+
| None -> (succ, skippedStatements) :: acc
388+
) [] labels in
389+
List.iter (fun (succ, skippedStatements) ->
390+
addEdge ~skippedStatements (Statement stmt) (loc, ASM(tmpls, outs, ins, true)) (Statement succ)
391+
) unique_dests;
391392
end
392393
| _ -> failwith "MyCFG.createCFG: >1 Asm succ"
393394
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//PARAM: --disable asm_is_nop
2+
#include <goblint.h>
3+
4+
int main(void) {
5+
int x = 0;
6+
asm ("nop" : "=x" (x));
7+
__goblint_check(x == 0); //WARN
8+
return 0;
9+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//PARAM: --set ana.activated[+] deadlock --disable asm_is_nop
2+
#include <unistd.h>
3+
#include <pthread.h>
4+
#include <stdio.h>
5+
#include <goblint.h>
6+
7+
pthread_mutex_t lock_a;
8+
pthread_mutex_t lock_b;
9+
10+
extern __goblint_unknown(void*);
11+
12+
void *proc_a(void *arg) {
13+
asm ("nop" : "=g" (lock_a));
14+
__goblint_unknown(&lock_a);
15+
pthread_mutex_lock(&lock_a);
16+
sleep(1);
17+
pthread_mutex_lock(&lock_b);
18+
pthread_exit(NULL);
19+
}
20+
21+
void *proc_b(void *arg) {
22+
pthread_mutex_lock(&lock_b);
23+
sleep(1);
24+
pthread_mutex_lock(&lock_a);
25+
return NULL;
26+
}
27+
28+
int main(void) {
29+
int x;
30+
pthread_t a, b;
31+
pthread_create(&a, NULL, proc_a, NULL);
32+
proc_b(NULL);
33+
// this will remove lock_a from must_lockset
34+
puts("no deadlock!");
35+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak --disable asm_is_nop
2+
#include <stdlib.h>
3+
4+
void ok(void) {
5+
char *x = malloc(64);
6+
char *y = x;
7+
asm ("nop" : "=x" (x));
8+
free(y);
9+
return; //NOWARN
10+
}
11+
12+
void not_ok(void) {
13+
char *x = malloc(64);
14+
asm ("nop" : "=x" (x));
15+
free(x);
16+
return; //WARN
17+
}
18+
19+
int main(void) {
20+
ok();
21+
not_ok();
22+
return 0;
23+
}

0 commit comments

Comments
 (0)