Skip to content

Restrict function pointers by name #5262

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

danpoe
Copy link
Contributor

@danpoe danpoe commented Mar 7, 2020

Replaces #5174.

  • 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.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@danpoe danpoe changed the title Restrict function pointer by name feature Restrict function pointer by name feature [depends-on: #5257] Mar 7, 2020
@danpoe danpoe added the aws Bugs or features of importance to AWS CBMC users label Mar 7, 2020
@danpoe danpoe changed the title Restrict function pointer by name feature [depends-on: #5257] Restrict function pointers by name [depends-on: #5257] Mar 7, 2020
@danpoe danpoe force-pushed the feature/restrict-function-pointer-by-name branch from 0c1597e to 354cb01 Compare March 7, 2020 19:56
restriction_format_message};
}
if(pointer_name_end == 0)
{
throw invalid_command_line_argument_exceptiont{
"couldn't find target name before '/' in `" + restriction_opt + "'",
"--" RESTRICT_FUNCTION_POINTER_OPT};
option_name};

Choose a reason for hiding this comment

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

🚫 option

@@ -328,22 +349,83 @@ parse_function_pointer_restrictions_from_file(
}
return merged_restrictions;
}

function_pointer_restrictionst::restrictionst

Choose a reason for hiding this comment

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

The purpose of this needs to be documented, I am fairly sure I wrote this and it took me like 5 minutes trying to figure out what this was doing and why

@danpoe danpoe force-pushed the feature/restrict-function-pointer-by-name branch from 354cb01 to f55f636 Compare March 16, 2020 16:08
@danpoe danpoe changed the title Restrict function pointers by name [depends-on: #5257] Restrict function pointers by name Mar 16, 2020
@danpoe danpoe force-pushed the feature/restrict-function-pointer-by-name branch 4 times, most recently from 49f01cc to 4677cf6 Compare March 18, 2020 19:02
Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

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

Will review tests after lunch.

Note to other reviews: it is easier to review all at once rather than by commit

Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

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

🚫 need a test that assigns a fp on a line a few lines before the call


void main()
{
fp_t fp = f;
Copy link
Contributor

Choose a reason for hiding this comment

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

🐑

}

fptr_t get_f(void)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess all this deletion would be clearer if put in its own commit explaining why

This works similar to restrict-function-pointer, but for names of individual
function pointer variables (globals, locals, parameters) rather than call sites.
This isn't applicable to all situations (for example, calling function pointers
in structs or function pointers returned from functions), but is more readily
applicable to some common use scenarios (e.g. global function pointers loaded at
start time like in OpenGL).
@danpoe danpoe force-pushed the feature/restrict-function-pointer-by-name branch 4 times, most recently from 9262c73 to cbffdd8 Compare March 23, 2020 17:02
@danpoe
Copy link
Contributor Author

danpoe commented Mar 24, 2020

@thk123 A test that assigns a function pointer a few lines before the call is not necessary. The reason we look for those assignments is because the label_function_pointer_calls pass inserts them, and it always does so immediately before the call. (I've also removed the loops that search for these assignments and replaced them by a check of just the previous instruction)

@danpoe danpoe force-pushed the feature/restrict-function-pointer-by-name branch from cbffdd8 to c8ecc1a Compare March 24, 2020 15:51
if(!can_cast_expr<dereference_exprt>(function))
return {};

auto const &function_pointer_call_site = to_symbol_expr(
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Even a comment here:

// function pointer guarateed to be a symbol by the function-pointer-label pass

Where function-pointer-label should be an actual file/folder/function that can be searched for!

Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

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

Looks good from a code perspective.

Call me a Luddite, but even knowing the code doesn't rely on an assignment from a few lines before, I think it would be good to add the test, since not obvious to me that this is true.

I also would feel better about the test without it having distinct regexes so we know it remains doing something

Other than that, lgtm 👍 thanks for addressing comments

Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

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

Only reviewed the main changed, not the tests

@danpoe danpoe force-pushed the feature/restrict-function-pointer-by-name branch from c8ecc1a to 8c64c36 Compare March 24, 2020 16:54
@danpoe danpoe force-pushed the feature/restrict-function-pointer-by-name branch from 8c64c36 to 9545831 Compare March 24, 2020 17:06
@danpoe danpoe force-pushed the feature/restrict-function-pointer-by-name branch from 9545831 to 677442a Compare March 24, 2020 17:16
- remove unnecessary loop
- make it return the restriction instead of inserting it into the map
@danpoe danpoe force-pushed the feature/restrict-function-pointer-by-name branch from 677442a to 3528195 Compare March 24, 2020 17:59
Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

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

Dan pointed out that all the tests that don't have a local variable are testing what I was referring to.

@codecov-io
Copy link

codecov-io commented Mar 24, 2020

Codecov Report

Merging #5262 into develop will decrease coverage by 35.74%.
The diff coverage is 35.86%.

Impacted file tree graph

@@             Coverage Diff              @@
##           develop    #5262       +/-   ##
============================================
- Coverage    67.50%   31.76%   -35.75%     
============================================
  Files         1170      918      -252     
  Lines        96287    80144    -16143     
============================================
- Hits         65003    25460    -39543     
- Misses       31284    54684    +23400     
Flag Coverage Δ
#cproversmt2 ?
#regression ?
#unit 31.76% <35.86%> (+0.02%) ⬆️
Impacted Files Coverage Δ
src/goto-programs/restrict_function_pointers.cpp 39.10% <35.16%> (-42.31%) ⬇️
src/goto-programs/restrict_function_pointers.h 100.00% <100.00%> (ø)
src/cpp/cpp_id.h 0.00% <0.00%> (-100.00%) ⬇️
src/cpp/cpp_scope.h 0.00% <0.00%> (-100.00%) ⬇️
src/cpp/cpp_token.h 0.00% <0.00%> (-100.00%) ⬇️
src/cpp/cpp_name.cpp 0.00% <0.00%> (-100.00%) ⬇️
src/cpp/cpp_util.cpp 0.00% <0.00%> (-100.00%) ⬇️
src/util/identifier.h 0.00% <0.00%> (-100.00%) ⬇️
src/xmllang/graphml.h 0.00% <0.00%> (-100.00%) ⬇️
src/cpp/cpp_is_pod.cpp 0.00% <0.00%> (-100.00%) ⬇️
... and 890 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 094fc97...3528195. Read the comment docs.

@danpoe danpoe force-pushed the feature/restrict-function-pointer-by-name branch from 3528195 to 8154f23 Compare March 24, 2020 19:30
@danpoe danpoe merged commit 7e27cb2 into diffblue:develop Mar 24, 2020
@danpoe danpoe deleted the feature/restrict-function-pointer-by-name branch June 2, 2020 17:06
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants