Skip to content

check for side effects in quantifiers #2979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions regression/cbmc/Quantifiers1/quantifier-with-side-effect.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
int func()
{
return 1;
}

int main()
{
// clang-format off
// no side effects!
assert(__CPROVER_forall { int i; func() });
// clang-format on

return 0;
}
7 changes: 7 additions & 0 deletions regression/cbmc/Quantifiers1/quantifier-with-side-effect.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
quantifier-with-side-effect.c

^EXIT=6$
^SIGNAL=0$
^file .* line 10 function main: quantifier must not contain side effects$
--
8 changes: 8 additions & 0 deletions src/ansi-c/c_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Author: Daniel Kroening, [email protected]
#include <util/c_types.h>
#include <util/config.h>
#include <util/cprover_prefix.h>
#include <util/expr_util.h>
#include <util/ieee_float.h>
#include <util/pointer_offset_size.h>
#include <util/pointer_predicates.h>
Expand Down Expand Up @@ -299,6 +300,13 @@ void c_typecheck_baset::typecheck_expr_main(exprt &expr)
throw 0;
}

if(has_subexpr(expr.op1(), ID_side_effect))
{
err_location(expr);
error() << "quantifier must not contain side effects" << eom;
throw 0;
}

// replace declaration by symbol expression
symbol_exprt bound=to_symbol_expr(expr.op0().op0());
expr.op0().swap(bound);
Expand Down
18 changes: 5 additions & 13 deletions src/goto-programs/goto_clean_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ Author: Daniel Kroening, [email protected]

#include "goto_convert_class.h"

#include <util/cprover_prefix.h>
#include <util/expr_util.h>
#include <util/fresh_symbol.h>
#include <util/simplify_expr.h>
#include <util/std_expr.h>
#include <util/cprover_prefix.h>

#include <util/c_types.h>

Expand Down Expand Up @@ -405,18 +406,9 @@ void goto_convertt::clean_expr(
}
else if(expr.id()==ID_forall || expr.id()==ID_exists)
{
assert(expr.operands().size()==2);
// check if there are side-effects
goto_programt tmp;
clean_expr(expr.op1(), tmp, mode, true);
if(tmp.instructions.empty())
{
error().source_location=expr.find_source_location();
error() << "no side-effects in quantified expressions allowed"
<< eom;
throw 0;
}
return;
DATA_INVARIANT(
!has_subexpr(expr, ID_side_effect),
"the front-end should check quantified expressions for side-effects");
}
else if(expr.id()==ID_address_of)
{
Expand Down