Skip to content

Commit c4c20df

Browse files
authored
Merge pull request #1894 from goblint/cast-kind
Add cast kinds in CIL
2 parents f37871c + 20c3cce commit c4c20df

29 files changed

+124
-75
lines changed

goblint.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ dev-repo: "git+https://github.com/goblint/analyzer.git"
102102
x-maintenance-intent: ["(latest)" "(latest).(latest-1)"] # also keep previous minor version (with two releases per year, always keep a SV-COMP release)
103103
available: os-family != "bsd" & os-distribution != "alpine" & (arch != "arm64" | os = "macos")
104104
pin-depends: [
105-
[ "goblint-cil.2.0.9" "git+https://github.com/goblint/cil.git#1b48fc0ce4f3576a51618305251121ffedd0bf1e" ]
105+
[ "goblint-cil.2.0.9" "git+https://github.com/goblint/cil.git#e21285af8f4408ed5354b1674dab840c43e84712" ]
106106
# pinned for stability (https://github.com/goblint/analyzer/issues/1520), remove after new apron release
107107
[ "apron.v0.9.15" "git+https://github.com/antoinemine/apron.git#418a217c7a70dae3f422678f3aaba38ae374d91a" ]
108108
]

goblint.opam.locked

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ post-messages: [
148148
pin-depends: [
149149
[
150150
"goblint-cil.2.0.9"
151-
"git+https://github.com/goblint/cil.git#1b48fc0ce4f3576a51618305251121ffedd0bf1e"
151+
"git+https://github.com/goblint/cil.git#e21285af8f4408ed5354b1674dab840c43e84712"
152152
]
153153
[
154154
"apron.v0.9.15"

goblint.opam.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
x-maintenance-intent: ["(latest)" "(latest).(latest-1)"] # also keep previous minor version (with two releases per year, always keep a SV-COMP release)
44
available: os-family != "bsd" & os-distribution != "alpine" & (arch != "arm64" | os = "macos")
55
pin-depends: [
6-
[ "goblint-cil.2.0.9" "git+https://github.com/goblint/cil.git#1b48fc0ce4f3576a51618305251121ffedd0bf1e" ]
6+
[ "goblint-cil.2.0.9" "git+https://github.com/goblint/cil.git#e21285af8f4408ed5354b1674dab840c43e84712" ]
77
# pinned for stability (https://github.com/goblint/analyzer/issues/1520), remove after new apron release
88
[ "apron.v0.9.15" "git+https://github.com/antoinemine/apron.git#418a217c7a70dae3f422678f3aaba38ae374d91a" ]
99
]

src/analyses/apron/relationAnalysis.apron.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ struct
216216
| Const x -> e
217217
| UnOp (unop, e, typ) -> UnOp(unop, inner e, typ)
218218
| BinOp (binop, e1, e2, typ) -> BinOp (binop, inner e1, inner e2, typ)
219-
| CastE (t,e) -> CastE (t, inner e)
219+
| CastE (k,t,e) -> CastE (k, t, inner e)
220220
| Lval (Var v, off) -> Lval (Var v, off)
221221
| Lval (Mem e, NoOffset) ->
222222
begin match ask (Queries.MayPointTo e) with

src/analyses/base.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ struct
825825
eval_rv_base_lval ~eval_lv ~man st exp lv
826826
(* Binary operators *)
827827
(* Eq/Ne when both values are equal and casted to the same type *)
828-
| BinOp ((Eq | Ne) as op, (CastE (t1, e1) as c1), (CastE (t2, e2) as c2), typ) when typeSig t1 = typeSig t2 ->
828+
| BinOp ((Eq | Ne) as op, (CastE (_, t1, e1) as c1), (CastE (_, t2, e2) as c2), typ) when typeSig t1 = typeSig t2 ->
829829
let a1 = eval_rv ~man st e1 in
830830
let a2 = eval_rv ~man st e2 in
831831
let extra_is_safe =
@@ -842,7 +842,7 @@ struct
842842
(* split nested LOr Eqs to equality pairs, if possible *)
843843
let rec split = function
844844
(* copied from above to support pointer equalities with implicit casts inserted *)
845-
| BinOp (Eq, (CastE (t1, e1) as c1), (CastE (t2, e2) as c2), typ) when typeSig t1 = typeSig t2 ->
845+
| BinOp (Eq, (CastE (_, t1, e1) as c1), (CastE (_, t2, e2) as c2), typ) when typeSig t1 = typeSig t2 ->
846846
Some [binop_remove_same_casts ~extra_is_safe:false ~e1 ~e2 ~t1 ~t2 ~c1 ~c2]
847847
| BinOp (Eq, arg1, arg2, _) ->
848848
Some [(arg1, arg2)]
@@ -927,8 +927,8 @@ struct
927927
let array_ofs = `Index (IdxDom.of_int (Cilfacade.ptrdiff_ikind ()) Z.zero, `NoOffset) in
928928
let array_start = add_offset_varinfo array_ofs in
929929
Address (AD.map array_start (eval_lv ~man st lval))
930-
| CastE (t, Const (CStr (x,e))) -> (* VD.top () *) eval_rv ~man st (Const (CStr (x,e))) (* TODO safe? *)
931-
| CastE (t, exp) ->
930+
| CastE (_, t, Const (CStr (x,e))) -> (* VD.top () *) eval_rv ~man st (Const (CStr (x,e))) (* TODO safe? *)
931+
| CastE (_, t, exp) ->
932932
(let v = eval_rv ~man st exp in
933933
try
934934
VD.cast ~torg:(Cilfacade.typeOf exp) t v
@@ -1072,7 +1072,7 @@ struct
10721072
match ofs with
10731073
| NoOffset -> `NoOffset
10741074
| Field (fld, ofs) -> `Field (fld, convert_offset ~man st ofs)
1075-
| Index (exp, ofs) when CilType.Exp.equal exp (Lazy.force Offset.Index.Exp.any) -> (* special offset added by convertToQueryLval *)
1075+
| Index (exp, ofs) when Offset.Index.Exp.is_any exp -> (* special offset added by convertToQueryLval *)
10761076
`Index (IdxDom.top (), convert_offset ~man st ofs)
10771077
| Index (exp, ofs) ->
10781078
match eval_rv ~man st exp with
@@ -1395,7 +1395,7 @@ struct
13951395
| Imag e
13961396
| SizeOfE e
13971397
| AlignOfE e
1398-
| CastE (_, e) -> exp_may_signed_overflow man e
1398+
| CastE (_, _, e) -> exp_may_signed_overflow man e
13991399
| UnOp (unop, e, _) ->
14001400
(* check if the current operation causes a signed overflow *)
14011401
begin match unop with
@@ -2391,7 +2391,8 @@ struct
23912391
|> AD.type_of in
23922392
(* when src and destination type coincide, take value from the source, otherwise use top *)
23932393
let value = if (typeSig dest_typ = typeSig src_typ) && dest_size_equal_n then
2394-
let src_cast_lval = mkMem ~addr:(Cilfacade.mkCast ~e:src ~newt:(TPtr (dest_typ, []))) ~off:NoOffset in
2394+
(* TODO: why cast if types coincide? *)
2395+
let src_cast_lval = mkMem ~addr:(Cilfacade.mkCast ~kind:Internal ~e:src ~newt:(TPtr (dest_typ, []))) ~off:NoOffset in
23952396
eval_rv ~man st (Lval src_cast_lval)
23962397
else
23972398
VD.top_value (unrollType dest_typ)

src/analyses/baseInvariant.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ struct
245245
else
246246
`NotUnderstood
247247
| BinOp(op, rval, Lval x, typ) -> derived_invariant (BinOp(switchedOp op, Lval x, rval, typ)) tv
248-
| BinOp(op, CastE (t1, c1), CastE (t2, c2), t) when (op = Eq || op = Ne) && typeSig t1 = typeSig t2 && VD.is_statically_safe_cast t1 (Cilfacade.typeOf c1) && VD.is_statically_safe_cast t2 (Cilfacade.typeOf c2)
248+
| BinOp(op, CastE (_, t1, c1), CastE (_, t2, c2), t) when (op = Eq || op = Ne) && typeSig t1 = typeSig t2 && VD.is_statically_safe_cast t1 (Cilfacade.typeOf c1) && VD.is_statically_safe_cast t2 (Cilfacade.typeOf c2)
249249
-> derived_invariant (BinOp (op, c1, c2, t)) tv
250-
| BinOp(op, CastE (t1, Lval x), rval, typ) when Cil.isIntegralType t1 ->
250+
| BinOp(op, CastE (_, t1, Lval x), rval, typ) when Cil.isIntegralType t1 ->
251251
begin match eval_rv ~man st (Lval x) with
252252
| Int v ->
253253
if VD.is_dynamically_safe_cast t1 (Cilfacade.typeOfLval x) (Int v) then
@@ -256,8 +256,8 @@ struct
256256
`NotUnderstood
257257
| _ -> `NotUnderstood
258258
end
259-
| BinOp(op, rval, CastE (ti, Lval x), typ) when Cil.isIntegralType ti ->
260-
derived_invariant (BinOp (switchedOp op, CastE(ti, Lval x), rval, typ)) tv
259+
| BinOp(op, rval, CastE (k, ti, Lval x), typ) when Cil.isIntegralType ti ->
260+
derived_invariant (BinOp (switchedOp op, CastE(k, ti, Lval x), rval, typ)) tv
261261
| BinOp(op, (Const _ | AddrOf _), rval, typ) ->
262262
(* This is last such that we never reach here with rval being Lval (it is swapped around). *)
263263
`NothingToRefine
@@ -649,15 +649,15 @@ struct
649649
| UnOp (Neg, e, _), Float c -> inv_exp (unop_FD Neg c) e st
650650
| UnOp ((BNot|Neg) as op, e, _), Int c -> inv_exp (Int (unop_ID op c)) e st
651651
(* no equivalent for Float, as VD.is_statically_safe_cast fails for all float types anyways *)
652-
| BinOp((Eq | Ne) as op, CastE (t1, e1), CastE (t2, e2), t), Int c when typeSig (Cilfacade.typeOf e1) = typeSig (Cilfacade.typeOf e2) && VD.is_statically_safe_cast t1 (Cilfacade.typeOf e1) && VD.is_statically_safe_cast t2 (Cilfacade.typeOf e2) ->
652+
| BinOp((Eq | Ne) as op, CastE (_, t1, e1), CastE (_, t2, e2), t), Int c when typeSig (Cilfacade.typeOf e1) = typeSig (Cilfacade.typeOf e2) && VD.is_statically_safe_cast t1 (Cilfacade.typeOf e1) && VD.is_statically_safe_cast t2 (Cilfacade.typeOf e2) ->
653653
inv_exp (Int c) (BinOp (op, e1, e2, t)) st
654654
| BinOp (LOr, arg1, arg2, typ) as exp, Int c ->
655655
(* copied & modified from eval_rv_base... *)
656656
let (let*) = Option.bind in
657657
(* split nested LOr Eqs to equality pairs, if possible *)
658658
let rec split = function
659659
(* copied from above to support pointer equalities with implicit casts inserted *)
660-
| BinOp (Eq, CastE (t1, e1), CastE (t2, e2), typ) when typeSig (Cilfacade.typeOf e1) = typeSig (Cilfacade.typeOf e2) && VD.is_statically_safe_cast t1 (Cilfacade.typeOf e1) && VD.is_statically_safe_cast t2 (Cilfacade.typeOf e2) -> (* slightly different from eval_rv_base... *)
660+
| BinOp (Eq, CastE (_, t1, e1), CastE (_, t2, e2), typ) when typeSig (Cilfacade.typeOf e1) = typeSig (Cilfacade.typeOf e2) && VD.is_statically_safe_cast t1 (Cilfacade.typeOf e1) && VD.is_statically_safe_cast t2 (Cilfacade.typeOf e2) -> (* slightly different from eval_rv_base... *)
661661
Some [(e1, e2)]
662662
| BinOp (Eq, arg1, arg2, _) ->
663663
Some [(arg1, arg2)]
@@ -835,7 +835,7 @@ struct
835835
| _ -> assert false
836836
end
837837
| Const _ , _ -> st (* nothing to do *)
838-
| CastE (t, e), c_typed ->
838+
| CastE (k, t, e), c_typed ->
839839
begin match Cil.unrollType t, c_typed with
840840
| TFloat (_, _), Float c ->
841841
(match unrollType (Cilfacade.typeOf e), FD.get_fkind c with
@@ -864,7 +864,7 @@ struct
864864
fallback (fun () -> Pretty.dprintf "CastE: %a evaluates to %a which is bigger than the type it is cast to which is %a" d_plainexp e ID.pretty i CilType.Typ.pretty t) st
865865
| x -> fallback (fun () -> Pretty.dprintf "CastE: e did evaluate to Int, but the type did not match %a" CilType.Typ.pretty t) st)
866866
| v -> fallback (fun () -> Pretty.dprintf "CastE: e did not evaluate to Int, but %a" VD.pretty v) st)
867-
| _, _ -> fallback (fun () -> Pretty.dprintf "CastE: %a not implemented" d_plainexp (CastE (t, e))) st
867+
| _, _ -> fallback (fun () -> Pretty.dprintf "CastE: %a not implemented" d_plainexp (CastE (k, t, e))) st
868868
end
869869
| e, _ -> fallback (fun () -> Pretty.dprintf "%a not implemented" d_plainexp e) st
870870
in

src/analyses/condVars.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module Domain = struct
1818
and var_in_expr p = function
1919
| Const _ | SizeOf _ | SizeOfStr _ | AlignOf _ -> true
2020
| Lval l | AddrOf l | StartOf l -> var_in_lval p l
21-
| SizeOfE e | AlignOfE e | UnOp (_,e,_) | CastE (_,e) | Imag e | Real e -> var_in_expr p e
21+
| SizeOfE e | AlignOfE e | UnOp (_,e,_) | CastE (_,_,e) | Imag e | Real e -> var_in_expr p e
2222
| BinOp (_,e1,e2,_) -> var_in_expr p e1 && var_in_expr p e2
2323
| Question (c,t,e,_) -> var_in_expr p c && var_in_expr p t && var_in_expr p e
2424
| AddrOfLabel _ -> true

src/analyses/malloc_null.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct
7070

7171
let get_concrete_exp (exp:exp) gl (st:D.t) =
7272
match constFold true exp with
73-
| CastE (_,Lval (Var v, offs))
73+
| CastE (_,_,Lval (Var v, offs))
7474
| Lval (Var v, offs) -> Some (Var v,offs)
7575
| _ -> None
7676

src/analyses/memOutOfBounds.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct
4646
| SizeOfE e
4747
| AlignOfE e
4848
| UnOp (_, e, _)
49-
| CastE (_, e) -> exp_contains_a_ptr e
49+
| CastE (_, _, e) -> exp_contains_a_ptr e
5050
| BinOp (_, e1, e2, _) ->
5151
exp_contains_a_ptr e1 || exp_contains_a_ptr e2
5252
| Question (e1, e2, e3, _) ->
@@ -172,7 +172,7 @@ struct
172172
match ofs with
173173
| NoOffset -> `NoOffset
174174
| Field (fld, ofs) -> `Field (fld, convert_offset ofs)
175-
| Index (exp, ofs) when CilType.Exp.equal exp (Lazy.force Offset.Index.Exp.any) -> (* special offset added by convertToQueryLval *)
175+
| Index (exp, ofs) when Offset.Index.Exp.is_any exp -> (* special offset added by convertToQueryLval *)
176176
`Index (ID.top (), convert_offset ofs)
177177
| Index (exp, ofs) ->
178178
let i = match man.ask (Queries.EvalInt exp) with
@@ -372,7 +372,7 @@ struct
372372
| SizeOfE e
373373
| AlignOfE e
374374
| UnOp (_, e, _)
375-
| CastE (_, e) -> check_exp_for_oob_access man ~is_implicitly_derefed e
375+
| CastE (_, _, e) -> check_exp_for_oob_access man ~is_implicitly_derefed e
376376
| BinOp (bop, e1, e2, t) ->
377377
check_exp_for_oob_access man ~is_implicitly_derefed e1;
378378
check_exp_for_oob_access man ~is_implicitly_derefed e2

src/analyses/tutorials/taint.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct
4545
| Imag e
4646
| SizeOfE e
4747
| AlignOfE e
48-
| CastE (_,e)
48+
| CastE (_,_,e)
4949
| UnOp (_,e,_) -> is_exp_tainted state e
5050
| SizeOf _ | SizeOfStr _ | Const _ | AlignOf _ | AddrOfLabel _ -> false
5151
| Question (b, t, f, _) -> is_exp_tainted state b || is_exp_tainted state t || is_exp_tainted state f

0 commit comments

Comments
 (0)