File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed
tests/regression/33-constants Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ (* * CIL's {!GoblintCil.Ptranal} for function pointer evaluation ([ptranal]).
2+
3+ Useful for sound analysis of function pointers without base. *)
4+
5+ (* TODO: fix unsoundness on some bench repo examples: https://github.com/goblint/analyzer/pull/1063 *)
6+
7+ open GoblintCil
8+ open Analyses
9+
10+ module Spec =
11+ struct
12+ include UnitAnalysis. Spec
13+
14+ let name () = " ptranal"
15+
16+ let query ctx (type a ) (q : a Queries.t ): a Queries.result =
17+ match q with
18+ | Queries. EvalFunvar (Lval (Mem e , _ )) ->
19+ let funs = Ptranal. resolve_exp e in
20+ (* TODO: filter compatible function pointers by type? *)
21+ List. fold_left (fun xs f -> Queries.AD. add (Queries.AD.Addr. of_var f) xs) (Queries.AD. empty () ) funs
22+ | _ -> Queries.Result. top q
23+
24+ let init _ : unit =
25+ Ptranal. analyze_file ! Cilfacade. current_file;
26+ Ptranal. compute_results false
27+
28+ end
29+
30+ let _ =
31+ MCP. register_analysis (module Spec : MCPSpec )
Original file line number Diff line number Diff line change @@ -164,6 +164,7 @@ module TaintPartialContexts = TaintPartialContexts
164164module UnassumeAnalysis = UnassumeAnalysis
165165module ExpRelation = ExpRelation
166166module AbortUnless = AbortUnless
167+ module PtranalAnalysis = PtranalAnalysis
167168
168169
169170(* * {1 Domains}
Original file line number Diff line number Diff line change 1+ //PARAM: --set ana.activated '["constants", "ptranal"]'
2+ // intentional explicit ana.activated to do tutorial in isolation
3+ int f (int a , int b ){
4+ int d = 3 ;
5+ int z = a + d ;
6+ return z ;
7+ }
8+
9+ int main (){
10+ int d = 0 ;
11+ int (* fp )(int ,int ) = & f ;
12+ d = fp (2 , 3 );
13+ return 0 ;
14+ }
You can’t perform that action at this time.
0 commit comments