Skip to content

Add missing DECL and DEAD instructions in function pointer call site labelling #6535

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

Conversation

remi-delmas-3000
Copy link
Collaborator

No change in functionality or performance is expected.

Previously, function pointer call site labelling introduced ASSIGNS and CALL instructions to a fresh function pointer variable in the goto program without adding corresponding DECL and DEAD instructions, which made them look like global variables when they really are local to the function.

This caused problems with function contracts checking, because a function would appear to be writing to a global that is not mentioned in its assigns clause.

We also add a small diagram to document what it means for goto_programt::insert_before_swap to preserve jumps to target.

  • 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).
  • 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.

@remi-delmas-3000 remi-delmas-3000 added aws Bugs or features of importance to AWS CBMC users aws-high labels Dec 17, 2021
@remi-delmas-3000 remi-delmas-3000 self-assigned this Dec 17, 2021
Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

Since you touched this code, would you mind adding the following cleanup:

  1. The lambda inserting the symbol into the symbol table should also set is_thread_local and is_file_local to true.
  2. Instead of the repeated and long-winded goto_model.symbol_table.lookup_ref could you please introduce a namespacet ns{goto_model.symbol_table} early on and replace the goto_model.symbol_table.lookup_ref by ns.lookup?

Also, would it be possible to include a test, for example by adding patterns to regression/goto-instrument/restrict-function-pointer-by-name-local/test.desc that check for the existence of the new DECL/DEAD instructions?

Comment on lines +628 to +643
///
/// Turns:
/// ```
/// ...->[a]->...
/// ^
/// target
/// ```
///
/// Into:
/// ```
/// ...->[i]->[a]->...
/// ^
/// target
/// ```
///
/// So that jumps to `a` now jump to the newly inserted `i`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you! But then: would you mind putting this in a commit of its own?

auto decl_instruction =
goto_programt::make_decl(new_function_pointer, source_location);
goto_function.second.body.insert_before_swap(it, decl_instruction);
it++;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit picking: ++it (which the compiler will likely take care of for you, but why rely on compiler optimisations...).

it++;

// transform original call into a call to the new variable
to_code_function_call(it->code_nonconst()).function() =
Copy link
Collaborator

Choose a reason for hiding this comment

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

it->call_function() = would be a shorter version thereof.

@remi-delmas-3000 remi-delmas-3000 force-pushed the function-pointer-call-site-add-decl-dead branch from 52311df to bd9372b Compare December 17, 2021 23:24
Remi Delmas added 2 commits December 17, 2021 23:40
…ites.

Previously, function pointer call site labelling introduced ASSIGNS and CALL instructions
to a fresh function pointer variable in the goto program without adding corresponding
DECL and DEAD instructions which made them look like global variables when they really
are local to the function.
@remi-delmas-3000 remi-delmas-3000 force-pushed the function-pointer-call-site-add-decl-dead branch from bd9372b to 6642254 Compare December 17, 2021 23:43
@codecov
Copy link

codecov bot commented Dec 18, 2021

Codecov Report

Merging #6535 (6642254) into develop (8834dc5) will increase coverage by 0.00%.
The diff coverage is 94.73%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #6535   +/-   ##
========================================
  Coverage    75.98%   75.99%           
========================================
  Files         1578     1578           
  Lines       180919   180944   +25     
========================================
+ Hits        137476   137500   +24     
- Misses       43443    43444    +1     
Impacted Files Coverage Δ
src/goto-programs/goto_program.h 90.27% <ø> (ø)
src/analyses/goto_check_c.cpp 90.29% <92.30%> (-0.10%) ⬇️
src/goto-programs/goto_convert.cpp 92.03% <100.00%> (+0.07%) ⬆️
...oto-programs/label_function_pointer_call_sites.cpp 100.00% <100.00%> (ø)
src/solvers/smt2/smt2_dec.cpp 76.52% <0.00%> (+0.86%) ⬆️

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 4ec7d9b...6642254. Read the comment docs.

@remi-delmas-3000 remi-delmas-3000 merged commit 7429e79 into diffblue:develop Dec 18, 2021
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants