-
Notifications
You must be signed in to change notification settings - Fork 273
Clean Const Function Pointer Removal #519
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
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
89562ca
Adding tests for function pointer removal
995f504
Made remove_function_pointers inherit from messaget
563a351
First implemention of the new approach
3b3acd6
Support for removing the typecast
e4829eb
Adding support for top level pointers and typecasts
11f15ee
Fixing arrays containing null pointers
a479c98
Correctly deal with const structures
921f0b7
Fixing component access and const access
b814d65
Fixing todo to use separate array
22ca113
Corrected const-ness for components
d87dffd
Handle failure to squash the value when getting out of an array
f51b252
Correcting const check for pointers
1fbfbbc
Adding examples to tests of what the const prevents
5ab672a
Corrected const check for no FP pointers
0499b44
Added tests to cover a couple of missed lines
208ef2b
Fixed issue with structs with other components
3da26cd
Adding test for another way the previous bug could be exhibited
eefba98
Adding a test variation of 44 without the consts that fails correctly
132801a
Squash constant symbols first
931b239
Fixed major bug with non const structs
2e94125
Removing redundant code
63afb80
Added logging for all the ways the FP removal might not complete
9da5ba2
Adding consistency checks for the output
d81f6cb
Adding comments to remove_const_function_pointers
3e669c0
Renamed all the tests
a6e71e0
Tidied up tests
ea5c151
Fixing compile errors for musketeer
f68ff26
Refactored resolve_index_of_function_call
6298fea
Split out functions from try_resolve_function_call
5d33d4d
Made the behaviour of try_resolve_function_call clearer
a75957b
Split up try_resolve_expression into functions
37660b1
Made other try_resolve*_function_call use the normal method
8362233
Extracted element dealing with calling resolve on each result
e57677e
Adding the pointer check flag
0de6b17
Adding checks for NULL function pointers
10a08ef
Renaming functions to more consistent name
cf6a49a
Swap to using an unorded set
db11c31
Added flag for goto-instrument to just remove const function pointers
052da5a
Check the GOTO program for loss of const
6ba0469
Added a couple of missed test cases.
18b5907
Fixing tests to work with new test.pl
2538f4f
Fixing missing new lines
29e7e0d
Split out the const check into own analysis
649e0bf
Descend all children of the same base type
4607e73
PR Feedback implementation
d7c15ae
Use pointers in is_type_at_least_as_const_as
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
regression/goto-analyzer/approx-array-variable-const-fp/main.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <stdio.h> | ||
|
||
void f1 (void) { printf("%i\n", 1); } | ||
void f2 (void) { printf("%i\n", 2); } | ||
void f3 (void) { printf("%i\n", 3); } | ||
void f4 (void) { printf("%i\n", 4); } | ||
void f5 (void) { printf("%i\n", 5); } | ||
void f6 (void) { printf("%i\n", 6); } | ||
void f7 (void) { printf("%i\n", 7); } | ||
void f8 (void) { printf("%i\n", 8); } | ||
void f9 (void) { printf("%i\n", 9); } | ||
|
||
typedef void(*void_fp)(void); | ||
|
||
const void_fp fp_tbl[] = {f2, f3 ,f4}; | ||
|
||
// There is a basic check that excludes all functions that aren't used anywhere | ||
// This ensures that check can't work in this example | ||
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9}; | ||
|
||
void func(int i) | ||
{ | ||
fp_tbl[i](); | ||
} | ||
|
||
int main() | ||
{ | ||
for(int i=0;i<3;i++) | ||
{ | ||
func(i); | ||
} | ||
|
||
return 0; | ||
} | ||
17 changes: 17 additions & 0 deletions
17
regression/goto-analyzer/approx-array-variable-const-fp/test.desc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
CORE | ||
main.c | ||
--show-goto-functions --verbosity 10 --pointer-check | ||
|
||
^Removing function pointers and virtual functions$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f2 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f3 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f4 THEN GOTO [0-9]$ | ||
^SIGNAL=0$ | ||
-- | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f1 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f5 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f6 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f7 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f8 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f9 THEN GOTO [0-9]$ | ||
^warning: ignoring |
41 changes: 41 additions & 0 deletions
41
regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/main.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <stdio.h> | ||
|
||
void f1 (void) { printf("%i\n", 1); } | ||
void f2 (void) { printf("%i\n", 2); } | ||
void f3 (void) { printf("%i\n", 3); } | ||
void f4 (void) { printf("%i\n", 4); } | ||
void f5 (void) { printf("%i\n", 5); } | ||
void f6 (void) { printf("%i\n", 6); } | ||
void f7 (void) { printf("%i\n", 7); } | ||
void f8 (void) { printf("%i\n", 8); } | ||
void f9 (void) { printf("%i\n", 9); } | ||
|
||
typedef void(*void_fp)(void); | ||
|
||
// There is a basic check that excludes all functions that aren't used anywhere | ||
// This ensures that check can't work in this example | ||
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9}; | ||
|
||
void(* const fp_tbl[3])(void) = | ||
{ | ||
(void(*)())f2, | ||
(void(*)())f3, | ||
(void(*)())f4, | ||
}; | ||
|
||
|
||
void func(int i) | ||
{ | ||
const void_fp fp = fp_tbl[i]; | ||
fp(); | ||
} | ||
|
||
int main() | ||
{ | ||
for(int i=0;i<3;i++) | ||
{ | ||
func(i); | ||
} | ||
|
||
return 0; | ||
} |
17 changes: 17 additions & 0 deletions
17
regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
CORE | ||
main.c | ||
--show-goto-functions --verbosity 10 --pointer-check | ||
|
||
^Removing function pointers and virtual functions$ | ||
^\s*IF fp == f2 THEN GOTO [0-9]$ | ||
^\s*IF fp == f3 THEN GOTO [0-9]$ | ||
^\s*IF fp == f4 THEN GOTO [0-9]$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f1 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f5 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f6 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f7 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f8 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f9 THEN GOTO [0-9]$ |
35 changes: 35 additions & 0 deletions
35
regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/main.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <stdio.h> | ||
|
||
void f1 (void) { printf("%i\n", 1); } | ||
void f2 (void) { printf("%i\n", 2); } | ||
void f3 (void) { printf("%i\n", 3); } | ||
void f4 (void) { printf("%i\n", 4); } | ||
void f5 (void) { printf("%i\n", 5); } | ||
void f6 (void) { printf("%i\n", 6); } | ||
void f7 (void) { printf("%i\n", 7); } | ||
void f8 (void) { printf("%i\n", 8); } | ||
void f9 (void) { printf("%i\n", 9); } | ||
|
||
typedef void(*void_fp)(void); | ||
|
||
const void_fp fp_tbl[] = {f2, f3 ,f4, 0}; | ||
|
||
// There is a basic check that excludes all functions that aren't used anywhere | ||
// This ensures that check can't work in this example | ||
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9}; | ||
|
||
void func(int i) | ||
{ | ||
const void_fp fp = fp_tbl[i]; | ||
fp(); | ||
} | ||
|
||
int main() | ||
{ | ||
for(int i=0;i<3;i++) | ||
{ | ||
func(i); | ||
} | ||
|
||
return 0; | ||
} |
17 changes: 17 additions & 0 deletions
17
regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
CORE | ||
main.c | ||
--show-goto-functions --verbosity 10 --pointer-check | ||
|
||
^Removing function pointers and virtual functions$ | ||
^\s*IF fp == f2 THEN GOTO [0-9]$ | ||
^\s*IF fp == f3 THEN GOTO [0-9]$ | ||
^\s*IF fp == f4 THEN GOTO [0-9]$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f1 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f5 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f6 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f7 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f8 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f9 THEN GOTO [0-9]$ |
35 changes: 35 additions & 0 deletions
35
regression/goto-analyzer/approx-const-fp-array-variable-const-fp/main.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <stdio.h> | ||
|
||
void f1 (void) { printf("%i\n", 1); } | ||
void f2 (void) { printf("%i\n", 2); } | ||
void f3 (void) { printf("%i\n", 3); } | ||
void f4 (void) { printf("%i\n", 4); } | ||
void f5 (void) { printf("%i\n", 5); } | ||
void f6 (void) { printf("%i\n", 6); } | ||
void f7 (void) { printf("%i\n", 7); } | ||
void f8 (void) { printf("%i\n", 8); } | ||
void f9 (void) { printf("%i\n", 9); } | ||
|
||
typedef void(*void_fp)(void); | ||
|
||
const void_fp fp_tbl[] = {f2, f3 ,f4}; | ||
|
||
// There is a basic check that excludes all functions that aren't used anywhere | ||
// This ensures that check can't work in this example | ||
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9}; | ||
|
||
void func(int i) | ||
{ | ||
const void_fp fp = fp_tbl[i]; | ||
fp(); | ||
} | ||
|
||
int main() | ||
{ | ||
for(int i=0;i<3;i++) | ||
{ | ||
func(i); | ||
} | ||
|
||
return 0; | ||
} |
17 changes: 17 additions & 0 deletions
17
regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
CORE | ||
main.c | ||
--show-goto-functions --verbosity 10 --pointer-check | ||
|
||
^Removing function pointers and virtual functions$ | ||
^\s*IF fp == f2 THEN GOTO [0-9]$ | ||
^\s*IF fp == f3 THEN GOTO [0-9]$ | ||
^\s*IF fp == f4 THEN GOTO [0-9]$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f1 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f5 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f6 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f7 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f8 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f9 THEN GOTO [0-9]$ |
50 changes: 50 additions & 0 deletions
50
...to-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/main.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <stdio.h> | ||
|
||
void f1 (void) { printf("%i\n", 1); } | ||
void f2 (void) { printf("%i\n", 2); } | ||
void f3 (void) { printf("%i\n", 3); } | ||
void f4 (void) { printf("%i\n", 4); } | ||
void f5 (void) { printf("%i\n", 5); } | ||
void f6 (void) { printf("%i\n", 6); } | ||
void f7 (void) { printf("%i\n", 7); } | ||
void f8 (void) { printf("%i\n", 8); } | ||
void f9 (void) { printf("%i\n", 9); } | ||
|
||
typedef void(*void_fp)(void); | ||
|
||
struct action | ||
{ | ||
void_fp fun; | ||
}; | ||
|
||
const struct action rec = { .fun = f2 }; | ||
const struct action rec2 = { .fun = f3 }; | ||
const struct action rec3 = { .fun = f4 }; | ||
|
||
const struct action * const action_list[4] = | ||
{ | ||
&rec, | ||
&rec2, | ||
&rec3, | ||
&rec | ||
}; | ||
|
||
// There is a basic check that excludes all functions that aren't used anywhere | ||
// This ensures that check can't work in this example | ||
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9}; | ||
|
||
void func(int i) | ||
{ | ||
const void_fp fp = action_list[i]->fun; | ||
fp(); | ||
} | ||
|
||
int main() | ||
{ | ||
for(int i=0;i<3;i++) | ||
{ | ||
func(i); | ||
} | ||
|
||
return 0; | ||
} |
17 changes: 17 additions & 0 deletions
17
...analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
CORE | ||
main.c | ||
--show-goto-functions --verbosity 10 --pointer-check | ||
|
||
^Removing function pointers and virtual functions$ | ||
^\s*IF fp == f2 THEN GOTO [0-9]$ | ||
^\s*IF fp == f3 THEN GOTO [0-9]$ | ||
^\s*IF fp == f4 THEN GOTO [0-9]$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f1 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f5 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f6 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f7 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f8 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f9 THEN GOTO [0-9]$ |
51 changes: 51 additions & 0 deletions
51
regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/main.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <stdio.h> | ||
|
||
void f1 (void) { printf("%i\n", 1); } | ||
void f2 (void) { printf("%i\n", 2); } | ||
void f3 (void) { printf("%i\n", 3); } | ||
void f4 (void) { printf("%i\n", 4); } | ||
void f5 (void) { printf("%i\n", 5); } | ||
void f6 (void) { printf("%i\n", 6); } | ||
void f7 (void) { printf("%i\n", 7); } | ||
void f8 (void) { printf("%i\n", 8); } | ||
void f9 (void) { printf("%i\n", 9); } | ||
|
||
typedef void(*void_fp)(void); | ||
|
||
// There is a basic check that excludes all functions that aren't used anywhere | ||
// This ensures that check can't work in this example | ||
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9}; | ||
|
||
struct stable | ||
{ | ||
int x; | ||
void (*fp)(void); | ||
}; | ||
|
||
const struct stable stable_table [3] = | ||
{ | ||
{ 1, f2 }, | ||
{ 2, f3 }, | ||
{ 3, f4 } | ||
}; | ||
|
||
const struct stable another_table = { 4, f5 }; | ||
|
||
|
||
void func(int i) | ||
{ | ||
const void_fp fp = stable_table[i].fp; | ||
|
||
// Illegal | ||
// stable_table[1] = another_table; | ||
fp(); | ||
} | ||
|
||
int main() | ||
{ | ||
for(int i=0;i<3;i++) | ||
{ | ||
func(i); | ||
} | ||
return 0; | ||
} |
17 changes: 17 additions & 0 deletions
17
regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
CORE | ||
main.c | ||
--show-goto-functions --verbosity 10 --pointer-check | ||
|
||
^Removing function pointers and virtual functions$ | ||
^\s*IF fp == f2 THEN GOTO [0-9]$ | ||
^\s*IF fp == f3 THEN GOTO [0-9]$ | ||
^\s*IF fp == f4 THEN GOTO [0-9]$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f1 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f5 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f6 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f7 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f8 THEN GOTO [0-9]$ | ||
^\s*IF fp_tbl\[\(signed long int\)i\] == f9 THEN GOTO [0-9]$ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
missing newline at end of file (and other files)
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.
This should now be fixed