Skip to content

Fix SMT2 encoding of array_of_exprt #5974

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
Mar 26, 2021

Conversation

SaswatPadhi
Copy link
Contributor

The SMT conversion routines were broken for array_comprehension_exprt. They used quantifiers to initialize constant arrays, but that encoding didn't seem to work with existing SMT solvers.

This PR fixes the translation rule by using the as const construct in SMTLIB2.

NOTE: I am not sure which regression test is directly affected by this, I just noticed this issue while fixing another bug [#5973]. I'd be happy to add a new regression test, but there must be some broken-smt-backend regression test blocked on this one.

  • Each commit message has a non-empty body, explaining why the change was made.
  • NA Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • NA The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • NA My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • NA White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@SaswatPadhi SaswatPadhi added SMT Backend Interface bugfix aws Bugs or features of importance to AWS CBMC users labels Mar 25, 2021
@SaswatPadhi SaswatPadhi requested a review from allredj as a code owner March 25, 2021 00:45
@SaswatPadhi SaswatPadhi self-assigned this Mar 25, 2021
@SaswatPadhi SaswatPadhi changed the title Fixed SMT encoding of array_of_exprt Fix SMT encoding of array_of_exprt Mar 25, 2021
@SaswatPadhi SaswatPadhi changed the title Fix SMT encoding of array_of_exprt Fix SMT2 encoding of array_of_exprt Mar 25, 2021
@SaswatPadhi
Copy link
Contributor Author

Hmm ... CI is failing because CPROVER SMT2 doesn't understand as const but this is supported by Z3 and CVC4.

@kroening
Copy link
Member

Likewise here: you no longer need defined_expressions -- simply emit the required SMT-LIB expression directly.

#endif
out << "(define-fun " << id << " () ";
convert_type(array_of_expr.type());
out << " ((as const ";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm pretty sure as const isn't in SMT-LIB.

Copy link
Contributor Author

@SaswatPadhi SaswatPadhi Mar 25, 2021

Choose a reason for hiding this comment

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

I am not sure about the status of as const in SMTLIB2 standard, but both Z3 and CVC4 accept as const. We anyway didn't have a working solution for this with quantifiers, and I have tested array initialization with as const for both solvers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will make this translation solver-specific then -- only emit SMT2 output if solver is either Z3 or CVC4.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, it is fine to use extensions but they must not be in the default. Z3 and CVC4 are not the only solvers, they are not even the only solvers that people use with CBMC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. Please take another look and see if the changes look okay. I introduced the use_as_const field to track solvers that support as const.

@SaswatPadhi SaswatPadhi mentioned this pull request Mar 25, 2021
3 tasks
@SaswatPadhi SaswatPadhi marked this pull request as draft March 25, 2021 20:19
@SaswatPadhi
Copy link
Contributor Author

Marking as draft until #5976 is merged.

Instead of using quantifers to encode array_of expressions -- which, as indicated in the comments, doesn't seem to work on existing solvers -- we can use the `as const` construct for CVC4 and Z3.
@codecov
Copy link

codecov bot commented Mar 26, 2021

Codecov Report

Merging #5974 (aaa7a3a) into develop (95e1161) will decrease coverage by 0.00%.
The diff coverage is 71.15%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5974      +/-   ##
===========================================
- Coverage    75.02%   75.01%   -0.01%     
===========================================
  Files         1431     1433       +2     
  Lines       155595   155738     +143     
===========================================
+ Hits        116734   116834     +100     
- Misses       38861    38904      +43     
Impacted Files Coverage Δ
src/ansi-c/c_typecheck_base.h 100.00% <ø> (ø)
src/solvers/smt2/smt2_conv.h 100.00% <ø> (ø)
...rc/ansi-c/c_typecheck_gcc_polymorphic_builtins.cpp 76.58% <45.07%> (-4.36%) ⬇️
src/ansi-c/c_typecheck_expr.cpp 75.23% <66.66%> (-0.06%) ⬇️
src/ansi-c/c_expr.cpp 96.55% <96.55%> (ø)
src/solvers/smt2/smt2_conv.cpp 59.39% <96.77%> (+0.16%) ⬆️
src/ansi-c/c_expr.h 100.00% <100.00%> (ø)
...olvers/strings/string_constraint_instantiation.cpp 94.69% <0.00%> (+3.53%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab538eb...aaa7a3a. Read the comment docs.

@SaswatPadhi SaswatPadhi marked this pull request as ready for review March 26, 2021 00:38
@kroening
Copy link
Member

It would be awesome to identify the tests that work after this change, and remove the 'broken' flag from these!

@tautschnig
Copy link
Collaborator

It would be awesome to identify the tests that work after this change, and remove the 'broken' flag from these!

#5958 will help with this, but I need to do my homework first...

@kroening kroening merged commit 1a360f6 into diffblue:develop Mar 26, 2021
@SaswatPadhi
Copy link
Contributor Author

I will create a separate PR for the broken-* tests that are fixed, and I will link to this PR so we know the root cause.

@SaswatPadhi SaswatPadhi deleted the smt2_array_of branch March 26, 2021 14:40
TGWDB added a commit to TGWDB/cbmc that referenced this pull request Aug 4, 2021
This commit fixes an error introduced in diffblue#5974 where quantifiers
were produced for all SMT2 solvers despite only being supported by
Z3 and CVC4. The fix here reverts to the older behaviour for other
solvers.

Fixes diffblue#6263
TGWDB added a commit to TGWDB/cbmc that referenced this pull request May 12, 2022
This commit fixes an error introduced in diffblue#5974 where quantifiers
were produced for all SMT2 solvers despite only being supported by
Z3 and CVC4. The fix here reverts to the older behaviour for other
solvers.

Fixes diffblue#6263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws Bugs or features of importance to AWS CBMC users bugfix SMT Backend Interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants