Skip to content

Commit cb09957

Browse files
author
Simon Tietz
committed
todo: starting at valueDomain.ml (email), wtf should I do in cfgtools
1 parent a75b931 commit cb09957

File tree

7 files changed

+34
-48
lines changed

7 files changed

+34
-48
lines changed

src/analyses/accessAnalysis.ml

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

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

3030
let init _ =
31-
ignore_asm := get_bool "asm_is_nop";
3231
collect_local := get_bool "witness.yaml.enabled" && get_bool "witness.invariant.accessed";
3332
let activated = get_string_list "ana.activated" in
3433
emit_single_threaded := List.mem (ModifiedSinceSetjmp.Spec.name ()) activated || List.mem (PoisonVariables.Spec.name ()) activated
@@ -76,11 +75,12 @@ struct
7675
end
7776

7877
let asm ctx =
79-
if not !ignore_asm then begin
78+
if not ignore_asm then begin
8079
let ins, outs = Analyses.asm_extract_ins_outs ctx in
8180
let handle_in exp = access_one_top ctx Read false exp in
8281
List.iter handle_in ins;
83-
let handle_out lval = access_one_top ctx Write false (AddrOf lval) in
82+
(* deref needs to be set to true because we have to use AddrOf *)
83+
let handle_out lval = access_one_top ~deref:true ctx Write false (AddrOf lval) in
8484
List.iter handle_out outs;
8585
end;
8686
ctx.local

src/analyses/base.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,9 +2889,13 @@ struct
28892889
in
28902890
D.join ctx.local e_d'
28912891

2892+
let ignore_asm = get_bool "asm_is_nop"
2893+
28922894
let asm ctx =
2893-
let _, outs = Analyses.asm_extract_ins_outs ctx in
2894-
ctx.emit (Events.Invalidate {lvals=outs});
2895+
if not ignore_asm then begin
2896+
let _, outs = Analyses.asm_extract_ins_outs ctx in
2897+
ctx.emit (Events.Invalidate {lvals=outs});
2898+
end;
28952899
ctx.local
28962900

28972901
let event ctx e octx =

src/analyses/malloc_null.ml

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

20-
let ignore_asm = ref true
21-
22-
(*TODO: why is this init not called??? *)
23-
let init _ =
24-
ignore_asm := get_bool "asm_is_nop"
20+
let ignore_asm = get_bool "asm_is_nop"
2521

2622
(*
2723
Addr set functions:
@@ -161,9 +157,7 @@ struct
161157
| _ -> ctx.local
162158

163159
let asm ctx =
164-
(* tmp hack because init is broken *)
165-
let ignore_asm = ref (get_bool "asm_is_nop") in
166-
if not !ignore_asm then begin
160+
if not ignore_asm then begin
167161
let ins, outs = Analyses.asm_extract_ins_outs ctx in
168162
let handle_in exp = warn_deref_exp (Analyses.ask_of_ctx ctx) ctx.local exp in
169163
List.iter handle_in ins;

src/analyses/modifiedSinceSetjmp.ml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,6 @@ struct
6767
match e with
6868
| Access {ad; kind = Write; _} ->
6969
add_to_all_defined (relevants_from_ad ad) ctx.local
70-
| Invalidate {lvals} ->
71-
let lval_to_vs lval =
72-
let e = AddrOf lval in
73-
let mpt: _ Queries.t = MayPointTo e in
74-
let ad = ctx.ask mpt in
75-
relevants_from_ad ad in
76-
let vss = List.map lval_to_vs lvals in
77-
List.fold_left (fun d vs -> add_to_all_defined vs d) ctx.local vss
7870
| _ ->
7971
ctx.local
8072
end

src/analyses/uninit.ml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ 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 = ref true
34-
35-
let init _ =
36-
ignore_asm := get_bool "asm_is_nop"
33+
let ignore_asm = get_bool "asm_is_nop"
3734

3835
let access_address (ask: Queries.ask) write lv =
3936
match ask.f (Queries.MayPointTo (AddrOf lv)) with
@@ -230,11 +227,13 @@ struct
230227
init_lval (Analyses.ask_of_ctx ctx) lval ctx.local
231228

232229
let asm ctx =
233-
let ins, outs = Analyses.asm_extract_ins_outs ctx in
234-
let handle_in exp = ignore (is_expr_initd (Analyses.ask_of_ctx ctx) exp ctx.local) in
235-
List.iter handle_in ins;
236-
let handle_out local lval = init_lval (Analyses.ask_of_ctx ctx) lval local in
237-
List.fold_left handle_out ctx.local outs
230+
if not ignore_asm then begin
231+
let ins, outs = Analyses.asm_extract_ins_outs ctx in
232+
let handle_in exp = ignore (is_expr_initd (Analyses.ask_of_ctx ctx) exp ctx.local) in
233+
List.iter handle_in ins;
234+
let handle_out local lval = init_lval (Analyses.ask_of_ctx ctx) lval local in
235+
List.fold_left handle_out ctx.local outs
236+
end else ctx.local
238237

239238
let branch ctx (exp:exp) (tv:bool) : trans_out =
240239
ignore (is_expr_initd (Analyses.ask_of_ctx ctx) exp ctx.local);

src/analyses/useAfterFree.ml

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

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

3330
let context _ _ = ()
3431
(* HELPER FUNCTIONS *)
@@ -176,7 +173,7 @@ struct
176173
ctx.local
177174

178175
let asm ctx =
179-
if not !ignore_asm then begin
176+
if not ignore_asm then begin
180177
let ins, outs = Analyses.asm_extract_ins_outs ctx in
181178
let handle_out lval = warn_lval_might_contain_freed "asm" ctx lval in
182179
List.iter handle_out outs;

src/common/framework/cfgTools.ml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ end
141141

142142
module CfgEdgeH = BatHashtbl.Make (CfgEdge)
143143

144-
let ignore_asm = get_bool "asm_is_nop"
145-
146144
let createCFG (file: file) =
147145
let cfgF = H.create 113 in
148146
let cfgB = H.create 113 in
@@ -378,19 +376,21 @@ let createCFG (file: file) =
378376

379377
| Asm (_, tmpls, outs, ins, _, labels, loc) ->
380378
begin match real_succs () with
381-
| [] -> failwith "MyCFG.createCFG: 0 Asm succ"
382-
| [succ, skippedStatements] -> begin
379+
| [] -> failwith "MyCFG.createCFG: 0 Asm succ"
380+
| [succ, skippedStatements] -> begin
383381
addEdge ~skippedStatements (Statement stmt) (loc, ASM(tmpls, outs, ins, false)) (Statement succ);
384-
if not ignore_asm then
385-
List.iter (fun label ->
386-
let succ, skippedStatements = find_real_stmt ~parent:stmt !label in
387-
addEdge ~skippedStatements (Statement stmt) (loc, ASM(tmpls, outs, ins, true)) (Statement succ)
388-
) labels
389-
else ()
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;
390391
end
391-
| _ -> failwith "MyCFG.createCFG: >1 Asm succ"
392+
| _ -> failwith "MyCFG.createCFG: >1 Asm succ"
392393
end
393-
394394
| Continue _
395395
| Break _
396396
| Switch _ ->

0 commit comments

Comments
 (0)