Skip to content
Snippets Groups Projects
Commit b25866a7 authored by Julien Signoles's avatar Julien Signoles Committed by Kostyantyn Vorobyov
Browse files

[typing] fix issue with -e-acsl-gmp-only and quantifier

parent 531215da
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
int main(void) int main(void)
{ {
int __retres; int __retres;
__e_acsl_memory_init((int *)0,(char ***)0,(size_t)8);
/*@ assert ∀ ℤ x; 0 ≤ x ≤ 1 ⇒ x ≡ 0 ∨ x ≡ 1; */ /*@ assert ∀ ℤ x; 0 ≤ x ≤ 1 ⇒ x ≡ 0 ∨ x ≡ 1; */
{ {
{ {
...@@ -204,7 +205,41 @@ int main(void) ...@@ -204,7 +205,41 @@ int main(void)
25); 25);
} }
} }
{
int buf[10];
__e_acsl_store_block((void *)(buf),(size_t)40);
/*@ assert ∀ ℤ i; 0 ≤ i < 10 ⇒ \valid(&buf[i]); */
{
{
int __gen_e_acsl_forall_7;
int __gen_e_acsl_i;
__gen_e_acsl_forall_7 = 1;
__gen_e_acsl_i = 0;
while (1) {
if (__gen_e_acsl_i < 10) ; else break;
{
int __gen_e_acsl_valid;
__gen_e_acsl_valid = __e_acsl_valid((void *)(& buf[__gen_e_acsl_i]),
sizeof(int));
if (__gen_e_acsl_valid) ;
else {
__gen_e_acsl_forall_7 = 0;
goto e_acsl_end_loop9;
}
}
__gen_e_acsl_i ++;
}
e_acsl_end_loop9: ;
__e_acsl_assert(__gen_e_acsl_forall_7,(char *)"Assertion",
(char *)"main",
(char *)"\\forall integer i; 0 <= i < 10 ==> \\valid(&buf[i])",
30);
__e_acsl_delete_block((void *)(buf));
}
}
}
__retres = 0; __retres = 0;
__e_acsl_memory_clean();
return __retres; return __retres;
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
int main(void) int main(void)
{ {
int __retres; int __retres;
__e_acsl_memory_init((int *)0,(char ***)0,(size_t)8);
/*@ assert ∀ ℤ x; 0 ≤ x ≤ 1 ⇒ x ≡ 0 ∨ x ≡ 1; */ /*@ assert ∀ ℤ x; 0 ≤ x ≤ 1 ⇒ x ≡ 0 ∨ x ≡ 1; */
{ {
{ {
...@@ -596,7 +597,71 @@ int main(void) ...@@ -596,7 +597,71 @@ int main(void)
__gmpz_clear(__gen_e_acsl_x_7); __gmpz_clear(__gen_e_acsl_x_7);
} }
} }
{
int buf[10];
__e_acsl_store_block((void *)(buf),(size_t)40);
/*@ assert ∀ ℤ i; 0 ≤ i < 10 ⇒ \valid(&buf[i]); */
{
{
int __gen_e_acsl_forall_7;
__e_acsl_mpz_t __gen_e_acsl_i;
__gen_e_acsl_forall_7 = 1;
__gmpz_init(__gen_e_acsl_i);
{
__e_acsl_mpz_t __gen_e_acsl__40;
__gmpz_init_set_si(__gen_e_acsl__40,0L);
__gmpz_set(__gen_e_acsl_i,
(__e_acsl_mpz_struct const *)(__gen_e_acsl__40));
__gmpz_clear(__gen_e_acsl__40);
}
while (1) {
{
__e_acsl_mpz_t __gen_e_acsl__41;
int __gen_e_acsl_lt_7;
__gmpz_init_set_si(__gen_e_acsl__41,10L);
__gen_e_acsl_lt_7 = __gmpz_cmp((__e_acsl_mpz_struct const *)(__gen_e_acsl_i),
(__e_acsl_mpz_struct const *)(__gen_e_acsl__41));
if (__gen_e_acsl_lt_7 < 0) ; else break;
__gmpz_clear(__gen_e_acsl__41);
}
{
long __gen_e_acsl_i_2;
int __gen_e_acsl_valid;
__gen_e_acsl_i_2 = __gmpz_get_si((__e_acsl_mpz_struct const *)(__gen_e_acsl_i));
__gen_e_acsl_valid = __e_acsl_valid((void *)(& buf[__gen_e_acsl_i_2]),
sizeof(int));
if (__gen_e_acsl_valid) ;
else {
__gen_e_acsl_forall_7 = 0;
goto e_acsl_end_loop9;
}
}
{
__e_acsl_mpz_t __gen_e_acsl__42;
__e_acsl_mpz_t __gen_e_acsl_add_15;
__gmpz_init_set_si(__gen_e_acsl__42,1L);
__gmpz_init(__gen_e_acsl_add_15);
__gmpz_add(__gen_e_acsl_add_15,
(__e_acsl_mpz_struct const *)(__gen_e_acsl_i),
(__e_acsl_mpz_struct const *)(__gen_e_acsl__42));
__gmpz_set(__gen_e_acsl_i,
(__e_acsl_mpz_struct const *)(__gen_e_acsl_add_15));
__gmpz_clear(__gen_e_acsl__42);
__gmpz_clear(__gen_e_acsl_add_15);
}
}
e_acsl_end_loop9: ;
__e_acsl_assert(__gen_e_acsl_forall_7,(char *)"Assertion",
(char *)"main",
(char *)"\\forall integer i; 0 <= i < 10 ==> \\valid(&buf[i])",
30);
__gmpz_clear(__gen_e_acsl_i);
__e_acsl_delete_block((void *)(buf));
}
}
}
__retres = 0; __retres = 0;
__e_acsl_memory_clean();
return __retres; return __retres;
} }
......
...@@ -14,6 +14,7 @@ FRAMAC_SHARE/libc/stdlib.h:277:[kernel] warning: No code nor implicit assigns cl ...@@ -14,6 +14,7 @@ FRAMAC_SHARE/libc/stdlib.h:277:[kernel] warning: No code nor implicit assigns cl
__e_acsl_init ∈ [--..--] __e_acsl_init ∈ [--..--]
__e_acsl_internal_heap ∈ [--..--] __e_acsl_internal_heap ∈ [--..--]
__e_acsl_heap_allocation_size ∈ [--..--] __e_acsl_heap_allocation_size ∈ [--..--]
[value] using specification for function __e_acsl_memory_init
tests/gmp/quantif.i:9:[value] warning: assertion got status unknown. tests/gmp/quantif.i:9:[value] warning: assertion got status unknown.
tests/gmp/quantif.i:9:[value] entering loop for the first time tests/gmp/quantif.i:9:[value] entering loop for the first time
[value] using specification for function __e_acsl_assert [value] using specification for function __e_acsl_assert
...@@ -31,4 +32,10 @@ tests/gmp/quantif.i:21:[value] entering loop for the first time ...@@ -31,4 +32,10 @@ tests/gmp/quantif.i:21:[value] entering loop for the first time
tests/gmp/quantif.i:25:[value] warning: assertion got status unknown. tests/gmp/quantif.i:25:[value] warning: assertion got status unknown.
tests/gmp/quantif.i:25:[value] entering loop for the first time tests/gmp/quantif.i:25:[value] entering loop for the first time
tests/gmp/quantif.i:26:[value] entering loop for the first time tests/gmp/quantif.i:26:[value] entering loop for the first time
[value] using specification for function __e_acsl_store_block
tests/gmp/quantif.i:30:[value] warning: assertion got status unknown.
tests/gmp/quantif.i:30:[value] entering loop for the first time
[value] using specification for function __e_acsl_valid
[value] using specification for function __e_acsl_delete_block
[value] using specification for function __e_acsl_memory_clean
[value] done for function main [value] done for function main
...@@ -14,6 +14,7 @@ FRAMAC_SHARE/libc/stdlib.h:277:[kernel] warning: No code nor implicit assigns cl ...@@ -14,6 +14,7 @@ FRAMAC_SHARE/libc/stdlib.h:277:[kernel] warning: No code nor implicit assigns cl
__e_acsl_init ∈ [--..--] __e_acsl_init ∈ [--..--]
__e_acsl_internal_heap ∈ [--..--] __e_acsl_internal_heap ∈ [--..--]
__e_acsl_heap_allocation_size ∈ [--..--] __e_acsl_heap_allocation_size ∈ [--..--]
[value] using specification for function __e_acsl_memory_init
tests/gmp/quantif.i:9:[value] warning: assertion got status unknown. tests/gmp/quantif.i:9:[value] warning: assertion got status unknown.
[value] using specification for function __gmpz_init [value] using specification for function __gmpz_init
[value] using specification for function __gmpz_init_set_si [value] using specification for function __gmpz_init_set_si
...@@ -41,4 +42,11 @@ tests/gmp/quantif.i:25:[value] entering loop for the first time ...@@ -41,4 +42,11 @@ tests/gmp/quantif.i:25:[value] entering loop for the first time
tests/gmp/quantif.i:26:[value] entering loop for the first time tests/gmp/quantif.i:26:[value] entering loop for the first time
[value] using specification for function __gmpz_tdiv_q [value] using specification for function __gmpz_tdiv_q
[value] using specification for function __gmpz_mul [value] using specification for function __gmpz_mul
[value] using specification for function __e_acsl_store_block
tests/gmp/quantif.i:30:[value] warning: assertion got status unknown.
tests/gmp/quantif.i:30:[value] entering loop for the first time
[value] using specification for function __gmpz_get_si
[value] using specification for function __e_acsl_valid
[value] using specification for function __e_acsl_delete_block
[value] using specification for function __e_acsl_memory_clean
[value] done for function main [value] done for function main
...@@ -25,5 +25,10 @@ int main(void) { ...@@ -25,5 +25,10 @@ int main(void) {
/*@ assert \forall int x; 0 <= x < 10 /*@ assert \forall int x; 0 <= x < 10
==> x % 2 == 0 ==> \exists integer y; 0 <= y <= x/2 && x == 2 * y; */ ==> x % 2 == 0 ==> \exists integer y; 0 <= y <= x/2 && x == 2 * y; */
{ // Gitlab issue #42
int buf[10];
/*@ assert \forall integer i; 0 <= i < 10 ==> \valid(buf+i); */
}
return 0; return 0;
} }
...@@ -178,7 +178,9 @@ let ty_of_interv ?ctx i = ...@@ -178,7 +178,9 @@ let ty_of_interv ?ctx i =
let ukind = Cil.intKindForValue u is_pos in let ukind = Cil.intKindForValue u is_pos in
(* kind corresponding to the interval *) (* kind corresponding to the interval *)
if Cil.intTypeIncluded lkind ukind then ukind else lkind if Cil.intTypeIncluded lkind ukind then ukind else lkind
| _, _ -> Kernel.fatal ~current:true "ival: %a" Ival.pretty i | None, None -> raise Cil.Not_representable (* GMP *)
| None, Some _ | Some _, None ->
Kernel.fatal ~current:true "ival: %a" Ival.pretty i
in in
(* convert the kind to [IInt] whenever smaller. *) (* convert the kind to [IInt] whenever smaller. *)
let kind = if Cil.intTypeIncluded itv_kind IInt then IInt else itv_kind in let kind = if Cil.intTypeIncluded itv_kind IInt then IInt else itv_kind in
...@@ -553,8 +555,8 @@ let rec type_predicate p = ...@@ -553,8 +555,8 @@ let rec type_predicate p =
| _ -> assert false | _ -> assert false
in in
let i2 = Interval.infer t2 in let i2 = Interval.infer t2 in
(* add one to [i2], since we increment the loop counter one more (* add one to [i2], since we increment the loop counter one more
time before going outside the loop. *) time before going outside the loop. *)
let i2 = match r2 with let i2 = match r2 with
| Rlt -> i2 | Rlt -> i2
| Rle -> Ival.add_singleton_int Integer.one i2 | Rle -> Ival.add_singleton_int Integer.one i2
...@@ -579,6 +581,13 @@ let rec type_predicate p = ...@@ -579,6 +581,13 @@ let rec type_predicate p =
GMP variable when --e-acsl-gmp-only *) GMP variable when --e-acsl-gmp-only *)
ignore (type_term ~use_gmp_opt:false ~ctx t1); ignore (type_term ~use_gmp_opt:false ~ctx t1);
ignore (type_term ~use_gmp_opt:false ~ctx t2); ignore (type_term ~use_gmp_opt:false ~ctx t2);
(* if we must generate GMP code, degrade the interval in order to
guarantee that [x] will be a GMP when typing the goal *)
let i = match ctx with
| C_type _ -> i
| Gmp -> Ival.inject_range None None (* [ -\infty; +\infty ] *)
| Other -> assert false
in
Interval.Env.add x i) Interval.Env.add x i)
guards; guards;
(type_predicate goal).ty (type_predicate goal).ty
...@@ -589,7 +598,7 @@ let rec type_predicate p = ...@@ -589,7 +598,7 @@ let rec type_predicate p =
| Pvalid(_, t) | Pvalid(_, t)
| Pvalid_read(_, t) | Pvalid_read(_, t)
| Pvalid_function t -> | Pvalid_function t ->
ignore (type_term ~use_gmp_opt:true ~ctx:Other t); ignore (type_term ~use_gmp_opt:false ~ctx:Other t);
c_int c_int
| Pforall _ -> Error.not_yet "unguarded \\forall quantification" | Pforall _ -> Error.not_yet "unguarded \\forall quantification"
......
...@@ -56,6 +56,8 @@ type integer_ty = private ...@@ -56,6 +56,8 @@ type integer_ty = private
| C_type of ikind | C_type of ikind
| Other (** Any non-integral type *) | Other (** Any non-integral type *)
val pretty: Format.formatter -> integer_ty -> unit
(** {3 Smart constructors} *) (** {3 Smart constructors} *)
val gmp: integer_ty val gmp: integer_ty
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment