Skip to content

Commit

Permalink
SMT back-end: Extend trace value evaluation
Browse files Browse the repository at this point in the history
We record the values of expressions by adding `expr == expr`
as constraints in order to be able to fetch and display them in the GOTO
trace (for declaration; we presently also introduce new symbols in other
cases). Constructing a trace then requires the ability to evaluate all
kinds of expressions to obtain the value for those expressions.

Fixes: diffblue#7308
  • Loading branch information
tautschnig committed Nov 11, 2022
1 parent 0060417 commit f89af9d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 18 deletions.
15 changes: 15 additions & 0 deletions regression/cbmc/Empty_struct3/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <assert.h>

struct Unit
{
};

int main()
{
struct Unit var_0;
int x;
int y = x;
assert(0);
assert(y == x);
return 0;
}
8 changes: 8 additions & 0 deletions regression/cbmc/Empty_struct3/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--json-ui
VERIFICATION FAILED
^EXIT=10$
^SIGNAL=0$
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/cbmc/trace-values/trace-values.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE broken-smt-backend
CORE
trace-values.c
--trace
^EXIT=10$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc/trace_options_json_extended/extended.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE broken-smt-backend
CORE
test.c
--trace --json-ui --trace-json-extended
^EXIT=10$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE broken-smt-backend
CORE
test.c
--trace --json-ui
^EXIT=10$
Expand Down
1 change: 1 addition & 0 deletions regression/validate-trace-xml-schema/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
# this uses json-ui (fails for a different reason actually, but should also
# fail because of command line incompatibility)
['json1', 'test.desc'],
['Empty_struct3', 'test.desc'],
# uses show-goto-functions
['reachability-slice', 'test.desc'],
['reachability-slice', 'test2.desc'],
Expand Down
31 changes: 16 additions & 15 deletions src/solvers/smt2/smt2_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,6 @@ exprt smt2_convt::get(const exprt &expr) const
if(it!=identifier_map.end())
return it->second.value;
}
else if(expr.id()==ID_member)
{
const member_exprt &member_expr=to_member_expr(expr);
exprt tmp=get(member_expr.struct_op());
if(tmp.is_nil())
return nil_exprt();
return member_exprt(tmp, member_expr.get_component_name(), expr.type());
}
else if(expr.id() == ID_literal)
{
auto l = to_literal_expr(expr).get_literal();
Expand All @@ -321,16 +313,23 @@ exprt smt2_convt::get(const exprt &expr) const
else if(op.is_false())
return true_exprt();
}
else if(expr.is_constant())
else if(
expr.is_constant() || expr.id() == ID_empty_union ||
(!expr.has_operands() && (expr.id() == ID_struct || expr.id() == ID_array)))
{
return expr;
else if(const auto &array = expr_try_dynamic_cast<array_exprt>(expr))
}
else if(expr.has_operands())
{
exprt array_copy = *array;
for(auto &element : array_copy.operands())
exprt copy = expr;
for(auto &op : copy.operands())
{
element = get(element);
exprt eval_op = get(op);
if(eval_op.is_nil())
return nil_exprt{};
op = std::move(eval_op);
}
return array_copy;
return copy;
}

return nil_exprt();
Expand Down Expand Up @@ -4780,7 +4779,9 @@ void smt2_convt::set_to(const exprt &expr, bool value)
const irep_idt &identifier=
to_symbol_expr(equal_expr.lhs()).get_identifier();

if(identifier_map.find(identifier)==identifier_map.end())
if(
identifier_map.find(identifier) == identifier_map.end() &&
equal_expr.lhs() != equal_expr.rhs())
{
identifiert &id=identifier_map[identifier];
CHECK_RETURN(id.type.is_nil());
Expand Down

0 comments on commit f89af9d

Please sign in to comment.