Skip to content

Commit 53d3388

Browse files
authored
Merge pull request #1876 from goblint/witness-invariant-anon-comp-field-2
Exclude `__annonCompField` offsets from witness invariants
2 parents 662e770 + 48a8377 commit 53d3388

File tree

6 files changed

+40
-8
lines changed

6 files changed

+40
-8
lines changed

src/analyses/apron/relationAnalysis.apron.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ struct
613613
if (one_var || GobApron.Lincons1.num_vars lincons1 >= 2) && (exact || Apron.Lincons1.get_typ lincons1 <> EQ) then
614614
RD.cil_exp_of_lincons1 lincons1
615615
|> Option.map e_inv
616-
|> Option.filter (fun exp -> not (InvariantCil.exp_contains_tmp exp) && InvariantCil.exp_is_in_scope scope exp)
616+
|> Option.filter (InvariantCil.exp_is_suitable ~scope)
617617
else
618618
None
619619
)

src/analyses/apron/relationPriv.apron.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ struct
733733
(* RD.invariant simplifies two octagon SUPEQ constraints to one EQ, so exact works *)
734734
if (one_var || GobApron.Lincons1.num_vars lincons1 >= 2) && (exact || Apron.Lincons1.get_typ lincons1 <> EQ) then
735735
RD.cil_exp_of_lincons1 lincons1
736-
|> Option.filter (fun exp -> not (InvariantCil.exp_contains_tmp exp))
736+
|> Option.filter (InvariantCil.exp_is_suitable ?scope:None)
737737
else
738738
None
739739
)

src/analyses/varEq.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct
2828
if B.mem MyCFG.unknown_exp s then
2929
a
3030
else (
31-
let s' = B.filter (fun x -> not (InvariantCil.exp_contains_tmp x) && InvariantCil.exp_is_in_scope scope x && not (is_str_constant x)) s in
31+
let s' = B.filter (fun x -> InvariantCil.exp_is_suitable ~scope x && not (is_str_constant x)) s in
3232
if B.cardinal s' >= 2 then (
3333
(* instead of returning quadratically many pairwise equalities from a cluster,
3434
output linear number of equalities with just one expression *)

src/cdomain/value/cdomains/valueDomain.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ struct
13641364
Cilfacade.mkCast ~e ~newt:(TPtr (TVoid [], []))
13651365
in
13661366
let i =
1367-
if InvariantCil.(not (exp_contains_tmp c_exp) && exp_is_in_scope scope c_exp && not (var_is_tmp vi) && var_is_in_scope scope vi && not (var_is_heap vi)) then
1367+
if InvariantCil.(exp_is_suitable ~scope c_exp && var_is_suitable ~scope vi && not (var_is_heap vi)) then
13681368
try
13691369
let addr_exp = AddrOf (Var vi, offset) in (* AddrOf or Lval? *)
13701370
let addr_exp, c_exp = if typeSig (Cilfacade.typeOf addr_exp) <> typeSig (Cilfacade.typeOf c_exp) then
@@ -1395,7 +1395,7 @@ struct
13951395
| Addr.NullPtr ->
13961396
let i =
13971397
let addr_exp = integer 0 in
1398-
if InvariantCil.(not (exp_contains_tmp c_exp) && exp_is_in_scope scope c_exp) then
1398+
if InvariantCil.exp_is_suitable ~scope c_exp then
13991399
Invariant.of_exp Cil.(BinOp (Eq, c_exp, addr_exp, intType))
14001400
else
14011401
Invariant.none
@@ -1417,13 +1417,13 @@ struct
14171417
and vd_invariant ~vs ~offset ~lval = function
14181418
| Compound.Int n ->
14191419
let e = Lval lval in
1420-
if InvariantCil.(not (exp_contains_tmp e) && exp_is_in_scope scope e) then
1420+
if InvariantCil.exp_is_suitable ~scope e then
14211421
ID.invariant e n
14221422
else
14231423
Invariant.none
14241424
| Float n ->
14251425
let e = Lval lval in
1426-
if InvariantCil.(not (exp_contains_tmp e) && exp_is_in_scope scope e) then
1426+
if InvariantCil.exp_is_suitable ~scope e then
14271427
FD.invariant e n
14281428
else
14291429
Invariant.none

src/cdomain/value/domains/invariantCil.ml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,38 @@ let exp_contains_tmp e =
9090
ignore (visitCilExpr visitor e);
9191
!acc
9292

93+
94+
let fieldinfo_is_anon (fi: fieldinfo) =
95+
String.starts_with ~prefix:"__annonCompField" fi.fname (* TODO: what if CIL-ed program explicitly has this? *)
96+
97+
let rec offset_contains_anon_comp_offset = function
98+
| NoOffset -> false
99+
| Index (e, offs') -> offset_contains_anon_comp_offset offs' (* does not check e!, done by visitor *)
100+
| Field (fi, offs') -> fieldinfo_is_anon fi || offset_contains_anon_comp_offset offs'
101+
102+
class exp_contains_anon_comp_offset_visitor = object
103+
inherit nopCilVisitor
104+
method! voffs (offs: offset) =
105+
if offset_contains_anon_comp_offset offs then
106+
raise Stdlib.Exit
107+
else
108+
DoChildren (* recurse to Index offset expressions! *)
109+
end
110+
let exp_contains_anon_comp_offset =
111+
let visitor = new exp_contains_anon_comp_offset_visitor in
112+
fun e ->
113+
match visitCilExpr visitor e with
114+
| _ -> false
115+
| exception Stdlib.Exit -> true
116+
117+
118+
let var_is_suitable ?scope v =
119+
not (var_is_tmp v) && GobOption.for_all (fun scope -> var_is_in_scope scope v) scope
120+
121+
let exp_is_suitable ?scope e =
122+
not (exp_contains_tmp e || exp_contains_anon_comp_offset e) && GobOption.for_all (fun scope -> exp_is_in_scope scope e) scope
123+
124+
93125
class exp_contains_anon_type_visitor = object
94126
inherit nopCilVisitor
95127
method! vtype (t: typ) =

src/cdomains/c2poDomain.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ module D = struct
293293
let not_in_scope t =
294294
let var = T.get_var t in
295295
let var = Var.to_varinfo var in
296-
InvariantCil.var_is_tmp var || not (InvariantCil.var_is_in_scope scope var)
296+
not (InvariantCil.var_is_suitable ~scope var)
297297
in
298298
remove_terms not_in_scope cc
299299
end

0 commit comments

Comments
 (0)