Skip to content

Use remove-function-pointers code for restricted function pointers #6376

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

We had two instances of code generating an if-else sequence of function
calls for function pointers. The code used with
--restrict-function-pointer, however, was not able to cope with type
mismatches. Make the code from remove_function_pointers re-usable in
both contexts, enabling support for additional type casts.

Fixes: #6368

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

{
std::stringstream comment;

comment << "dereferenced function pointer at must be ";
Copy link

Choose a reason for hiding this comment

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

Needs location after at?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, thanks! (Well, I actually removed the location.)

}
else if(candidates.empty())
{
comment.str("no candidates for dereferenced function pointer");
Copy link

Choose a reason for hiding this comment

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

Location here too would be great.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My rationale for omitting this is that the location will be provided anyway, I don't think we need to repeat it.

@feliperodri feliperodri added the aws Bugs or features of importance to AWS CBMC users label Nov 11, 2021
@tautschnig tautschnig force-pushed the restrictions branch 2 times, most recently from d6fa9bd to 74bc2fe Compare November 11, 2021 20:49
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.

Yes. There seem to be a number of different but overlapping changes in this PR. There is a little formatting, threading the logging infrastructure through the functions, converting the generation code, catching up on the changed output, etc. I realise that in this case it is not really easy to separate these but in future, if possible, separate commits would make this easier to review.

@@ -131,9 +101,10 @@ remove_function_pointerst::remove_function_pointerst(
}
}

bool remove_function_pointerst::arg_is_type_compatible(
static bool arg_is_type_compatible(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason for preferring static functions over private member functions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As I made remove_function_pointer a global function, I had to have a way to use these functions.

goto_programt &goto_program,
const irep_idt &function_id,
goto_programt::targett target,
const std::unordered_set<symbol_exprt, irep_hash> &functions,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the key line right? It gives a way of passing a map to function pointer removal and this splitting the process into "generate function maps" and "convert code using the maps"?

@codecov
Copy link

codecov bot commented Nov 11, 2021

Codecov Report

Merging #6376 (d825d04) into develop (57ee7ac) will increase coverage by 0.00%.
The diff coverage is 96.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #6376   +/-   ##
========================================
  Coverage    76.04%   76.04%           
========================================
  Files         1546     1546           
  Lines       165541   165536    -5     
========================================
+ Hits        125882   125888    +6     
+ Misses       39659    39648   -11     
Impacted Files Coverage Δ
src/goto-programs/restrict_function_pointers.h 100.00% <ø> (ø)
src/goto-programs/restrict_function_pointers.cpp 79.11% <80.00%> (-3.09%) ⬇️
.../goto-instrument/goto_instrument_parse_options.cpp 68.29% <100.00%> (ø)
src/goto-programs/remove_function_pointers.cpp 92.48% <100.00%> (+0.69%) ⬆️
src/pointer-analysis/value_set.cpp 82.94% <100.00%> (+1.75%) ⬆️
src/pointer-analysis/value_set_dereference.cpp 95.03% <0.00%> (+0.33%) ⬆️

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 d460e1c...d825d04. Read the comment docs.

@tautschnig
Copy link
Collaborator Author

Yes. There seem to be a number of different but overlapping changes in this PR. There is a little formatting, threading the logging infrastructure through the functions, converting the generation code, catching up on the changed output, etc. I realise that in this case it is not really easy to separate these but in future, if possible, separate commits would make this easier to review.

You're absolutely right that I should have tried to factor this into multiple commits. I had kept this in mind even when making the changes, but struggled to make it happen. And, upon a second look, I still struggle. So unless I'm really forced to, I'd rather keep it as is.

We had two instances of code generating an if-else sequence of function
calls for function pointers. The code used with
--restrict-function-pointer, however, was not able to cope with type
mismatches. Make the code from remove_function_pointers re-usable in
both contexts, enabling support for additional type casts.

Fixes: diffblue#6368
@tautschnig tautschnig assigned tautschnig and unassigned kroening Dec 1, 2021
@tautschnig tautschnig merged commit faaf50e into diffblue:develop Dec 1, 2021
@tautschnig tautschnig deleted the restrictions branch December 1, 2021 13:40
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 cleanup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Input validation problems with --function-pointer-restrictions-file
5 participants