Skip to content

Invoke goto_functions.update() after inlining #6493

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
Dec 1, 2021

Conversation

tautschnig
Copy link
Collaborator

Inlining will alter location (instruction) numbers, which need to be
updated to once again be globally unique.

This is a follow-up to #6473.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a 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.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

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.

Backedges are a necessary but not sufficient test for loops so may_have_loops is good.

I have a vague recollection of a previous "Call update() after inline" issue / PR.

Comment on lines 696 to 795
goto_function_inline(
goto_functions, function_name, ns, log.get_message_handler());
goto_functions.update();
Copy link
Collaborator

Choose a reason for hiding this comment

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

If one should always call them together, wouldn't be safer to add a proper API with both calls? It'd certainly help us to avoid these mistakes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe. The problem is the cost of these calls. If you're making multiple modifications to goto programs and don't depend on unique instruction numbers, loop numbering in between, then you should not need to invoke it. There are, in fact, a lot more places in the contracts instrumentation code where such updates need to be considered.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we at least mention in the goto_inline.h doc that it breaks the internal consistency of the goto model / function and that a call to goto_functionst::update is needed to restore it? Or maybe in the preconditions of natural_loops ?

What type of modifications require calls to update ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, I am wondering where to best document (or implement!) this. Any operations that add or remove instructions for a goto program require calls to update. I realise that goto_programt::validate does not actually check for these properties (as documented with the location_number and loop_number members of goto_programt::instructiont).

@feliperodri feliperodri added aws Bugs or features of importance to AWS CBMC users bugfix labels Nov 30, 2021
@codecov
Copy link

codecov bot commented Nov 30, 2021

Codecov Report

Merging #6493 (3af4718) into develop (f245b3a) will decrease coverage by 0.00%.
The diff coverage is 81.74%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #6493      +/-   ##
===========================================
- Coverage    76.06%   76.06%   -0.01%     
===========================================
  Files         1546     1546              
  Lines       165584   165618      +34     
===========================================
+ Hits        125951   125975      +24     
- Misses       39633    39643      +10     
Impacted Files Coverage Δ
...java_bytecode/java_bytecode_internal_additions.cpp 100.00% <ø> (ø)
src/analyses/escape_analysis.cpp 63.83% <ø> (ø)
src/ansi-c/ansi_c_internal_additions.cpp 90.36% <ø> (ø)
src/ansi-c/c_typecheck_base.h 100.00% <ø> (ø)
src/crangler/ctokenit.cpp 0.00% <0.00%> (ø)
src/crangler/ctokenit.h 0.00% <0.00%> (ø)
src/goto-instrument/contracts/assigns.h 100.00% <ø> (ø)
src/goto-instrument/contracts/contracts.h 100.00% <ø> (ø)
src/goto-instrument/contracts/utils.h 100.00% <ø> (ø)
src/goto-programs/goto_convert_class.h 87.30% <ø> (ø)
... and 124 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 7eceeb5...3af4718. Read the comment docs.

@tautschnig tautschnig force-pushed the followup-6473 branch 2 times, most recently from 2a96d8c to 2d691ea Compare December 1, 2021 12:18
Inlining will alter location (instruction) numbers, which need to be
updated to once again be globally unique.

With this change, invar_check_large requires an assigns clause for the
loop as the local may alias analysis returns "UNKNOWN." The previous
result was actually unsound, because the automatically computed assigns
set did not include arr0, arr1, arr2, arr3, arr4. This also demonstrated
that the implementation in the test was incorrect: it would not terminate when:
*(arr[h]) == pivot && *(arr[l]) == pivot && h != r && l != r.
@tautschnig tautschnig merged commit 03a24d9 into diffblue:develop Dec 1, 2021
@tautschnig tautschnig deleted the followup-6473 branch December 1, 2021 18:46
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants