Skip to content

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 46 commits into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
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
Jan 13, 2017
995f504
Made remove_function_pointers inherit from messaget
Jan 30, 2017
563a351
First implemention of the new approach
Feb 2, 2017
3b3acd6
Support for removing the typecast
Feb 2, 2017
e4829eb
Adding support for top level pointers and typecasts
Feb 2, 2017
11f15ee
Fixing arrays containing null pointers
Feb 2, 2017
a479c98
Correctly deal with const structures
Feb 2, 2017
921f0b7
Fixing component access and const access
Feb 2, 2017
b814d65
Fixing todo to use separate array
Feb 6, 2017
22ca113
Corrected const-ness for components
Feb 7, 2017
d87dffd
Handle failure to squash the value when getting out of an array
Feb 7, 2017
f51b252
Correcting const check for pointers
Feb 7, 2017
1fbfbbc
Adding examples to tests of what the const prevents
Feb 7, 2017
5ab672a
Corrected const check for no FP pointers
Feb 7, 2017
0499b44
Added tests to cover a couple of missed lines
Feb 7, 2017
208ef2b
Fixed issue with structs with other components
Feb 8, 2017
3da26cd
Adding test for another way the previous bug could be exhibited
Feb 8, 2017
eefba98
Adding a test variation of 44 without the consts that fails correctly
Feb 8, 2017
132801a
Squash constant symbols first
Feb 8, 2017
931b239
Fixed major bug with non const structs
Feb 8, 2017
2e94125
Removing redundant code
Feb 8, 2017
63afb80
Added logging for all the ways the FP removal might not complete
Feb 8, 2017
9da5ba2
Adding consistency checks for the output
Feb 9, 2017
d81f6cb
Adding comments to remove_const_function_pointers
Feb 9, 2017
3e669c0
Renamed all the tests
Feb 9, 2017
a6e71e0
Tidied up tests
Feb 10, 2017
ea5c151
Fixing compile errors for musketeer
Feb 10, 2017
f68ff26
Refactored resolve_index_of_function_call
Feb 10, 2017
6298fea
Split out functions from try_resolve_function_call
Feb 10, 2017
5d33d4d
Made the behaviour of try_resolve_function_call clearer
Feb 10, 2017
a75957b
Split up try_resolve_expression into functions
Feb 10, 2017
37660b1
Made other try_resolve*_function_call use the normal method
Feb 10, 2017
8362233
Extracted element dealing with calling resolve on each result
Feb 10, 2017
e57677e
Adding the pointer check flag
Feb 13, 2017
0de6b17
Adding checks for NULL function pointers
Feb 13, 2017
10a08ef
Renaming functions to more consistent name
Feb 13, 2017
cf6a49a
Swap to using an unorded set
Feb 13, 2017
db11c31
Added flag for goto-instrument to just remove const function pointers
Feb 13, 2017
052da5a
Check the GOTO program for loss of const
Feb 14, 2017
6ba0469
Added a couple of missed test cases.
Feb 16, 2017
18b5907
Fixing tests to work with new test.pl
Feb 16, 2017
2538f4f
Fixing missing new lines
Feb 20, 2017
29e7e0d
Split out the const check into own analysis
Mar 20, 2017
649e0bf
Descend all children of the same base type
Mar 21, 2017
4607e73
PR Feedback implementation
Mar 22, 2017
d7c15ae
Use pointers in is_type_at_least_as_const_as
Mar 22, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions regression/goto-analyzer/approx-array-variable-const-fp/main.c
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;
}
Copy link
Member

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)

Copy link
Contributor Author

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

17 changes: 17 additions & 0 deletions regression/goto-analyzer/approx-array-variable-const-fp/test.desc
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
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;
}
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]$
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;
}
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]$
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;
}
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]$
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;
}
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]$
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;
}
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]$
Loading