Skip to content

SMT back-end: Extend trace value evaluation #7310

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
Nov 14, 2022
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
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{};
Comment on lines +328 to +329
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand why we return nil if any operand could be nil? The old code here (e.g.) for arrays would leave the nil in place and return the larger expr.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd fear that we fail to notice problems. I'm not sure returning nil ever is the right thing to do?

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