Skip to content

Commit 7410da7

Browse files
better test
1 parent 5dba343 commit 7410da7

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/cdomains/apron/sharedFunctions.apron.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,12 @@ struct
170170
| exception Invalid_argument _ -> raise (Unsupported_CilExp Exp_not_supported)
171171
| true -> texpr1 e
172172
| false -> (* Cast is not injective - we now try to establish suitable ranges manually *)
173-
GobRef.wrap AnalysisState.executing_speculative_computations true @@ fun () ->
174-
(* try to evaluate e by EvalInt Query *)
175-
let res = try (query e @@ Cilfacade.get_ikind_exp e) with Invalid_argument _ -> raise (Unsupported_CilExp Exp_not_supported) in
176-
(* convert response to a constant *)
177-
let const = IntDomain.IntDomTuple.to_int @@ IntDomain.IntDomTuple.cast_to t_ik res in
173+
(* retrieving a valuerange for a non-injective cast works by a query to the value-domain with subsequent value extraction from domtuple - which should be speculative, since it is not program code *)
174+
let const,res = GobRef.wrap AnalysisState.executing_speculative_computations true @@ fun () ->
175+
(* try to evaluate e by EvalInt Query *)
176+
let res = try (query e @@ Cilfacade.get_ikind_exp e) with Invalid_argument _ -> raise (Unsupported_CilExp Exp_not_supported) in
177+
(* convert response to a constant *)
178+
IntDomain.IntDomTuple.to_int @@ IntDomain.IntDomTuple.cast_to t_ik res, res in
178179
match const with
179180
| Some c -> Cst (Coeff.s_of_z c) (* Got a constant value -> use it straight away *)
180181
(* I gotten top, we can not guarantee injectivity *)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//SKIP PARAM: --enable ana.int.interval --set sem.int.signed_overflow assume_none --set ana.activated[+] lin2vareq
2+
3+
#include <goblint.h>
4+
5+
int nondet() {
6+
int x;
7+
return x;
8+
}
9+
int SIZE = 1;
10+
int rand;
11+
12+
int main() {
13+
unsigned int n=2,i=8;
14+
n = i%(SIZE+2); //NOWARN
15+
16+
rand=nondet();
17+
18+
if (rand>5 && rand<10) {
19+
n= i%(rand+2); //NOWARN
20+
}
21+
22+
return 0;
23+
}
24+

0 commit comments

Comments
 (0)