-
Notifications
You must be signed in to change notification settings - Fork 276
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
Restrict function pointers by name #5262
Conversation
0c1597e
to
354cb01
Compare
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}; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
354cb01
to
f55f636
Compare
49f01cc
to
4677cf6
Compare
There was a problem hiding this 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
There was a problem hiding this 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
regression/goto-instrument/restrict-function-pointer-by-name-global/test.c
Show resolved
Hide resolved
|
||
void main() | ||
{ | ||
fp_t fp = f; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
regression/goto-instrument/restrict-function-pointer-by-name-local/test.desc
Show resolved
Hide resolved
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).
9262c73
to
cbffdd8
Compare
@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 |
cbffdd8
to
c8ecc1a
Compare
if(!can_cast_expr<dereference_exprt>(function)) | ||
return {}; | ||
|
||
auto const &function_pointer_call_site = to_symbol_expr( |
There was a problem hiding this comment.
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!
There was a problem hiding this 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
There was a problem hiding this 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
c8ecc1a
to
8c64c36
Compare
8c64c36
to
9545831
Compare
9545831
to
677442a
Compare
- remove unnecessary loop - make it return the restriction instead of inserting it into the map
677442a
to
3528195
Compare
There was a problem hiding this 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 Report
@@ 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
Continue to review full report at Codecov.
|
3528195
to
8154f23
Compare
Replaces #5174.