Skip to content

Commit adae595

Browse files
committed
Modular: Fix handling of globals for new style of combine in Base.
1 parent 04fe716 commit adae595

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

src/analyses/base.ml

+21-21
Original file line numberDiff line numberDiff line change
@@ -2953,7 +2953,7 @@ struct
29532953
module AddrPairSet = Set.Make (AddrPair)
29542954

29552955
(** In the given local state, from the start state, find the addresses that correspond to the goals *)
2956-
let collect_targets_with_graph ctx (graph: Graph.t) (args: exp list) (params: varinfo list) (goal: AD.t) =
2956+
let collect_targets_with_graph ctx (graph: Graph.t) (args: exp list) (params: varinfo list) (globals: varinfo list) (goal: AD.t) =
29572957
let ask = Analyses.ask_of_ctx ctx in
29582958

29592959
(* TODO: !! Pass addresses instead of params, or, alternatively, pass global variables separetely, as they should be !! *)
@@ -2994,6 +2994,16 @@ struct
29942994
) dir_reachable_abs;
29952995
) combined;
29962996

2997+
(* Add globals *)
2998+
let add_global_to_queue (g: varinfo) =
2999+
let a_c = Addr.of_var ~is_modular:false g in
3000+
let a = Addr.of_var ~is_modular:true g in
3001+
3002+
Queue.add (a_c, a) queue;
3003+
visited := AddrPairSet.add (a_c, a) !visited;
3004+
in
3005+
List.iter add_global_to_queue globals;
3006+
29973007
(* M.tracel "modular_combine" "Initalized conc: %a\n" (d_list ", " ADOffsetMap.pretty) (List.map Tuple2.first combined);
29983008
M.tracel "modular_combine" "Initalized abs: %a\n" (d_list ", " ADOffsetMap.pretty) (List.map Tuple2.second combined);
29993009
M.tracel "modular_combine" "graph: %a\n" Graph.pretty graph; *)
@@ -3021,14 +3031,15 @@ struct
30213031
let combine_env_modular ctx lval fexp f args fc au (f_ask: Queries.ask) =
30223032
let ask = Analyses.ask_of_ctx ctx in
30233033
let glob_fun = modular_glob_fun ctx in
3024-
let callee_globals_exp = UsedGlobals.get_used_globals f_ask in
3034+
(* let callee_globals_exp = UsedGlobals.get_used_globals f_ask in *)
30253035
let callee_globals = UsedGlobals.get_used_globals f_ask in
3026-
let callee_globals = List.map (fun v -> Lval (Var v, NoOffset)) callee_globals in
3036+
(* let callee_globals = List.map (fun v -> Lval (Var v, NoOffset)) callee_globals in *)
30273037

3028-
let effective_params = f.sformals @ callee_globals_exp in
3029-
let effective_args = args @ callee_globals in
3038+
let params = f.sformals in
3039+
(* let effective_params = params in
3040+
let effective_args = args in *)
30303041

3031-
M.tracel "modular_combine" "effective_params: %a\n effective_args: %a\n" (d_list ", " CilType.Varinfo.pretty) effective_params (d_list ", " CilType.Exp.pretty) effective_args;
3042+
(* M.tracel "modular_combine" "effective_params: %a\n effective_args: %a\n" (d_list ", " Addr.pretty) params (d_list ", " CilType.Exp.pretty) effective_args; *)
30323043
(* TODO: Use information from Read and Written graphs to determine subset of reachable that is reachable via arguments like provided in the graph. *)
30333044
(*
30343045
let reachable = collect_funargs ask ~warn:false glob_fun ctx.local effective_args in
@@ -3043,12 +3054,9 @@ struct
30433054
else
30443055
(* TODO: Use information from Read and Written graphs to determine subset of reachable that is reachable via arguments like provided in the graph. *)
30453056
let write_graph = ask.f (WriteGraph f) in
3046-
let read_graph = ask.f (ReadGraph f) in
3047-
3048-
let write_graph = Graph.join write_graph read_graph in
30493057

30503058
(* TODO: pass goal, use goal in collect_targets_with_graph function*)
3051-
let reachable = collect_targets_with_graph ctx write_graph effective_args effective_params (AD.bot ()) in
3059+
let reachable = collect_targets_with_graph ctx write_graph args params callee_globals (AD.bot ()) in
30523060

30533061
M.tracel "modular_combine_reachable" "reachable: %a\n" AD.pretty reachable;
30543062
let vars_to_writes : value_map VarMap.t =
@@ -3106,17 +3114,12 @@ struct
31063114
combine_env_regular ctx lval fexp f args fc au f_ask
31073115

31083116
let translate_callee_value_back ctx f f_ask (args: exp list) (value: VD.t): VD.t =
3109-
let glob_fun = modular_glob_fun ctx in
31103117
let ask = Analyses.ask_of_ctx ctx in
3111-
3112-
(* TODO: Is write-graph for return value computation? *)
31133118
let write_graph = ask.f (WriteGraph f) in
3114-
let read_graph = ask.f (ReadGraph f) in
3115-
let write_graph = Graph.join write_graph read_graph in
31163119
(* TODO: pass goal, use goal in collect_targets_with_graph function*)
31173120
let callee_globals = UsedGlobals.get_used_globals f_ask in
3118-
let effective_params = f.sformals @ callee_globals in
3119-
let reachable = collect_targets_with_graph ctx write_graph args effective_params (AD.bot ()) in
3121+
let params = f.sformals in
3122+
let reachable = collect_targets_with_graph ctx write_graph args params callee_globals (AD.bot ()) in
31203123
let value = ModularUtil.ValueDomainExtension.map_back value ~reachable in
31213124
value
31223125

@@ -3129,10 +3132,7 @@ struct
31293132
else VD.top ()
31303133
in
31313134
let return_val = if is_callee_modular ~ask:(Analyses.ask_of_ctx ctx) ~callee:f then
3132-
let callee_globals = UsedGlobals.get_used_globals_exps f_ask in
3133-
(* let effective_args = args @ callee_globals in *)
3134-
let effective_args = args @ callee_globals in
3135-
translate_callee_value_back ctx f f_ask effective_args return_val
3135+
translate_callee_value_back ctx f f_ask args return_val
31363136
else
31373137
return_val
31383138
in

src/analyses/readAnalysis.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ struct
144144
let threadspawn ctx ~multiple lval f args fctx = ctx.local
145145
let exitstate v = D.top ()
146146

147-
let query ctx (type a) (q: a Q.t): a Q.result =
147+
let query ctx (type a) (q: a Q.t): a Q.result = (* TODO: Only use in access analysis *)
148148
match q with
149149
| Read ->
150150
let read : D.t = ctx.local in
151-
read
151+
D.bot ()
152152
| ReadGraph f ->
153153
let read : G.t = ctx.global f in
154-
read
154+
G.bot ()
155155
| _ -> Q.Result.top q
156156

157157
let modular_support () = Modular

src/cdomain/value/cdomains/valueDomain.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ struct
13581358
| Union u ->
13591359
Unions.fold (fun k v acc -> AD.join (reachable_from v description) acc) u empty
13601360
(* For arrays, we ask to read from an unknown index, this will cause it
1361-
* join all its values. *)
1361+
* join all its values. *)
13621362
| Array a ->
13631363
let handle_item (acc: AD.t) (v: t) =
13641364
let reachable = reachable_from v description in

0 commit comments

Comments
 (0)