@@ -1292,17 +1292,21 @@ struct
1292
1292
| Some m1 , Some m2 -> Option. is_some (Addr.Mval. prefix m1 m2)
1293
1293
| _ -> false
1294
1294
1295
+ module Graph = ValueDomain. ADGraph
1296
+
1295
1297
(* Given a set of addresses, collect graph
1296
1298
that contains all paths with which these addresses are reachable with a depth-first search *)
1297
1299
let collect_graph (local : CPA.t ) (start : AD.t ) (goal : AD.t ) =
1298
- if AD. is_empty start || AD. is_empty goal then
1300
+ if M. tracing then M. tracel " collect_graph" " local: %a\n start: %a\n " CPA. pretty local AD. pretty start;
1301
+ let r = if AD. is_empty start || AD. is_empty goal then
1299
1302
ValueDomain.ADGraph. bot ()
1300
1303
else
1301
1304
let ask: Queries. ask = { Queries. f = (fun (type a ) (q : a Queries.t ) -> Queries.Result. top q)} in
1302
1305
let state = D. top () in
1303
1306
let local = {state with cpa = local} in
1304
1307
let rec dfs node (visited , graph ) : bool * ValueDomain.ADGraph.t =
1305
1308
let node = node in
1309
+ if M. tracing then M. tracel " collect_graph" " visited-set: %a + %a\n " AD. pretty visited Addr. pretty node;
1306
1310
let visited = AD. join visited (AD. singleton node) in
1307
1311
let glob_fun = fun _ -> failwith " Should not lookup globals." in
1308
1312
let reachable_from_node = reachable_from_address_offset ask glob_fun local (AD. singleton node) in
@@ -1318,10 +1322,11 @@ struct
1318
1322
else
1319
1323
begin
1320
1324
let found, graph = dfs n (visited, graph) in
1321
- if goal_reached || found then
1325
+ if goal_reached || found then begin
1326
+ if M. tracing then M. tracel " collect_graph" " Adding edge from %a via %a to %a graph.\n " Addr. pretty node Offset.Unit. pretty o Addr. pretty n;
1322
1327
let graph = ValueDomain.ADGraph. add node (ADOffsetMap. singleton o (AD. singleton n)) graph in
1323
1328
(true , graph)
1324
- else
1329
+ end else
1325
1330
(found, graph)
1326
1331
end
1327
1332
in
@@ -1330,16 +1335,17 @@ struct
1330
1335
let f, g = dfs_add_edge o a g in
1331
1336
f, g) n g
1332
1337
in
1333
- ADOffsetMap. fold dfs_add_edge reachable_from_node (false , ValueDomain.ADGraph. bot () )
1338
+ ADOffsetMap. fold dfs_add_edge reachable_from_node (false , graph )
1334
1339
in
1335
1340
let dfs_combine node (_ , graph ) =
1336
- let graph = dfs node (AD. empty () , graph) in
1337
- graph
1341
+ dfs node (AD. empty () , graph)
1338
1342
in
1339
1343
let empty_graph = ValueDomain.ADGraph. empty () in
1340
1344
let _, result = AD. fold dfs_combine start (false , empty_graph) in
1341
- if M. tracing then M. tracel " collect_graph" " From %a to %a, in graph %a\n " AD. pretty start AD. pretty goal ValueDomain.ADGraph. pretty result;
1342
1345
result
1346
+ in
1347
+ if M. tracing then M. tracel " collect_graph" " Result: %a\n " Graph. pretty r;
1348
+ r
1343
1349
1344
1350
let query ctx (type a ) (q : a Q.t ): a Q.result =
1345
1351
match q with
@@ -2940,19 +2946,23 @@ struct
2940
2946
module AddrPair = Lattice. Prod (Addr ) (Addr )
2941
2947
module AddrPairSet = Set. Make (AddrPair )
2942
2948
2943
- module Graph = ValueDomain. ADGraph
2944
-
2945
2949
(* * In the given local state, from the start state, find the addresses that correspond to the goals *)
2946
2950
let collect_targets_with_graph ctx (graph : Graph.t ) (args : exp list ) (params : varinfo list ) (goal : AD.t ) =
2947
2951
let ask = Analyses. ask_of_ctx ctx in
2948
2952
let start = List. map (Addr. of_var ~is_modular: true ) params in
2949
- let queue = List. combine start start in
2950
- let queue : (Addr.t * Addr.t) Queue.t = queue |> Seq. of_list |> Queue. of_seq in (* mutable! *)
2953
+ (* let queue = List.combine args start in *)
2954
+ (* let queue : (Addr.t * Addr.t) Queue.t = queue |> Seq.of_list |> Queue.of_seq in mutable! *)
2955
+ let queue = Queue. of_seq Seq. empty in
2951
2956
let visited = ref AddrPairSet. empty in
2952
2957
2953
2958
2954
2959
let dir_reachable_conc = collect_funargs_immediate_offset ask ctx.global ctx.local args in
2955
- let dir_reachable_abs = List. map (fun a -> Graph. find a graph) start in
2960
+ let dir_reachable_abs = List. map (fun a ->
2961
+ let r = Graph. find a graph in
2962
+ if M. tracing then M. tracel " modular_combine" " For %a found %a in graph.\n " Addr. pretty a ADOffsetMap. pretty r;
2963
+ r)
2964
+ start
2965
+ in
2956
2966
let combined = try
2957
2967
List. combine dir_reachable_conc dir_reachable_abs
2958
2968
with Invalid_argument e -> (
@@ -2975,6 +2985,10 @@ struct
2975
2985
) dir_reachable_abs;
2976
2986
) combined;
2977
2987
2988
+ M. tracel " modular_combine" " Initalized conc: %a\n " (d_list " , " ADOffsetMap. pretty) (List. map Tuple2. first combined);
2989
+ M. tracel " modular_combine" " Initalized abs: %a\n " (d_list " , " ADOffsetMap. pretty) (List. map Tuple2. second combined);
2990
+ M. tracel " modular_combine" " graph: %a\n " Graph. pretty graph;
2991
+
2978
2992
while not (Queue. is_empty queue) do
2979
2993
let c, a = Queue. pop queue in
2980
2994
let dir_reachable_conc = reachable_from_address_offset ask ctx.global ctx.local (AD. singleton c) in
@@ -2998,8 +3012,13 @@ struct
2998
3012
let combine_env_modular ctx lval fexp f args fc au (f_ask : Queries.ask ) =
2999
3013
let ask = Analyses. ask_of_ctx ctx in
3000
3014
let glob_fun = modular_glob_fun ctx in
3001
- let callee_globals = UsedGlobals. get_callee_globals f_ask in
3015
+ let callee_globals_exp = UsedGlobals. get_used_globals f_ask in
3016
+ let callee_globals = UsedGlobals. get_used_globals_exps f_ask in
3017
+
3018
+ let effective_params = f.sformals @ callee_globals_exp in
3002
3019
let effective_args = args @ callee_globals in
3020
+
3021
+ 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;
3003
3022
(* TODO: Use information from Read and Written graphs to determine subset of reachable that is reachable via arguments like provided in the graph. *)
3004
3023
(*
3005
3024
let reachable = collect_funargs ask ~warn:false glob_fun ctx.local effective_args in
@@ -3014,8 +3033,9 @@ struct
3014
3033
let write_graph = ask.f (WriteGraph f) in
3015
3034
3016
3035
(* TODO: pass goal, use goal in collect_targets_with_graph function*)
3017
- let reachable = collect_targets_with_graph ctx write_graph args f.sformals (AD. bot () ) in
3036
+ let reachable = collect_targets_with_graph ctx write_graph effective_args effective_params (AD. bot () ) in
3018
3037
3038
+ M. tracel " modular_combine" " reachable: %a\n " AD. pretty reachable;
3019
3039
let vars_to_writes : value_map VarMap.t =
3020
3040
let update_entry (address : address ) (value : value ) (acc : value_map VarMap.t ) =
3021
3041
let lvals = AD. to_mval address in
@@ -3070,12 +3090,14 @@ struct
3070
3090
else
3071
3091
combine_env_regular ctx lval fexp f args fc au f_ask
3072
3092
3073
- let translate_callee_value_back ctx f (args : exp list ) (value : VD.t ): VD.t =
3093
+ let translate_callee_value_back ctx f f_ask (args : exp list ) (value : VD.t ): VD.t =
3074
3094
let glob_fun = modular_glob_fun ctx in
3075
3095
let ask = Analyses. ask_of_ctx ctx in
3076
3096
let write_graph = ask.f (WriteGraph f) in
3077
3097
(* TODO: pass goal, use goal in collect_targets_with_graph function*)
3078
- let reachable = collect_targets_with_graph ctx write_graph args f.sformals (AD. bot () ) in
3098
+ let callee_globals = UsedGlobals. get_used_globals f_ask in
3099
+ let effective_params = f.sformals @ callee_globals in
3100
+ let reachable = collect_targets_with_graph ctx write_graph args effective_params (AD. bot () ) in
3079
3101
let value = ModularUtil.ValueDomainExtension. map_back value ~reachable in
3080
3102
value
3081
3103
@@ -3088,10 +3110,10 @@ struct
3088
3110
else VD. top ()
3089
3111
in
3090
3112
let return_val = if is_callee_modular ~ask: (Analyses. ask_of_ctx ctx) ~callee: f then
3091
- let callee_globals = UsedGlobals. get_callee_globals f_ask in
3113
+ let callee_globals = UsedGlobals. get_used_globals_exps f_ask in
3092
3114
(* let effective_args = args @ callee_globals in *)
3093
- let effective_args = args in
3094
- translate_callee_value_back ctx f effective_args return_val
3115
+ let effective_args = args @ callee_globals in
3116
+ translate_callee_value_back ctx f f_ask effective_args return_val
3095
3117
else
3096
3118
return_val
3097
3119
in
0 commit comments