Skip to content

SMT2 back-end: detect when solver returns unexpected model #8379

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
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE smt-backend no-new-smt
KNOWNBUG smt-backend no-new-smt
smt_missing_range_check.c
--no-malloc-may-fail --pointer-check -z3
^EXIT=10$
Expand All @@ -9,7 +9,10 @@ smt_missing_range_check.c
--
--
Check that memory checks fail for pointer dereferences inside an existential
qualifier, for out of bounds memory access, when using the smt backend and
quantifier, for out of bounds memory access, when using the smt backend and
the range of the index is unbound. Note that this test is not expected to work
with the SAT backend at the time of writing, as the SAT backend does not support
qualifiers in this form.
quantifiers in this form.

Neither Z3 nor CVC5 currently return complete models, and Bitwuzla does not
complete in more than 5 minutes.
2 changes: 1 addition & 1 deletion regression/cbmc/Quantifiers-assertion/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE no-new-smt
CORE broken-z3-smt-backend no-new-smt
main.c

^\*\* Results:$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc/z3/Issue5977.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Issue5977.c
--z3
^EXIT=(6|10)$
^SIGNAL=0$
^SMT2 solver returned "unknown"$
^SMT2 solver returned ("unknown"|non-constant value for variable B\d+)$
--
--
This tests that an "unknown" result from the SMT solver is reported.
45 changes: 34 additions & 11 deletions src/solvers/smt2/smt2_dec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,22 +236,45 @@
{
const std::string boolean_identifier =
convert_identifier("B" + std::to_string(v));
boolean_assignment[v] = [&]() {
const auto found_parsed_value =
parsed_values.find(drop_quotes(boolean_identifier));
if(found_parsed_value != parsed_values.end())
{
return found_parsed_value->second.id() == ID_true;
const irept &value = found_parsed_value->second;

if(value.id() != ID_true && value.id() != ID_false)
{
messaget log{message_handler};
log.error() << "SMT2 solver returned non-constant value for variable "
<< boolean_identifier << messaget::eom;
return decision_proceduret::resultt::D_ERROR;
}
boolean_assignment[v] = value.id() == ID_true;
}
else

Check warning on line 254 in src/solvers/smt2/smt2_dec.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_dec.cpp#L254

Added line #L254 was not covered by tests
{
// Work out the value based on what set_to was called with.
const auto found_set_value = set_values.find(boolean_identifier);
if(found_set_value != set_values.end())
boolean_assignment[v] = found_set_value->second;

Check warning on line 259 in src/solvers/smt2/smt2_dec.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_dec.cpp#L257-L259

Added lines #L257 - L259 were not covered by tests
else
{
// Old code used the computation
// const irept &value=values["B"+std::to_string(v)];
// boolean_assignment[v]=(value.id()==ID_true);
const irept &value = parsed_values[boolean_identifier];

Check warning on line 265 in src/solvers/smt2/smt2_dec.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_dec.cpp#L265

Added line #L265 was not covered by tests

if(value.id() != ID_true && value.id() != ID_false)

Check warning on line 267 in src/solvers/smt2/smt2_dec.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_dec.cpp#L267

Added line #L267 was not covered by tests
{
messaget log{message_handler};
log.error()
<< "SMT2 solver returned non-Boolean value for variable "
<< boolean_identifier << messaget::eom;
return decision_proceduret::resultt::D_ERROR;

Check warning on line 273 in src/solvers/smt2/smt2_dec.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_dec.cpp#L269-L273

Added lines #L269 - L273 were not covered by tests
}
boolean_assignment[v] = value.id() == ID_true;
}
}
// Work out the value based on what set_to was called with.
const auto found_set_value = set_values.find(boolean_identifier);
if(found_set_value != set_values.end())
return found_set_value->second;
// Old code used the computation
// const irept &value=values["B"+std::to_string(v)];
// boolean_assignment[v]=(value.id()==ID_true);
return parsed_values[boolean_identifier].id() == ID_true;
}();
}

return res;
Expand Down
Loading