Skip to content

Commit 0812cc1

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 6b7b29a commit 0812cc1

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ bool c_typecheck_baset::gcc_types_compatible_p(
166166
return false;
167167
}
168168

169+
static bool has_side_effect(const exprt &expr)
170+
{
171+
if(expr.id() == ID_side_effect)
172+
return true;
173+
174+
for(const auto &op : expr.operands())
175+
if(has_side_effect(op))
176+
return true;
177+
178+
return false;
179+
}
180+
169181
void c_typecheck_baset::typecheck_expr_main(exprt &expr)
170182
{
171183
if(expr.id()==ID_side_effect)
@@ -303,6 +315,13 @@ void c_typecheck_baset::typecheck_expr_main(exprt &expr)
303315
throw 0;
304316
}
305317

318+
if(has_side_effect(expr.op1()))
319+
{
320+
err_location(expr);
321+
error() << "quantifier must not contain side effects" << eom;
322+
throw 0;
323+
}
324+
306325
// replace declaration by symbol expression
307326
symbol_exprt bound=to_symbol_expr(expr.op0().op0());
308327
expr.op0().swap(bound);

src/goto-programs/goto_clean_expr.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -405,18 +405,7 @@ void goto_convertt::clean_expr(
405405
}
406406
else if(expr.id()==ID_forall || expr.id()==ID_exists)
407407
{
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;
408+
// the front-end checks these for side-effects
420409
}
421410
else if(expr.id()==ID_address_of)
422411
{

0 commit comments

Comments
 (0)