Skip to content

Conversation

@remi-delmas-3000
Copy link
Collaborator

The existing behaviour of cprover_c_library_factory is to load functions only if they already occur in the symbol table. This makes it impossible to load a library function unless a header declaring this function was included in the user's program and the function was actually used in the program.

This patch makes it possible to load functions of the cprover library even if they not already found in the symbol table and makes sure they survive the remove_internal_symbols cleanup pass.

The use case for this is to be able to programatically load functions in the symbol table before generating code that uses these functions as part of function contracts instrumentation.

  • 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.
  • [N/A] The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • [N/A] 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).
  • [N/A] 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.

@remi-delmas-3000 remi-delmas-3000 added blocker aws Bugs or features of importance to AWS CBMC users aws-high labels May 4, 2022
@remi-delmas-3000 remi-delmas-3000 self-assigned this May 4, 2022
@codecov
Copy link

codecov bot commented May 4, 2022

Codecov Report

Merging #6844 (3411b22) into develop (3df1868) will increase coverage by 0.74%.
The diff coverage is 82.14%.

@@             Coverage Diff             @@
##           develop    #6844      +/-   ##
===========================================
+ Coverage    77.04%   77.79%   +0.74%     
===========================================
  Files         1594     1567      -27     
  Lines       185287   179719    -5568     
===========================================
- Hits        142763   139804    -2959     
+ Misses       42524    39915    -2609     
Impacted Files Coverage Δ
src/ansi-c/ansi_c_language.h 75.00% <ø> (ø)
src/goto-instrument/cover_basic_blocks.h 100.00% <ø> (ø)
src/goto-instrument/source_lines.h 100.00% <ø> (ø)
src/goto-programs/show_properties.cpp 64.42% <47.82%> (-5.82%) ⬇️
src/ansi-c/cprover_library.cpp 87.50% <63.63%> (-10.12%) ⬇️
src/goto-checker/cover_goals_report_util.cpp 90.09% <68.96%> (-8.61%) ⬇️
...ecode/java_virtual_functions/virtual_functions.cpp 100.00% <100.00%> (ø)
src/ansi-c/ansi_c_language.cpp 96.51% <100.00%> (+0.08%) ⬆️
src/goto-instrument/cover_basic_blocks.cpp 89.09% <100.00%> (-1.68%) ⬇️
src/goto-instrument/cover_instrument_location.cpp 94.73% <100.00%> (ø)
... and 73 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 8699438...3411b22. Read the comment docs.

Comment on lines 106 to 107
std::string library_text;

library_text=get_cprover_library_text(functions, symbol_table);
library_text = get_cprover_library_text(functions, symbol_table, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

While at it: I don't see why declaration and definition should be separate instructions here, can you please merge them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 135 to 136
std::string library_text;
library_text = get_cprover_library_text(functions, symbol_table, true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

As above: these should not be two instructions.

special.insert("__delete");
special.insert("__delete_array");
// plus any extra symbols we wish to keep
if(!keep.empty())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think that test even is necessary for .empty() is the same as .begin() == .end().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

@TGWDB TGWDB left a comment

Choose a reason for hiding this comment

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

Please include some tests.

@tautschnig
Copy link
Collaborator

Please include some tests.

To have additional tests over the existing ones it will be necessary to add new functionality. That is being built, and is the reason for this PR in the first place. But it will also mean that this PR will become significantly larger.

@remi-delmas-3000
Copy link
Collaborator Author

Hi,

@TGWDB testing this is not possible from the ansi-C front end, so it would require to write C++ unit tests.

I took great care in ensuring no change in behaviour for all preexisting functions which do not have this extra 'keep' argument.

Since this new force-loading feature is meant to support new features in function contract instrumentation, which will themselves be testable from the C front-end, I expect code coverage to be achieved when this new contract instrumentation ships (hopefully before the end of May).

Would you be OK with the following: merge this PR, and simultaneously open a ticket to remind us to check for coverage when the next related PR gets merged ?

Alternatively, I could keep this PR's commits in the history of the next contract-feature PR, but since it is going to be quite substantial, I'd rather have this PR kept separate.

Tell me what you think !

not already found in the symbol table and ensure they survive
`remove_internal_symbols`.
@remi-delmas-3000 remi-delmas-3000 force-pushed the force-load-cprover-library branch from 7967f25 to 3411b22 Compare May 12, 2022 20:58
@tautschnig tautschnig assigned TGWDB and unassigned remi-delmas-3000 May 13, 2022
@TGWDB
Copy link
Contributor

TGWDB commented May 13, 2022

Hi,

@TGWDB testing this is not possible from the ansi-C front end, so it would require to write C++ unit tests.

I took great care in ensuring no change in behaviour for all preexisting functions which do not have this extra 'keep' argument.

Since this new force-loading feature is meant to support new features in function contract instrumentation, which will themselves be testable from the C front-end, I expect code coverage to be achieved when this new contract instrumentation ships (hopefully before the end of May).

Would you be OK with the following: merge this PR, and simultaneously open a ticket to remind us to check for coverage when the next related PR gets merged ?

Alternatively, I could keep this PR's commits in the history of the next contract-feature PR, but since it is going to be quite substantial, I'd rather have this PR kept separate.

Tell me what you think !

Thanks for the explanation. I'm going to approve this and look for tests in future.

@tautschnig tautschnig merged commit ee860d4 into diffblue:develop May 13, 2022
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 aws-high blocker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants