Skip to content

Commit 5290131

Browse files
authored
Merge pull request #1821 from goblint/issue-1782
Check cast safety in base `invariant_fallback`
2 parents 62e97b9 + 56445a1 commit 5290131

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/analyses/baseInvariant.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,13 @@ struct
237237
let switchedOp = function Lt -> Gt | Gt -> Lt | Le -> Ge | Ge -> Le | x -> x in (* a op b <=> b (switchedOp op) b *)
238238
match exp with
239239
(* Since we handle not only equalities, the order is important *)
240-
| BinOp(op, Lval x, rval, typ) -> helper op x (VD.cast (Cilfacade.typeOfLval x) (eval_rv ~man st rval)) tv
240+
| BinOp(op, Lval x, rval, typ) ->
241+
let v = eval_rv ~man st rval in
242+
let x_type = Cilfacade.typeOfLval x in
243+
if VD.is_dynamically_safe_cast x_type (Cilfacade.typeOf rval) v then
244+
helper op x (VD.cast x_type v) tv
245+
else
246+
`NotUnderstood
241247
| BinOp(op, rval, Lval x, typ) -> derived_invariant (BinOp(switchedOp op, Lval x, rval, typ)) tv
242248
| 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)
243249
-> derived_invariant (BinOp (op, c1, c2, t)) tv
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// PARAM: --enable ana.int.interval --set ana.activated[+] abortUnless
2+
#include <goblint.h>
3+
4+
extern void abort(void);
5+
void assume_abort_if_not(int cond) {
6+
if(!cond) {abort();}
7+
}
8+
9+
int main() {
10+
int n_update;
11+
12+
assume_abort_if_not(n_update >= 0);
13+
assume_abort_if_not(n_update <= ( 4294967295UL / sizeof (char)));
14+
15+
__goblint_check(1); // reachable
16+
return 0;
17+
}

0 commit comments

Comments
 (0)