Skip to content

Commit a0f6f5f

Browse files
committed
Fix SSA assert construction
CBMC 5.8 added FALSE || to the beginning of instrumented assertions which revealed a flaw in how the assertions were constructed in 2LS. Make the approach more general, recursively going through the whole assertion. Signed-off-by: František Nečas <[email protected]>
1 parent 17d7042 commit a0f6f5f

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

src/ssa/local_ssa.cpp

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -537,37 +537,58 @@ void local_SSAt::build_guard(locationt loc)
537537
(--nodes.end())->equalities.push_back(equality);
538538
}
539539

540-
/// turns assertions into constraints
541-
void local_SSAt::build_assertions(locationt loc)
540+
/// Recursively go through expr and look for an equality with a pointer
541+
/// object on the right side and construct a disjunct of possible
542+
/// concrete assignments.
543+
bool local_SSAt::get_deallocated_disjunction(const exprt &expr, exprt &result)
542544
{
543-
if(loc->is_assert())
545+
if(expr.id()==ID_equal && expr.op1().id()==ID_pointer_object &&
546+
expr.op1().op0().id()==ID_symbol)
544547
{
545-
exprt assert=loc->guard;
546-
if(assert.id()==ID_not && assert.op0().id()==ID_equal &&
547-
assert.op0().op1().id()==ID_pointer_object &&
548-
assert.op0().op1().op0().id()==ID_symbol)
548+
std::string id=id2string(
549+
to_symbol_expr(expr.op1().op0()).get_identifier());
550+
if(id.find("__CPROVER_deallocated")!=std::string::npos)
549551
{
550-
std::string id=id2string(
551-
to_symbol_expr(assert.op0().op1().op0()).get_identifier());
552-
if(id.find("__CPROVER_deallocated")!=std::string::npos)
552+
const exprt &dealloc_symbol=expr.op1().op0();
553+
exprt::operandst d;
554+
for(auto &global : assignments.ssa_objects.globals)
553555
{
554-
const exprt &dealloc_symbol=assert.op0().op1().op0();
555-
exprt::operandst d;
556-
for(auto &global : assignments.ssa_objects.globals)
556+
if(global.get_expr().get_bool("#concrete"))
557557
{
558-
if(global.get_expr().get_bool("#concrete"))
559-
{
560-
d.push_back(
561-
equal_exprt(
562-
dealloc_symbol,
563-
typecast_exprt(
564-
address_of_exprt(global.symbol_expr()),
565-
dealloc_symbol.type())));
566-
}
558+
d.push_back(
559+
equal_exprt(
560+
dealloc_symbol,
561+
typecast_exprt(
562+
address_of_exprt(global.symbol_expr()),
563+
dealloc_symbol.type())));
567564
}
568-
assert=implies_exprt(disjunction(d), assert);
569565
}
566+
result=disjunction(d);
567+
return true;
570568
}
569+
}
570+
else
571+
{
572+
// Recursively go through the operands
573+
if(!expr.has_operands())
574+
return false;
575+
else
576+
for(const exprt &op : expr.operands())
577+
if(get_deallocated_disjunction(op, result))
578+
return true;
579+
}
580+
return false;
581+
}
582+
583+
/// turns assertions into constraints
584+
void local_SSAt::build_assertions(locationt loc)
585+
{
586+
if(loc->is_assert())
587+
{
588+
exprt assert=loc->guard;
589+
exprt antecedent;
590+
if(get_deallocated_disjunction(assert, antecedent))
591+
assert=implies_exprt(antecedent, assert);
571592

572593
const exprt deref_rhs=dereference(assert, loc);
573594

src/ssa/local_ssa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ class local_SSAt
281281
void build_cond(locationt loc);
282282
void build_guard(locationt loc);
283283
void build_function_call(locationt loc);
284+
bool get_deallocated_disjunction(const exprt &expr, exprt &result);
284285
void build_assertions(locationt loc);
285286
void build_unknown_objs(locationt loc);
286287

src/ssa/malloc_ssa.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ std::vector<exprt> collect_pointer_vars(
9393
std::vector<exprt> pointers;
9494
forall_symbols(it, symbol_table.symbols)
9595
{
96+
if(it->second.is_type)
97+
continue;
9698
if(ns.follow(it->second.type).id()==ID_struct)
9799
{
98100
for(auto &component : to_struct_type(

0 commit comments

Comments
 (0)