@@ -114,31 +114,29 @@ struct
114114 | Mem (Lval lv ), off ->
115115 let lvals = eval_lv ~man st (Mem (Lval lv), off) in
116116 let res = AD. fold (fun a acc ->
117- match a with
118- | Addr (base , _ ) as orig ->
119- let (a:VD.t ) = Address (AD. singleton (AD.Addr. of_var base)) in
120- if M. tracing then M. tracel " inv" " Consider case of lval %a = %a" d_lval lv VD. pretty a;
121- let st = set' lv a st in
122- let old_val = get ~man st (AD. singleton orig) None in
123- let old_val = VD. cast (Cilfacade. typeOfLval x) old_val in (* needed as the type of this pointer may be different *)
124- (* this what I would originally have liked to do, but eval_rv_lval_refine uses queries and thus stale values *)
125- (* let old_val = eval_rv_lval_refine ~man st exp x in *)
126- let old_val = map_oldval old_val (Cilfacade. typeOfLval x) in
127- let v = apply_invariant ~old_val ~new_val: c' in
128- if is_some_bot v then
129- D. join acc (try contra st with Analyses. Deadcode -> D. bot () )
130- else (
131- if M. tracing then M. tracel " inv" " improve lval %a from %a to %a (c = %a, c' = %a)" d_lval x VD. pretty old_val VD. pretty v pretty c VD. pretty c';
132- D. join acc (set' x v st)
117+ Option. bind acc (fun acc ->
118+ match a with
119+ | Addr (base , _ ) as orig ->
120+ let (a:VD.t ) = Address (AD. singleton (AD.Addr. of_var base)) in
121+ if M. tracing then M. tracel " inv" " Consider case of lval %a = %a" d_lval lv VD. pretty a;
122+ let st = set' lv a st in
123+ let old_val = get ~man st (AD. singleton orig) None in
124+ let old_val = VD. cast (Cilfacade. typeOfLval x) old_val in (* needed as the type of this pointer may be different *)
125+ (* this what I would originally have liked to do, but eval_rv_lval_refine uses queries and thus stale values *)
126+ (* let old_val = eval_rv_lval_refine ~man st exp x in *)
127+ let old_val = map_oldval old_val (Cilfacade. typeOfLval x) in
128+ let v = apply_invariant ~old_val ~new_val: c' in
129+ if is_some_bot v then
130+ Some (D. join acc (try contra st with Analyses. Deadcode -> D. bot () ))
131+ else (
132+ if M. tracing then M. tracel " inv" " improve lval %a from %a to %a (c = %a, c' = %a)" d_lval x VD. pretty old_val VD. pretty v pretty c VD. pretty c';
133+ Some (D. join acc (set' x v st))
134+ )
135+ | _ -> None
133136 )
134- | _ ->
135- default ()
136- ) lvals (D. bot () )
137+ ) lvals (Some (D. bot () ))
137138 in
138- if D. is_bot res then
139- raise Analyses. Deadcode
140- else
141- res
139+ BatOption. map_default_delayed (fun d -> if D. is_bot d then raise Analyses. Deadcode else d) default res
142140 | Var _, _
143141 | Mem _ , _ ->
144142 default ()
0 commit comments