Skip to content

Fix bugs stemming from duplicate output streams in smt2_convt::write_footer() #6207

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

Conversation

thomasspriggs
Copy link
Contributor

This fixes bugs arising from some of the member functions of
smt2::convt writing to an os argument and some of the them writing
to smt2_convt::out. This was causing some of the generated text to be
written out when using --outfile argument with cbmc, but not without
it.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • 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).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

This fixes bugs arising from some of the member functions of
`smt2::convt` writing to an `os` argument and some of the them writing
to `smt2_convt::out`. This was causing some of the generated text to be
written out when using `--outfile` argument with cbmc, but not without
it.

It might be easier to understand `smt2_convt` if the output stream was
passed as an argument to the member functions, instead of kept as a
member variable. This commit replaces the arguments with references to
the member variable because it is a less wide sweeping change and it
still solves the bugs.

The address_space_size_limit3 test is disabled with smt2, because the
output of this test was already different between the sat and smt2
backends and therefore it was already not producing the correct output.
Presumably this test was returning the expected `VERIFICATION FAILED`
result for the wrong reasons. The `VERIFICATION FAILED` result is only
returned in the case where the object size limits are missing. Further
work will be needed to properly debug the support for `--pointer-check`
with smt2.
This is worth explaining because it is no longer clear where the output
is written to based on the arguments/usage.
@codecov
Copy link

codecov bot commented Jun 30, 2021

Codecov Report

Merging #6207 (b68902f) into develop (0002950) will increase coverage by 7.98%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #6207      +/-   ##
===========================================
+ Coverage    67.40%   75.39%   +7.98%     
===========================================
  Files         1157     1456     +299     
  Lines        95236   161216   +65980     
===========================================
+ Hits         64197   121544   +57347     
- Misses       31039    39672    +8633     
Flag Coverage Δ
cproversmt2 ?
regression ?
unit ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/util/string_container.cpp 52.94% <0.00%> (-47.06%) ⬇️
src/solvers/prop/prop.cpp 42.85% <0.00%> (-41.76%) ⬇️
src/solvers/flattening/boolbv_member.cpp 53.65% <0.00%> (-38.65%) ⬇️
src/cpp/cpp_storage_spec.cpp 65.00% <0.00%> (-35.00%) ⬇️
src/util/cmdline.h 66.66% <0.00%> (-33.34%) ⬇️
src/solvers/strings/array_pool.h 66.66% <0.00%> (-33.34%) ⬇️
src/solvers/strings/string_refinement.h 66.66% <0.00%> (-33.34%) ⬇️
...rs/strings/string_concatenation_builtin_function.h 0.00% <0.00%> (-33.34%) ⬇️
src/cbmc/c_test_input_generator.cpp 60.00% <0.00%> (-30.33%) ⬇️
src/analyses/local_cfg.h 75.00% <0.00%> (-25.00%) ⬇️
... and 1435 more

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 5b8e8fa...b68902f. Read the comment docs.

Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

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

Thanks for fixing all of these bugs; that is great to see. I am not sure I really understand the changes to smt2_dec.cpp and why they were needed.

@@ -1,4 +1,4 @@
CORE
CORE broken-smt-backend
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why has this now broken?

problem_out << stringstream.str();
write_footer(problem_out);
}
const auto write_problem_to_file = [&](std::ofstream problem_out) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems longer, more complex and harder to debug than the code it replaces. What am I missing?

Copy link
Contributor

Choose a reason for hiding this comment

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

The old code would do the following:

  1. Write the internal stored string stream to file
  2. Call the footer to explicitly write to the file

The problem was that the write_footer call would call another function (define_object_size) that would write to the internal string stream.

The desirable behaviour is to do the following:

  1. Have stored string of the SMT that can be used for multiple calls to the solver
  2. Write this stored string to the file
  3. Add a footer to the file with the specific details of the current call/check (e.g. assumptions and check-sat-assuming).

The modified code stores the common SMT to the cached_output and then writes this at the beginning of each call. The write_footer function (and called functions such as define_object_size) now write to the same internal string stream as all the other SMT conversion code (reducing future misunderstandings like this fixes). The internal string stream is cleared before writing the footer and after, to ensure no accidental duplication of SMT instructions/data.

I hope this has helped clarify.

@TGWDB
Copy link
Contributor

TGWDB commented Jul 1, 2021

I believe this also fixes #5952

@TGWDB TGWDB merged commit 845343e into diffblue:develop Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants