Skip to content

Commit f505207

Browse files
author
Daniel Kroening
committed
check for side effects in quantifiers in the front-end
This fixes a failed attempt to check for quantifiers during goto conversion by checking earlier in the C front-end.
1 parent 3e7bc8e commit f505207

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
int func()
2+
{
3+
return 1;
4+
}
5+
6+
int main()
7+
{
8+
// no side effects!
9+
assert(__CPROVER_forall { int i; func() } );
10+
11+
return 0;
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
quantifier-with-side-effect.c
3+
4+
^EXIT=6$
5+
^SIGNAL=0$
6+
^file .* line 9 function main: quantifier must not contain side effects$
7+
--

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Author: Daniel Kroening, [email protected]
1818
#include <util/c_types.h>
1919
#include <util/config.h>
2020
#include <util/cprover_prefix.h>
21+
#include <util/expr_util.h>
2122
#include <util/ieee_float.h>
2223
#include <util/pointer_offset_size.h>
2324
#include <util/pointer_predicates.h>
@@ -299,6 +300,13 @@ void c_typecheck_baset::typecheck_expr_main(exprt &expr)
299300
throw 0;
300301
}
301302

303+
if(has_subexpr(expr.op1(), ID_side_effect))
304+
{
305+
err_location(expr);
306+
error() << "quantifier must not contain side effects" << eom;
307+
throw 0;
308+
}
309+
302310
// replace declaration by symbol expression
303311
symbol_exprt bound=to_symbol_expr(expr.op0().op0());
304312
expr.op0().swap(bound);

src/goto-programs/goto_clean_expr.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "goto_convert_class.h"
1313

14+
#include <util/expr_util.h>
1415
#include <util/fresh_symbol.h>
1516
#include <util/simplify_expr.h>
1617
#include <util/std_expr.h>
@@ -405,18 +406,7 @@ void goto_convertt::clean_expr(
405406
}
406407
else if(expr.id()==ID_forall || expr.id()==ID_exists)
407408
{
408-
assert(expr.operands().size()==2);
409-
// check if there are side-effects
410-
goto_programt tmp;
411-
clean_expr(expr.op1(), tmp, mode, true);
412-
if(tmp.instructions.empty())
413-
{
414-
error().source_location=expr.find_source_location();
415-
error() << "no side-effects in quantified expressions allowed"
416-
<< eom;
417-
throw 0;
418-
}
419-
return;
409+
DATA_INVARIANT(!has_subexpr(expr, ID_side_effect), "the front-end should check quantified expressions for side-effects");
420410
}
421411
else if(expr.id()==ID_address_of)
422412
{

0 commit comments

Comments
 (0)