From 89562ca5955df4d5ad76ecbd9419e48a21ebb98a Mon Sep 17 00:00:00 2001 From: thk123 Date: Fri, 13 Jan 2017 11:32:34 +0000 Subject: [PATCH 01/46] Adding tests for function pointer removal These tests demonstrate the different ways in which we could easily do better in function pointer resolution. At the moment, each example thinks the function pointer could be any of the 9 functions but in all cases can do much better (either know exactly the function or subset of functions) Added const to arrays that aren't modified which will then be used to determine arrays whose contents can be known. Added test for arrays that are not constant and are in fact modified. Adding test for when FP array declared as a pointer The function pointer optimsation can be further improved by dealing with things like structs and pointers to function pointers. More detail is outlined in https://github.com/diffblue/cbmc/issues/476 Added test for nullptr terminated arrays Adding const struct regression tests FPs may not always be assigned into a const FP and instead may be called in place (e.g. directly from the array). This modifies the exprt structure that must be unpacked. These tests demonstrate the different ways that can be done. Adding and correcting tests for pointers to FPs --- regression/goto-analyzer/fp-removal1/main.c | 27 +++++++ .../goto-analyzer/fp-removal1/test.desc | 8 ++ regression/goto-analyzer/fp-removal10/main.c | 31 ++++++++ .../goto-analyzer/fp-removal10/test.desc | 17 +++++ regression/goto-analyzer/fp-removal11/main.c | 31 ++++++++ .../goto-analyzer/fp-removal11/test.desc | 17 +++++ regression/goto-analyzer/fp-removal12/main.c | 38 ++++++++++ .../goto-analyzer/fp-removal12/test.desc | 15 ++++ regression/goto-analyzer/fp-removal13/main.c | 41 +++++++++++ .../goto-analyzer/fp-removal13/test.desc | 15 ++++ regression/goto-analyzer/fp-removal14/main.c | 32 ++++++++ .../goto-analyzer/fp-removal14/test.desc | 15 ++++ regression/goto-analyzer/fp-removal15/main.c | 28 +++++++ .../goto-analyzer/fp-removal15/test.desc | 17 +++++ regression/goto-analyzer/fp-removal16/main.c | 31 ++++++++ .../goto-analyzer/fp-removal16/test.desc | 16 ++++ regression/goto-analyzer/fp-removal17/main.c | 29 ++++++++ .../goto-analyzer/fp-removal17/test.desc | 8 ++ regression/goto-analyzer/fp-removal19/main.c | 35 +++++++++ .../goto-analyzer/fp-removal19/test.desc | 11 +++ regression/goto-analyzer/fp-removal2/main.c | 29 ++++++++ .../goto-analyzer/fp-removal2/test.desc | 8 ++ regression/goto-analyzer/fp-removal20/main.c | 73 +++++++++++++++++++ .../goto-analyzer/fp-removal20/test.desc | 11 +++ regression/goto-analyzer/fp-removal21/main.c | 46 ++++++++++++ .../goto-analyzer/fp-removal21/test.desc | 11 +++ regression/goto-analyzer/fp-removal22/main.c | 28 +++++++ .../goto-analyzer/fp-removal22/test.desc | 11 +++ regression/goto-analyzer/fp-removal23/main.c | 35 +++++++++ .../goto-analyzer/fp-removal23/test.desc | 9 +++ regression/goto-analyzer/fp-removal24/main.c | 43 +++++++++++ .../goto-analyzer/fp-removal24/test.desc | 9 +++ regression/goto-analyzer/fp-removal25/main.c | 45 ++++++++++++ .../goto-analyzer/fp-removal25/test.desc | 11 +++ regression/goto-analyzer/fp-removal26/main.c | 41 +++++++++++ .../goto-analyzer/fp-removal26/test.desc | 11 +++ regression/goto-analyzer/fp-removal27/main.c | 30 ++++++++ .../goto-analyzer/fp-removal27/test.desc | 16 ++++ regression/goto-analyzer/fp-removal28/main.c | 38 ++++++++++ .../goto-analyzer/fp-removal28/test.desc | 11 +++ regression/goto-analyzer/fp-removal29/main.c | 37 ++++++++++ .../goto-analyzer/fp-removal29/test.desc | 17 +++++ regression/goto-analyzer/fp-removal3/main.c | 29 ++++++++ .../goto-analyzer/fp-removal3/test.desc | 8 ++ regression/goto-analyzer/fp-removal30/main.c | 34 +++++++++ .../goto-analyzer/fp-removal30/test.desc | 9 +++ regression/goto-analyzer/fp-removal31/main.c | 27 +++++++ .../goto-analyzer/fp-removal31/test.desc | 15 ++++ regression/goto-analyzer/fp-removal32/main.c | 36 +++++++++ .../goto-analyzer/fp-removal32/test.desc | 9 +++ regression/goto-analyzer/fp-removal33/main.c | 28 +++++++ .../goto-analyzer/fp-removal33/test.desc | 8 ++ regression/goto-analyzer/fp-removal34/main.c | 27 +++++++ .../goto-analyzer/fp-removal34/test.desc | 11 +++ regression/goto-analyzer/fp-removal35/main.c | 29 ++++++++ .../goto-analyzer/fp-removal35/test.desc | 11 +++ regression/goto-analyzer/fp-removal36/main.c | 43 +++++++++++ .../goto-analyzer/fp-removal36/test.desc | 20 +++++ regression/goto-analyzer/fp-removal37/main.c | 46 ++++++++++++ .../goto-analyzer/fp-removal37/test.desc | 9 +++ regression/goto-analyzer/fp-removal38/main.c | 33 +++++++++ .../goto-analyzer/fp-removal38/test.desc | 15 ++++ regression/goto-analyzer/fp-removal39/main.c | 37 ++++++++++ .../goto-analyzer/fp-removal39/test.desc | 23 ++++++ regression/goto-analyzer/fp-removal4/main.c | 30 ++++++++ .../goto-analyzer/fp-removal4/test.desc | 8 ++ regression/goto-analyzer/fp-removal40/main.c | 25 +++++++ .../goto-analyzer/fp-removal40/test.desc | 17 +++++ regression/goto-analyzer/fp-removal41/main.c | 29 ++++++++ .../goto-analyzer/fp-removal41/test.desc | 17 +++++ regression/goto-analyzer/fp-removal5/main.c | 28 +++++++ .../goto-analyzer/fp-removal5/test.desc | 11 +++ regression/goto-analyzer/fp-removal6/main.c | 27 +++++++ .../goto-analyzer/fp-removal6/test.desc | 17 +++++ regression/goto-analyzer/fp-removal7/main.c | 25 +++++++ .../goto-analyzer/fp-removal7/test.desc | 17 +++++ regression/goto-analyzer/fp-removal8/main.c | 33 +++++++++ .../goto-analyzer/fp-removal8/test.desc | 17 +++++ 78 files changed, 1840 insertions(+) create mode 100644 regression/goto-analyzer/fp-removal1/main.c create mode 100644 regression/goto-analyzer/fp-removal1/test.desc create mode 100644 regression/goto-analyzer/fp-removal10/main.c create mode 100644 regression/goto-analyzer/fp-removal10/test.desc create mode 100644 regression/goto-analyzer/fp-removal11/main.c create mode 100644 regression/goto-analyzer/fp-removal11/test.desc create mode 100644 regression/goto-analyzer/fp-removal12/main.c create mode 100644 regression/goto-analyzer/fp-removal12/test.desc create mode 100644 regression/goto-analyzer/fp-removal13/main.c create mode 100644 regression/goto-analyzer/fp-removal13/test.desc create mode 100644 regression/goto-analyzer/fp-removal14/main.c create mode 100644 regression/goto-analyzer/fp-removal14/test.desc create mode 100644 regression/goto-analyzer/fp-removal15/main.c create mode 100644 regression/goto-analyzer/fp-removal15/test.desc create mode 100644 regression/goto-analyzer/fp-removal16/main.c create mode 100644 regression/goto-analyzer/fp-removal16/test.desc create mode 100644 regression/goto-analyzer/fp-removal17/main.c create mode 100644 regression/goto-analyzer/fp-removal17/test.desc create mode 100644 regression/goto-analyzer/fp-removal19/main.c create mode 100644 regression/goto-analyzer/fp-removal19/test.desc create mode 100644 regression/goto-analyzer/fp-removal2/main.c create mode 100644 regression/goto-analyzer/fp-removal2/test.desc create mode 100644 regression/goto-analyzer/fp-removal20/main.c create mode 100644 regression/goto-analyzer/fp-removal20/test.desc create mode 100644 regression/goto-analyzer/fp-removal21/main.c create mode 100644 regression/goto-analyzer/fp-removal21/test.desc create mode 100644 regression/goto-analyzer/fp-removal22/main.c create mode 100644 regression/goto-analyzer/fp-removal22/test.desc create mode 100644 regression/goto-analyzer/fp-removal23/main.c create mode 100644 regression/goto-analyzer/fp-removal23/test.desc create mode 100644 regression/goto-analyzer/fp-removal24/main.c create mode 100644 regression/goto-analyzer/fp-removal24/test.desc create mode 100644 regression/goto-analyzer/fp-removal25/main.c create mode 100644 regression/goto-analyzer/fp-removal25/test.desc create mode 100644 regression/goto-analyzer/fp-removal26/main.c create mode 100644 regression/goto-analyzer/fp-removal26/test.desc create mode 100644 regression/goto-analyzer/fp-removal27/main.c create mode 100644 regression/goto-analyzer/fp-removal27/test.desc create mode 100644 regression/goto-analyzer/fp-removal28/main.c create mode 100644 regression/goto-analyzer/fp-removal28/test.desc create mode 100644 regression/goto-analyzer/fp-removal29/main.c create mode 100644 regression/goto-analyzer/fp-removal29/test.desc create mode 100644 regression/goto-analyzer/fp-removal3/main.c create mode 100644 regression/goto-analyzer/fp-removal3/test.desc create mode 100644 regression/goto-analyzer/fp-removal30/main.c create mode 100644 regression/goto-analyzer/fp-removal30/test.desc create mode 100644 regression/goto-analyzer/fp-removal31/main.c create mode 100644 regression/goto-analyzer/fp-removal31/test.desc create mode 100644 regression/goto-analyzer/fp-removal32/main.c create mode 100644 regression/goto-analyzer/fp-removal32/test.desc create mode 100644 regression/goto-analyzer/fp-removal33/main.c create mode 100644 regression/goto-analyzer/fp-removal33/test.desc create mode 100644 regression/goto-analyzer/fp-removal34/main.c create mode 100644 regression/goto-analyzer/fp-removal34/test.desc create mode 100644 regression/goto-analyzer/fp-removal35/main.c create mode 100644 regression/goto-analyzer/fp-removal35/test.desc create mode 100644 regression/goto-analyzer/fp-removal36/main.c create mode 100644 regression/goto-analyzer/fp-removal36/test.desc create mode 100644 regression/goto-analyzer/fp-removal37/main.c create mode 100644 regression/goto-analyzer/fp-removal37/test.desc create mode 100644 regression/goto-analyzer/fp-removal38/main.c create mode 100644 regression/goto-analyzer/fp-removal38/test.desc create mode 100644 regression/goto-analyzer/fp-removal39/main.c create mode 100644 regression/goto-analyzer/fp-removal39/test.desc create mode 100644 regression/goto-analyzer/fp-removal4/main.c create mode 100644 regression/goto-analyzer/fp-removal4/test.desc create mode 100644 regression/goto-analyzer/fp-removal40/main.c create mode 100644 regression/goto-analyzer/fp-removal40/test.desc create mode 100644 regression/goto-analyzer/fp-removal41/main.c create mode 100644 regression/goto-analyzer/fp-removal41/test.desc create mode 100644 regression/goto-analyzer/fp-removal5/main.c create mode 100644 regression/goto-analyzer/fp-removal5/test.desc create mode 100644 regression/goto-analyzer/fp-removal6/main.c create mode 100644 regression/goto-analyzer/fp-removal6/test.desc create mode 100644 regression/goto-analyzer/fp-removal7/main.c create mode 100644 regression/goto-analyzer/fp-removal7/test.desc create mode 100644 regression/goto-analyzer/fp-removal8/main.c create mode 100644 regression/goto-analyzer/fp-removal8/test.desc diff --git a/regression/goto-analyzer/fp-removal1/main.c b/regression/goto-analyzer/fp-removal1/main.c new file mode 100644 index 00000000000..f9b5908bce2 --- /dev/null +++ b/regression/goto-analyzer/fp-removal1/main.c @@ -0,0 +1,27 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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 func() +{ + const void_fp fp = f2; + fp(); +} + +void main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal1/test.desc b/regression/goto-analyzer/fp-removal1/test.desc new file mode 100644 index 00000000000..c3065239e49 --- /dev/null +++ b/regression/goto-analyzer/fp-removal1/test.desc @@ -0,0 +1,8 @@ +CORE +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*f2(); +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal10/main.c b/regression/goto-analyzer/fp-removal10/main.c new file mode 100644 index 00000000000..56729ff428a --- /dev/null +++ b/regression/goto-analyzer/fp-removal10/main.c @@ -0,0 +1,31 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 9); } + +typedef void(*void_fp)(void); + +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(void_fp fp, int i){ + fp_tbl[2] = fp; + const void_fp fp2 = fp_tbl[2]; + fp2(); +} + +void main(){ + for(int i=0;i<3;i++){ + func(fp_all[i+3], i); + } +} diff --git a/regression/goto-analyzer/fp-removal10/test.desc b/regression/goto-analyzer/fp-removal10/test.desc new file mode 100644 index 00000000000..7f4fb53760e --- /dev/null +++ b/regression/goto-analyzer/fp-removal10/test.desc @@ -0,0 +1,17 @@ +CORE +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*IF fp2 == f1 THEN GOTO 1$ +^\s*IF fp2 == f2 THEN GOTO 2$ +^\s*IF fp2 == f3 THEN GOTO 3$ +^\s*IF fp2 == f4 THEN GOTO 4$ +^\s*IF fp2 == f5 THEN GOTO 5$ +^\s*IF fp2 == f6 THEN GOTO 6$ +^\s*IF fp2 == f7 THEN GOTO 7$ +^\s*IF fp2 == f8 THEN GOTO 8$ +^\s*IF fp2 == f9 THEN GOTO 9$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal11/main.c b/regression/goto-analyzer/fp-removal11/main.c new file mode 100644 index 00000000000..19988eaf32a --- /dev/null +++ b/regression/goto-analyzer/fp-removal11/main.c @@ -0,0 +1,31 @@ +#include +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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 func(){ + void_fp * const fp_tbl= malloc(sizeof(void_fp) * 3); + fp_tbl[0]=f2; + fp_tbl[1]=f3; + fp_tbl[2]=f4; + const void_fp fp = fp_tbl[1]; + fp(); +} + +void main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal11/test.desc b/regression/goto-analyzer/fp-removal11/test.desc new file mode 100644 index 00000000000..3c735d48a55 --- /dev/null +++ b/regression/goto-analyzer/fp-removal11/test.desc @@ -0,0 +1,17 @@ +CORE +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*IF fp == f1 THEN GOTO 1$ +^\s*IF fp == f2 THEN GOTO 2$ +^\s*IF fp == f3 THEN GOTO 3$ +^\s*IF fp == f4 THEN GOTO 4$ +^\s*IF fp == f5 THEN GOTO 5$ +^\s*IF fp == f6 THEN GOTO 6$ +^\s*IF fp == f7 THEN GOTO 7$ +^\s*IF fp == f8 THEN GOTO 8$ +^\s*IF fp == f9 THEN GOTO 9$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal12/main.c b/regression/goto-analyzer/fp-removal12/main.c new file mode 100644 index 00000000000..be398e7f255 --- /dev/null +++ b/regression/goto-analyzer/fp-removal12/main.c @@ -0,0 +1,38 @@ +#include +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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}; + +typedef struct fp_container +{ + const void_fp fp_tbl[3]; +} fp_container; + + + +void func(){ + fp_container container = { .fp_tbl = {f2 ,f3, f4} }; + fp_container container2 = { .fp_tbl = {f5 ,f6, f7} }; + // Illegal: + // container = container2; + const void_fp fp = container.fp_tbl[1]; + fp(); +} + +void main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal12/test.desc b/regression/goto-analyzer/fp-removal12/test.desc new file mode 100644 index 00000000000..63ff819792f --- /dev/null +++ b/regression/goto-analyzer/fp-removal12/test.desc @@ -0,0 +1,15 @@ +KNOWNBUG +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*f3();$ +^SIGNAL=0$ +-- +^warning: ignoring +-- +This test is marked as a KNOWNBUG as it is possible for the function +pointer to be optimized away. Currently goto-analyzer falls back to +assuming it could be any type compatible function. + +Issue: https://github.com/diffblue/cbmc/issues/476 diff --git a/regression/goto-analyzer/fp-removal13/main.c b/regression/goto-analyzer/fp-removal13/main.c new file mode 100644 index 00000000000..a64ca581ae5 --- /dev/null +++ b/regression/goto-analyzer/fp-removal13/main.c @@ -0,0 +1,41 @@ +#include +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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}; + +typedef struct fp_container +{ + void_fp fp_tbl[3]; +} fp_container; + + + +void func(){ + const fp_container container = { .fp_tbl = {f2 ,f3, f4} }; + fp_container container2 = { .fp_tbl = {f5 ,f6, f7} }; + const void_fp alternatate_fp_tbl[] = {f5 ,f6, f7}; + // Illegal: + // container = container2; + // container.fp_tbl = alternatate_fp_tbl; + // container.fp_tbl[1] = f4; + const void_fp fp = container.fp_tbl[1]; + fp(); +} + +void main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal13/test.desc b/regression/goto-analyzer/fp-removal13/test.desc new file mode 100644 index 00000000000..649ba6fbedd --- /dev/null +++ b/regression/goto-analyzer/fp-removal13/test.desc @@ -0,0 +1,15 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*f3();$ +^SIGNAL=0$ +-- +^warning: ignoring +-- +This test is marked as a KNOWNBUG as it is possible for the function +pointer to be optimized away. Currently goto-analyzer falls back to +assuming it could be any type compatible function. + +Issue: https://github.com/diffblue/cbmc/issues/476 diff --git a/regression/goto-analyzer/fp-removal14/main.c b/regression/goto-analyzer/fp-removal14/main.c new file mode 100644 index 00000000000..b5599183e11 --- /dev/null +++ b/regression/goto-analyzer/fp-removal14/main.c @@ -0,0 +1,32 @@ +#include +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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 func(){ + const void_fp fp = f3; + const void_fp fp2 = f4; + const void_fp* const p2fp = &fp; + // Illegal: + //p2fp = &fp2; + //fp = f5; + (*p2fp)(); +} + +void main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal14/test.desc b/regression/goto-analyzer/fp-removal14/test.desc new file mode 100644 index 00000000000..63ff819792f --- /dev/null +++ b/regression/goto-analyzer/fp-removal14/test.desc @@ -0,0 +1,15 @@ +KNOWNBUG +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*f3();$ +^SIGNAL=0$ +-- +^warning: ignoring +-- +This test is marked as a KNOWNBUG as it is possible for the function +pointer to be optimized away. Currently goto-analyzer falls back to +assuming it could be any type compatible function. + +Issue: https://github.com/diffblue/cbmc/issues/476 diff --git a/regression/goto-analyzer/fp-removal15/main.c b/regression/goto-analyzer/fp-removal15/main.c new file mode 100644 index 00000000000..4b81bffdb30 --- /dev/null +++ b/regression/goto-analyzer/fp-removal15/main.c @@ -0,0 +1,28 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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 func() +{ + void_fp fp = f2; + fp = f3; + fp(); +} + +void main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal15/test.desc b/regression/goto-analyzer/fp-removal15/test.desc new file mode 100644 index 00000000000..3c735d48a55 --- /dev/null +++ b/regression/goto-analyzer/fp-removal15/test.desc @@ -0,0 +1,17 @@ +CORE +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*IF fp == f1 THEN GOTO 1$ +^\s*IF fp == f2 THEN GOTO 2$ +^\s*IF fp == f3 THEN GOTO 3$ +^\s*IF fp == f4 THEN GOTO 4$ +^\s*IF fp == f5 THEN GOTO 5$ +^\s*IF fp == f6 THEN GOTO 6$ +^\s*IF fp == f7 THEN GOTO 7$ +^\s*IF fp == f8 THEN GOTO 8$ +^\s*IF fp == f9 THEN GOTO 9$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal16/main.c b/regression/goto-analyzer/fp-removal16/main.c new file mode 100644 index 00000000000..f1d35373e15 --- /dev/null +++ b/regression/goto-analyzer/fp-removal16/main.c @@ -0,0 +1,31 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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 func() +{ + const void_fp fp = f2; + const void_fp fp3 = f4; + void_fp fp2 = fp; + fp2 = fp3; + fp2(); +} + +void main() +{ + func(); +} diff --git a/regression/goto-analyzer/fp-removal16/test.desc b/regression/goto-analyzer/fp-removal16/test.desc new file mode 100644 index 00000000000..9ea2dfbbc29 --- /dev/null +++ b/regression/goto-analyzer/fp-removal16/test.desc @@ -0,0 +1,16 @@ +CORE +main.c +--show-goto-functions +^Removing function pointers and virtual functions$ +^\s*IF fp2 == f1 THEN GOTO 1$ +^\s*IF fp2 == f2 THEN GOTO 2$ +^\s*IF fp2 == f3 THEN GOTO 3$ +^\s*IF fp2 == f4 THEN GOTO 4$ +^\s*IF fp2 == f5 THEN GOTO 5$ +^\s*IF fp2 == f6 THEN GOTO 6$ +^\s*IF fp2 == f7 THEN GOTO 7$ +^\s*IF fp2 == f8 THEN GOTO 8$ +^\s*IF fp2 == f9 THEN GOTO 9$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal17/main.c b/regression/goto-analyzer/fp-removal17/main.c new file mode 100644 index 00000000000..16df50eeb11 --- /dev/null +++ b/regression/goto-analyzer/fp-removal17/main.c @@ -0,0 +1,29 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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 func() +{ + // There isn't an obvious reason to write this code, but perhaps some + // code can get transformed into this so we should still handle it. + (*(&f2))(); +} + +void main() +{ + func(); +} diff --git a/regression/goto-analyzer/fp-removal17/test.desc b/regression/goto-analyzer/fp-removal17/test.desc new file mode 100644 index 00000000000..c3065239e49 --- /dev/null +++ b/regression/goto-analyzer/fp-removal17/test.desc @@ -0,0 +1,8 @@ +CORE +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*f2(); +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal19/main.c b/regression/goto-analyzer/fp-removal19/main.c new file mode 100644 index 00000000000..45865b9599e --- /dev/null +++ b/regression/goto-analyzer/fp-removal19/main.c @@ -0,0 +1,35 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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(); +} + +void main(){ + for(int i=0;i<3;i++){ + func(i); + } +} diff --git a/regression/goto-analyzer/fp-removal19/test.desc b/regression/goto-analyzer/fp-removal19/test.desc new file mode 100644 index 00000000000..15840e69fe3 --- /dev/null +++ b/regression/goto-analyzer/fp-removal19/test.desc @@ -0,0 +1,11 @@ +CORE +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*IF fp == f2 THEN GOTO 1$ +^\s*IF fp == f3 THEN GOTO 2$ +^\s*IF fp == f4 THEN GOTO 3$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal2/main.c b/regression/goto-analyzer/fp-removal2/main.c new file mode 100644 index 00000000000..85f6fc5b79e --- /dev/null +++ b/regression/goto-analyzer/fp-removal2/main.c @@ -0,0 +1,29 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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 func() +{ + const void_fp fp = f2; + const void_fp fp2 = fp; + fp2(); +} + +void main() +{ + func(); +} diff --git a/regression/goto-analyzer/fp-removal2/test.desc b/regression/goto-analyzer/fp-removal2/test.desc new file mode 100644 index 00000000000..9ba26c84989 --- /dev/null +++ b/regression/goto-analyzer/fp-removal2/test.desc @@ -0,0 +1,8 @@ +CORE +main.c +--show-goto-functions +^Removing function pointers and virtual functions$ +^\s*f2();$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal20/main.c b/regression/goto-analyzer/fp-removal20/main.c new file mode 100644 index 00000000000..0abcd656db1 --- /dev/null +++ b/regression/goto-analyzer/fp-removal20/main.c @@ -0,0 +1,73 @@ +#include + +int f1 (void) +{ + printf("%i", 1); + return 1; +} +int f2 (void) +{ + printf("%i", 2); + return 2; +} +int f3 (void) +{ + printf("%i", 3); + return 3; +} +int f4 (void) +{ + printf("%i", 4); + return 4; +} +int f5 (void) +{ + printf("%i", 5); + return 5; +} +int f6 (void) +{ + printf("%i", 6); + return 6; +} +int f7 (void) +{ + printf("%i", 7); + return 7; +} +int f8 (void) +{ + printf("%i", 8); + return 8; +} +int f9 (void) +{ + printf("%i", 9); + return 9; +} + +typedef void(*void_fp)(void); +typedef int(*int_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 int_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; +} diff --git a/regression/goto-analyzer/fp-removal20/test.desc b/regression/goto-analyzer/fp-removal20/test.desc new file mode 100644 index 00000000000..f1dc8590822 --- /dev/null +++ b/regression/goto-analyzer/fp-removal20/test.desc @@ -0,0 +1,11 @@ +KNOWNBUG +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*IF fp == f2 THEN GOTO 1$ +^\s*IF fp == f3 THEN GOTO 2$ +^\s*IF fp == f4 THEN GOTO 3$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal21/main.c b/regression/goto-analyzer/fp-removal21/main.c new file mode 100644 index 00000000000..1e9deb388c1 --- /dev/null +++ b/regression/goto-analyzer/fp-removal21/main.c @@ -0,0 +1,46 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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; +} diff --git a/regression/goto-analyzer/fp-removal21/test.desc b/regression/goto-analyzer/fp-removal21/test.desc new file mode 100644 index 00000000000..4f3168057fa --- /dev/null +++ b/regression/goto-analyzer/fp-removal21/test.desc @@ -0,0 +1,11 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*IF fp == f2 THEN GOTO 1$ +^\s*IF fp == f3 THEN GOTO 2$ +^\s*IF fp == f4 THEN GOTO 3$ +^SIGNAL=0$ +-- +^warning: ignoring \ No newline at end of file diff --git a/regression/goto-analyzer/fp-removal22/main.c b/regression/goto-analyzer/fp-removal22/main.c new file mode 100644 index 00000000000..7bbfed5fd8b --- /dev/null +++ b/regression/goto-analyzer/fp-removal22/main.c @@ -0,0 +1,28 @@ +void f1 (void) { int tk = 1; } +void f2 (void) { int tk = 2; } +void f3 (void) { int tk = 3; } +void f4 (void) { int tk = 4; } +void f5 (void) { int tk = 5; } +void f6 (void) { int tk = 6; } +void f7 (void) { int tk = 7; } +void f8 (void) { int tk = 8; } +void f9 (void) { int tk = 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(); +} + +void main(){ + for(int i=0;i<3;i++){ + func(i); + } +} diff --git a/regression/goto-analyzer/fp-removal22/test.desc b/regression/goto-analyzer/fp-removal22/test.desc new file mode 100644 index 00000000000..15840e69fe3 --- /dev/null +++ b/regression/goto-analyzer/fp-removal22/test.desc @@ -0,0 +1,11 @@ +CORE +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*IF fp == f2 THEN GOTO 1$ +^\s*IF fp == f3 THEN GOTO 2$ +^\s*IF fp == f4 THEN GOTO 3$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal23/main.c b/regression/goto-analyzer/fp-removal23/main.c new file mode 100644 index 00000000000..09937213470 --- /dev/null +++ b/regression/goto-analyzer/fp-removal23/main.c @@ -0,0 +1,35 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 9); } + +typedef void(*void_fp)(void); + +struct action +{ + void_fp fun; +}; + +const struct action rec = { .fun = f2 }; + +// 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 = rec.fun; + fp(); +} + +void main(){ + for(int i=0;i<3;i++){ + func(i); + } +} diff --git a/regression/goto-analyzer/fp-removal23/test.desc b/regression/goto-analyzer/fp-removal23/test.desc new file mode 100644 index 00000000000..c78b9efabd8 --- /dev/null +++ b/regression/goto-analyzer/fp-removal23/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*f2(); +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal24/main.c b/regression/goto-analyzer/fp-removal24/main.c new file mode 100644 index 00000000000..6cf0b7ee3ce --- /dev/null +++ b/regression/goto-analyzer/fp-removal24/main.c @@ -0,0 +1,43 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 9); } + +typedef void(*void_fp)(void); + +struct action +{ + void_fp fun; +}; + +const struct action rec = { .fun = f2 }; + +const struct action * const action_list[4] = +{ + &rec, + &rec, + &rec, + &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(); +} + +void main(){ + for(int i=0;i<4;i++){ + func(i); + } +} diff --git a/regression/goto-analyzer/fp-removal24/test.desc b/regression/goto-analyzer/fp-removal24/test.desc new file mode 100644 index 00000000000..c78b9efabd8 --- /dev/null +++ b/regression/goto-analyzer/fp-removal24/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*f2(); +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal25/main.c b/regression/goto-analyzer/fp-removal25/main.c new file mode 100644 index 00000000000..51f8de1de9e --- /dev/null +++ b/regression/goto-analyzer/fp-removal25/main.c @@ -0,0 +1,45 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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(); +} + +void main(){ + for(int i=0;i<3;i++){ + func(i); + } +} diff --git a/regression/goto-analyzer/fp-removal25/test.desc b/regression/goto-analyzer/fp-removal25/test.desc new file mode 100644 index 00000000000..05b7ce7e581 --- /dev/null +++ b/regression/goto-analyzer/fp-removal25/test.desc @@ -0,0 +1,11 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*IF fp == f2 THEN GOTO 1$ +^\s*IF fp == f3 THEN GOTO 2$ +^\s*IF fp == f4 THEN GOTO 3$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal26/main.c b/regression/goto-analyzer/fp-removal26/main.c new file mode 100644 index 00000000000..66b03305547 --- /dev/null +++ b/regression/goto-analyzer/fp-removal26/main.c @@ -0,0 +1,41 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 9); } + +typedef void(*void_fp)(void); + +struct state +{ + int x; // Mutable! + const void_fp go; +}; +struct state thing = {0, &f2}; +struct state other_thing = {0, &f4}; +struct state * const pts = &thing; + +// 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){ + // Illegal + //pts=&other_thing; + // thing.go=&f6; + const void_fp fp = pts->go; + + fp(); +} + +void main(){ + for(int i=0;i<3;i++){ + func(i); + } +} diff --git a/regression/goto-analyzer/fp-removal26/test.desc b/regression/goto-analyzer/fp-removal26/test.desc new file mode 100644 index 00000000000..656246683a5 --- /dev/null +++ b/regression/goto-analyzer/fp-removal26/test.desc @@ -0,0 +1,11 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*f2();$ +^SIGNAL=0$ +-- +^warning: ignoring +-- +Mutable struct but const pointer inside it, not yet supported diff --git a/regression/goto-analyzer/fp-removal27/main.c b/regression/goto-analyzer/fp-removal27/main.c new file mode 100644 index 00000000000..1ed1a4c6511 --- /dev/null +++ b/regression/goto-analyzer/fp-removal27/main.c @@ -0,0 +1,30 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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 func() +{ + void_fp fp = f2; + fp = f3; + const void_fp fp2 = fp; + fp2(); +} + +void main() +{ + func(); +} diff --git a/regression/goto-analyzer/fp-removal27/test.desc b/regression/goto-analyzer/fp-removal27/test.desc new file mode 100644 index 00000000000..9ea2dfbbc29 --- /dev/null +++ b/regression/goto-analyzer/fp-removal27/test.desc @@ -0,0 +1,16 @@ +CORE +main.c +--show-goto-functions +^Removing function pointers and virtual functions$ +^\s*IF fp2 == f1 THEN GOTO 1$ +^\s*IF fp2 == f2 THEN GOTO 2$ +^\s*IF fp2 == f3 THEN GOTO 3$ +^\s*IF fp2 == f4 THEN GOTO 4$ +^\s*IF fp2 == f5 THEN GOTO 5$ +^\s*IF fp2 == f6 THEN GOTO 6$ +^\s*IF fp2 == f7 THEN GOTO 7$ +^\s*IF fp2 == f8 THEN GOTO 8$ +^\s*IF fp2 == f9 THEN GOTO 9$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal28/main.c b/regression/goto-analyzer/fp-removal28/main.c new file mode 100644 index 00000000000..cba5ae9bfc7 --- /dev/null +++ b/regression/goto-analyzer/fp-removal28/main.c @@ -0,0 +1,38 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 9); } + +typedef void(*void_fp)(void); + +struct state +{ + int x; // Mutable! + const void_fp go; +}; +struct state thing = {0, &f2}; + +struct state other_thing = {0, &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){ + thing = other_thing; + const void_fp fp = thing.go; + fp(); +} + +void main(){ + for(int i=0;i<3;i++){ + func(i); + } +} diff --git a/regression/goto-analyzer/fp-removal28/test.desc b/regression/goto-analyzer/fp-removal28/test.desc new file mode 100644 index 00000000000..656246683a5 --- /dev/null +++ b/regression/goto-analyzer/fp-removal28/test.desc @@ -0,0 +1,11 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*f2();$ +^SIGNAL=0$ +-- +^warning: ignoring +-- +Mutable struct but const pointer inside it, not yet supported diff --git a/regression/goto-analyzer/fp-removal29/main.c b/regression/goto-analyzer/fp-removal29/main.c new file mode 100644 index 00000000000..87e79cdb5d9 --- /dev/null +++ b/regression/goto-analyzer/fp-removal29/main.c @@ -0,0 +1,37 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 9); } + +typedef void(*void_fp)(void); + +struct action +{ + void_fp fun; +}; + +struct action rec = { .fun = f2 }; + +// 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){ + // Can mutate + rec.fun=f4; + const void_fp fp = rec.fun; + fp(); +} + +void main(){ + for(int i=0;i<3;i++){ + func(i); + } +} diff --git a/regression/goto-analyzer/fp-removal29/test.desc b/regression/goto-analyzer/fp-removal29/test.desc new file mode 100644 index 00000000000..deda28d213f --- /dev/null +++ b/regression/goto-analyzer/fp-removal29/test.desc @@ -0,0 +1,17 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*IF fp == f1 THEN GOTO 1$ +^\s*IF fp == f2 THEN GOTO 2$ +^\s*IF fp == f3 THEN GOTO 3$ +^\s*IF fp == f4 THEN GOTO 4$ +^\s*IF fp == f5 THEN GOTO 5$ +^\s*IF fp == f6 THEN GOTO 6$ +^\s*IF fp == f7 THEN GOTO 7$ +^\s*IF fp == f8 THEN GOTO 8$ +^\s*IF fp == f9 THEN GOTO 9$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal3/main.c b/regression/goto-analyzer/fp-removal3/main.c new file mode 100644 index 00000000000..4d057be3a08 --- /dev/null +++ b/regression/goto-analyzer/fp-removal3/main.c @@ -0,0 +1,29 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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() +{ + const void_fp fp = fp_tbl[1]; + fp(); +} + +void main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal3/test.desc b/regression/goto-analyzer/fp-removal3/test.desc new file mode 100644 index 00000000000..a36fb208c69 --- /dev/null +++ b/regression/goto-analyzer/fp-removal3/test.desc @@ -0,0 +1,8 @@ +CORE +main.c +--show-goto-functions +^Removing function pointers and virtual functions$ +^\s*f3();$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal30/main.c b/regression/goto-analyzer/fp-removal30/main.c new file mode 100644 index 00000000000..8fbd4796975 --- /dev/null +++ b/regression/goto-analyzer/fp-removal30/main.c @@ -0,0 +1,34 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 9); } + +typedef void(*void_fp)(void); + +struct action +{ + void_fp fun; +}; + +const struct action rec = { .fun = f2 }; + +// 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){ + rec.fun(); +} + +void main(){ + for(int i=0;i<3;i++){ + func(i); + } +} diff --git a/regression/goto-analyzer/fp-removal30/test.desc b/regression/goto-analyzer/fp-removal30/test.desc new file mode 100644 index 00000000000..c78b9efabd8 --- /dev/null +++ b/regression/goto-analyzer/fp-removal30/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*f2(); +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal31/main.c b/regression/goto-analyzer/fp-removal31/main.c new file mode 100644 index 00000000000..e27d618cea9 --- /dev/null +++ b/regression/goto-analyzer/fp-removal31/main.c @@ -0,0 +1,27 @@ +#include +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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 func(){ + const void_fp fp = f3; + (*(&fp))(); +} + +void main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal31/test.desc b/regression/goto-analyzer/fp-removal31/test.desc new file mode 100644 index 00000000000..649ba6fbedd --- /dev/null +++ b/regression/goto-analyzer/fp-removal31/test.desc @@ -0,0 +1,15 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*f3();$ +^SIGNAL=0$ +-- +^warning: ignoring +-- +This test is marked as a KNOWNBUG as it is possible for the function +pointer to be optimized away. Currently goto-analyzer falls back to +assuming it could be any type compatible function. + +Issue: https://github.com/diffblue/cbmc/issues/476 diff --git a/regression/goto-analyzer/fp-removal32/main.c b/regression/goto-analyzer/fp-removal32/main.c new file mode 100644 index 00000000000..6076e1f12be --- /dev/null +++ b/regression/goto-analyzer/fp-removal32/main.c @@ -0,0 +1,36 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 9); } + +typedef void(*void_fp)(void); + +struct state +{ + int x; // Mutable! + const void_fp go; +}; +struct state thing = {0, &f2}; +struct state const * const pts = &thing; + + +// 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){ + pts->go(); +} + +void main(){ + for(int i=0;i<3;i++){ + func(i); + } +} diff --git a/regression/goto-analyzer/fp-removal32/test.desc b/regression/goto-analyzer/fp-removal32/test.desc new file mode 100644 index 00000000000..0c27e7670ac --- /dev/null +++ b/regression/goto-analyzer/fp-removal32/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*f2();$ +^SIGNAL=0$ +-- +^warning: ignoring \ No newline at end of file diff --git a/regression/goto-analyzer/fp-removal33/main.c b/regression/goto-analyzer/fp-removal33/main.c new file mode 100644 index 00000000000..bd650bd01ae --- /dev/null +++ b/regression/goto-analyzer/fp-removal33/main.c @@ -0,0 +1,28 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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() +{ + fp_tbl[1](); +} + +void main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal33/test.desc b/regression/goto-analyzer/fp-removal33/test.desc new file mode 100644 index 00000000000..a36fb208c69 --- /dev/null +++ b/regression/goto-analyzer/fp-removal33/test.desc @@ -0,0 +1,8 @@ +CORE +main.c +--show-goto-functions +^Removing function pointers and virtual functions$ +^\s*f3();$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal34/main.c b/regression/goto-analyzer/fp-removal34/main.c new file mode 100644 index 00000000000..8fc4036e201 --- /dev/null +++ b/regression/goto-analyzer/fp-removal34/main.c @@ -0,0 +1,27 @@ +void f1 (void) { int tk = 1; } +void f2 (void) { int tk = 2; } +void f3 (void) { int tk = 3; } +void f4 (void) { int tk = 4; } +void f5 (void) { int tk = 5; } +void f6 (void) { int tk = 6; } +void f7 (void) { int tk = 7; } +void f8 (void) { int tk = 8; } +void f9 (void) { int tk = 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](); +} + +void main(){ + for(int i=0;i<3;i++){ + func(i); + } +} diff --git a/regression/goto-analyzer/fp-removal34/test.desc b/regression/goto-analyzer/fp-removal34/test.desc new file mode 100644 index 00000000000..cf845be0316 --- /dev/null +++ b/regression/goto-analyzer/fp-removal34/test.desc @@ -0,0 +1,11 @@ +CORE +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*IF fp_tbl\[(signed long int)i\] == f2 THEN GOTO 1$ +^\s*IF fp_tbl\[(signed long int)i\] == f3 THEN GOTO 2$ +^\s*IF fp_tbl\[(signed long int)i\] == f4 THEN GOTO 3$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal35/main.c b/regression/goto-analyzer/fp-removal35/main.c new file mode 100644 index 00000000000..cbe9e504df2 --- /dev/null +++ b/regression/goto-analyzer/fp-removal35/main.c @@ -0,0 +1,29 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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() +{ + const short short_const_variable=1; + fp_tbl[(signed long int)((signed int)short_const_variable & 0x1)](); +} + +void main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal35/test.desc b/regression/goto-analyzer/fp-removal35/test.desc new file mode 100644 index 00000000000..5b566c321ca --- /dev/null +++ b/regression/goto-analyzer/fp-removal35/test.desc @@ -0,0 +1,11 @@ +KNOWNBUG +main.c +--show-goto-functions +^Removing function pointers and virtual functions$ +^\s*f3();$ +^SIGNAL=0$ +-- +^warning: ignoring +-- +Fails because of the non-trivial index expression can be evaluated +constantly but isn't \ No newline at end of file diff --git a/regression/goto-analyzer/fp-removal36/main.c b/regression/goto-analyzer/fp-removal36/main.c new file mode 100644 index 00000000000..2f828e830ce --- /dev/null +++ b/regression/goto-analyzer/fp-removal36/main.c @@ -0,0 +1,43 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 9); } + +typedef void(*void_fp)(void); + +struct state +{ + int x; // Mutable! + const void_fp go; +}; +struct state thing = {0, &f2}; +struct state other_thing = {0, &f4}; + +// This shouldn't work +struct state * pts = &thing; + +// 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) +{ + // This shouldn't work since + pts = &other_thing; + const void_fp fp = pts->go; + fp(); +} + + +void main(){ + for(int i=0;i<3;i++){ + func(i); + } +} diff --git a/regression/goto-analyzer/fp-removal36/test.desc b/regression/goto-analyzer/fp-removal36/test.desc new file mode 100644 index 00000000000..b31b9aedfa1 --- /dev/null +++ b/regression/goto-analyzer/fp-removal36/test.desc @@ -0,0 +1,20 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*IF fp == f1 THEN GOTO 1$ +^\s*IF fp == f2 THEN GOTO 2$ +^\s*IF fp == f3 THEN GOTO 3$ +^\s*IF fp == f4 THEN GOTO 4$ +^\s*IF fp == f5 THEN GOTO 5$ +^\s*IF fp == f6 THEN GOTO 6$ +^\s*IF fp == f7 THEN GOTO 7$ +^\s*IF fp == f8 THEN GOTO 8$ +^\s*IF fp == f9 THEN GOTO 9$ +^SIGNAL=0$ +-- +^warning: ignoring +-- +This shouldn't work because the pointer can be assigned to a different +struct after initial assignment. diff --git a/regression/goto-analyzer/fp-removal37/main.c b/regression/goto-analyzer/fp-removal37/main.c new file mode 100644 index 00000000000..7e50789f2ad --- /dev/null +++ b/regression/goto-analyzer/fp-removal37/main.c @@ -0,0 +1,46 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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[1].fp; + + // Illegal + // stable_table[1] = another_table; + fp(); +} + +int main(){ + for(int i=0;i<3;i++){ + func(i); + } + return 0; +} diff --git a/regression/goto-analyzer/fp-removal37/test.desc b/regression/goto-analyzer/fp-removal37/test.desc new file mode 100644 index 00000000000..bfc412d2705 --- /dev/null +++ b/regression/goto-analyzer/fp-removal37/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*f3();$ +^SIGNAL=0$ +-- +^warning: ignoring \ No newline at end of file diff --git a/regression/goto-analyzer/fp-removal38/main.c b/regression/goto-analyzer/fp-removal38/main.c new file mode 100644 index 00000000000..c90c9bb9585 --- /dev/null +++ b/regression/goto-analyzer/fp-removal38/main.c @@ -0,0 +1,33 @@ +#include +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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 func(){ + const void_fp fp = f3; + const void_fp fp2 = f4; + const void_fp* const p2fp = &fp; + // Illegal: + //p2fp = &fp2; + //fp = f5; + const void_fp final_fp=*p2fp; + final_fp(); +} + +void main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal38/test.desc b/regression/goto-analyzer/fp-removal38/test.desc new file mode 100644 index 00000000000..649ba6fbedd --- /dev/null +++ b/regression/goto-analyzer/fp-removal38/test.desc @@ -0,0 +1,15 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*f3();$ +^SIGNAL=0$ +-- +^warning: ignoring +-- +This test is marked as a KNOWNBUG as it is possible for the function +pointer to be optimized away. Currently goto-analyzer falls back to +assuming it could be any type compatible function. + +Issue: https://github.com/diffblue/cbmc/issues/476 diff --git a/regression/goto-analyzer/fp-removal39/main.c b/regression/goto-analyzer/fp-removal39/main.c new file mode 100644 index 00000000000..1510abceb69 --- /dev/null +++ b/regression/goto-analyzer/fp-removal39/main.c @@ -0,0 +1,37 @@ +#include +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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 func(){ + const void_fp fp = f3; + const void_fp fp2 = f4; + const void_fp* p2fp = &fp; + + + // Illegal: + //fp = f5; + + // legal: + p2fp = &fp2; + const void_fp final_fp=*p2fp; + final_fp(); +} + +void main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal39/test.desc b/regression/goto-analyzer/fp-removal39/test.desc new file mode 100644 index 00000000000..c60094eebd3 --- /dev/null +++ b/regression/goto-analyzer/fp-removal39/test.desc @@ -0,0 +1,23 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*IF final_fp == f1 THEN GOTO 1$ +^\s*IF final_fp == f2 THEN GOTO 2$ +^\s*IF final_fp == f3 THEN GOTO 3$ +^\s*IF final_fp == f4 THEN GOTO 4$ +^\s*IF final_fp == f5 THEN GOTO 5$ +^\s*IF final_fp == f6 THEN GOTO 6$ +^\s*IF final_fp == f7 THEN GOTO 7$ +^\s*IF final_fp == f8 THEN GOTO 8$ +^\s*IF final_fp == f9 THEN GOTO 9$ +^SIGNAL=0$ +-- +^warning: ignoring +-- +This test is marked as a KNOWNBUG as it is possible for the function +pointer to be optimized away. Currently goto-analyzer falls back to +assuming it could be any type compatible function. + +Issue: https://github.com/diffblue/cbmc/issues/476 diff --git a/regression/goto-analyzer/fp-removal4/main.c b/regression/goto-analyzer/fp-removal4/main.c new file mode 100644 index 00000000000..fbbd4f34259 --- /dev/null +++ b/regression/goto-analyzer/fp-removal4/main.c @@ -0,0 +1,30 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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() +{ + const int x = 1; + const void_fp fp = fp_tbl[x]; + fp(); +} + +void main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal4/test.desc b/regression/goto-analyzer/fp-removal4/test.desc new file mode 100644 index 00000000000..a36fb208c69 --- /dev/null +++ b/regression/goto-analyzer/fp-removal4/test.desc @@ -0,0 +1,8 @@ +CORE +main.c +--show-goto-functions +^Removing function pointers and virtual functions$ +^\s*f3();$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal40/main.c b/regression/goto-analyzer/fp-removal40/main.c new file mode 100644 index 00000000000..080f1affcc8 --- /dev/null +++ b/regression/goto-analyzer/fp-removal40/main.c @@ -0,0 +1,25 @@ +void f1 (void) { int tk = 1; } +void f2 (void) { int tk = 2; } +void f3 (void) { int tk = 3; } +void f4 (void) { int tk = 4; } +void f5 (void) { int tk = 5; } +void f6 (void) { int tk = 6; } +void f7 (void) { int tk = 7; } +void f8 (void) { int tk = 8; } +void f9 (void) { int tk = 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 func(const void_fp fp){ + fp(); +} + +void main(){ + for(int i=0;i<3;i++){ + func(fp_all[i]); + } +} diff --git a/regression/goto-analyzer/fp-removal40/test.desc b/regression/goto-analyzer/fp-removal40/test.desc new file mode 100644 index 00000000000..3c735d48a55 --- /dev/null +++ b/regression/goto-analyzer/fp-removal40/test.desc @@ -0,0 +1,17 @@ +CORE +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*IF fp == f1 THEN GOTO 1$ +^\s*IF fp == f2 THEN GOTO 2$ +^\s*IF fp == f3 THEN GOTO 3$ +^\s*IF fp == f4 THEN GOTO 4$ +^\s*IF fp == f5 THEN GOTO 5$ +^\s*IF fp == f6 THEN GOTO 6$ +^\s*IF fp == f7 THEN GOTO 7$ +^\s*IF fp == f8 THEN GOTO 8$ +^\s*IF fp == f9 THEN GOTO 9$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal41/main.c b/regression/goto-analyzer/fp-removal41/main.c new file mode 100644 index 00000000000..fd73934e83c --- /dev/null +++ b/regression/goto-analyzer/fp-removal41/main.c @@ -0,0 +1,29 @@ +void f1 (void) { int tk = 1; } +void f2 (void) { int tk = 2; } +void f3 (void) { int tk = 3; } +void f4 (void) { int tk = 4; } +void f5 (void) { int tk = 5; } +void f6 (void) { int tk = 6; } +void f7 (void) { int tk = 7; } +void f8 (void) { int tk = 8; } +void f9 (void) { int tk = 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 func(int i, int j){ + const void_fp fp_tbl[] = {fp_all[i*2], fp_all[j+1]}; + // Illegal: + //fp_tbl[1] = f4; + const void_fp fp = fp_tbl[1]; + fp(); +} + +void main(){ + for(int i=0;i<3;i++){ + func(i,0); + } +} diff --git a/regression/goto-analyzer/fp-removal41/test.desc b/regression/goto-analyzer/fp-removal41/test.desc new file mode 100644 index 00000000000..3c735d48a55 --- /dev/null +++ b/regression/goto-analyzer/fp-removal41/test.desc @@ -0,0 +1,17 @@ +CORE +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*IF fp == f1 THEN GOTO 1$ +^\s*IF fp == f2 THEN GOTO 2$ +^\s*IF fp == f3 THEN GOTO 3$ +^\s*IF fp == f4 THEN GOTO 4$ +^\s*IF fp == f5 THEN GOTO 5$ +^\s*IF fp == f6 THEN GOTO 6$ +^\s*IF fp == f7 THEN GOTO 7$ +^\s*IF fp == f8 THEN GOTO 8$ +^\s*IF fp == f9 THEN GOTO 9$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal5/main.c b/regression/goto-analyzer/fp-removal5/main.c new file mode 100644 index 00000000000..20cf98fb59a --- /dev/null +++ b/regression/goto-analyzer/fp-removal5/main.c @@ -0,0 +1,28 @@ +void f1 (void) { int tk = 1; } +void f2 (void) { int tk = 2; } +void f3 (void) { int tk = 3; } +void f4 (void) { int tk = 4; } +void f5 (void) { int tk = 5; } +void f6 (void) { int tk = 6; } +void f7 (void) { int tk = 7; } +void f8 (void) { int tk = 8; } +void f9 (void) { int tk = 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(); +} + +void main(){ + for(int i=0;i<3;i++){ + func(i); + } +} diff --git a/regression/goto-analyzer/fp-removal5/test.desc b/regression/goto-analyzer/fp-removal5/test.desc new file mode 100644 index 00000000000..15840e69fe3 --- /dev/null +++ b/regression/goto-analyzer/fp-removal5/test.desc @@ -0,0 +1,11 @@ +CORE +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*IF fp == f2 THEN GOTO 1$ +^\s*IF fp == f3 THEN GOTO 2$ +^\s*IF fp == f4 THEN GOTO 3$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal6/main.c b/regression/goto-analyzer/fp-removal6/main.c new file mode 100644 index 00000000000..68ddffa073e --- /dev/null +++ b/regression/goto-analyzer/fp-removal6/main.c @@ -0,0 +1,27 @@ +void f1 (void) { int tk = 1; } +void f2 (void) { int tk = 2; } +void f3 (void) { int tk = 3; } +void f4 (void) { int tk = 4; } +void f5 (void) { int tk = 5; } +void f6 (void) { int tk = 6; } +void f7 (void) { int tk = 7; } +void f8 (void) { int tk = 8; } +void f9 (void) { int tk = 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 func(int i, int j){ + void_fp fp_tbl[] = {fp_all[i*2], fp_all[j+1]}; + const void_fp fp = fp_tbl[1]; + fp(); +} + +void main(){ + for(int i=0;i<3;i++){ + func(i,0); + } +} diff --git a/regression/goto-analyzer/fp-removal6/test.desc b/regression/goto-analyzer/fp-removal6/test.desc new file mode 100644 index 00000000000..3c735d48a55 --- /dev/null +++ b/regression/goto-analyzer/fp-removal6/test.desc @@ -0,0 +1,17 @@ +CORE +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*IF fp == f1 THEN GOTO 1$ +^\s*IF fp == f2 THEN GOTO 2$ +^\s*IF fp == f3 THEN GOTO 3$ +^\s*IF fp == f4 THEN GOTO 4$ +^\s*IF fp == f5 THEN GOTO 5$ +^\s*IF fp == f6 THEN GOTO 6$ +^\s*IF fp == f7 THEN GOTO 7$ +^\s*IF fp == f8 THEN GOTO 8$ +^\s*IF fp == f9 THEN GOTO 9$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal7/main.c b/regression/goto-analyzer/fp-removal7/main.c new file mode 100644 index 00000000000..8bbd6ee15d6 --- /dev/null +++ b/regression/goto-analyzer/fp-removal7/main.c @@ -0,0 +1,25 @@ +void f1 (void) { int tk = 1; } +void f2 (void) { int tk = 2; } +void f3 (void) { int tk = 3; } +void f4 (void) { int tk = 4; } +void f5 (void) { int tk = 5; } +void f6 (void) { int tk = 6; } +void f7 (void) { int tk = 7; } +void f8 (void) { int tk = 8; } +void f9 (void) { int tk = 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 func(void_fp fp){ + fp(); +} + +void main(){ + for(int i=0;i<3;i++){ + func(fp_all[i]); + } +} diff --git a/regression/goto-analyzer/fp-removal7/test.desc b/regression/goto-analyzer/fp-removal7/test.desc new file mode 100644 index 00000000000..3c735d48a55 --- /dev/null +++ b/regression/goto-analyzer/fp-removal7/test.desc @@ -0,0 +1,17 @@ +CORE +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*IF fp == f1 THEN GOTO 1$ +^\s*IF fp == f2 THEN GOTO 2$ +^\s*IF fp == f3 THEN GOTO 3$ +^\s*IF fp == f4 THEN GOTO 4$ +^\s*IF fp == f5 THEN GOTO 5$ +^\s*IF fp == f6 THEN GOTO 6$ +^\s*IF fp == f7 THEN GOTO 7$ +^\s*IF fp == f8 THEN GOTO 8$ +^\s*IF fp == f9 THEN GOTO 9$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal8/main.c b/regression/goto-analyzer/fp-removal8/main.c new file mode 100644 index 00000000000..26d09257aaf --- /dev/null +++ b/regression/goto-analyzer/fp-removal8/main.c @@ -0,0 +1,33 @@ +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 9); } + +typedef void(*void_fp)(void); + +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(void_fp fp, int i){ + // It is concievable this could be checked and seen the first value + // of the array is unchanged but is kind of a weird edge case. + fp_tbl[2] = fp; + const void_fp fp2 = fp_tbl[1]; + fp2(); +} + +void main(){ + for(int i=0;i<3;i++){ + func(fp_all[i+3], i); + } +} diff --git a/regression/goto-analyzer/fp-removal8/test.desc b/regression/goto-analyzer/fp-removal8/test.desc new file mode 100644 index 00000000000..7f4fb53760e --- /dev/null +++ b/regression/goto-analyzer/fp-removal8/test.desc @@ -0,0 +1,17 @@ +CORE +main.c +--show-goto-functions + +^Removing function pointers and virtual functions$ +^\s*IF fp2 == f1 THEN GOTO 1$ +^\s*IF fp2 == f2 THEN GOTO 2$ +^\s*IF fp2 == f3 THEN GOTO 3$ +^\s*IF fp2 == f4 THEN GOTO 4$ +^\s*IF fp2 == f5 THEN GOTO 5$ +^\s*IF fp2 == f6 THEN GOTO 6$ +^\s*IF fp2 == f7 THEN GOTO 7$ +^\s*IF fp2 == f8 THEN GOTO 8$ +^\s*IF fp2 == f9 THEN GOTO 9$ +^SIGNAL=0$ +-- +^warning: ignoring From 995f5045c28ccc30aeebb2d7205ef415b00ca843 Mon Sep 17 00:00:00 2001 From: thk123 Date: Mon, 30 Jan 2017 14:16:01 +0000 Subject: [PATCH 02/46] Made remove_function_pointers inherit from messaget This will allow for the logging to be done through the debug() channel and hence turned on and off. --- src/cbmc/cbmc_parse_options.cpp | 1 + .../goto_analyzer_parse_options.cpp | 3 ++- src/goto-diff/goto_diff_parse_options.cpp | 1 + .../goto_instrument_parse_options.cpp | 1 + src/goto-programs/remove_function_pointers.cpp | 17 +++++++++++++---- src/goto-programs/remove_function_pointers.h | 3 +++ 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/cbmc/cbmc_parse_options.cpp b/src/cbmc/cbmc_parse_options.cpp index 657e4531429..8bbdb8ce89e 100644 --- a/src/cbmc/cbmc_parse_options.cpp +++ b/src/cbmc/cbmc_parse_options.cpp @@ -877,6 +877,7 @@ bool cbmc_parse_optionst::process_goto_program( // remove function pointers status() << "Removal of function pointers and virtual functions" << eom; remove_function_pointers( + get_message_handler(), symbol_table, goto_functions, cmdline.isset("pointer-check")); diff --git a/src/goto-analyzer/goto_analyzer_parse_options.cpp b/src/goto-analyzer/goto_analyzer_parse_options.cpp index e462740c1cc..10fb9d8d6d9 100644 --- a/src/goto-analyzer/goto_analyzer_parse_options.cpp +++ b/src/goto-analyzer/goto_analyzer_parse_options.cpp @@ -385,7 +385,8 @@ bool goto_analyzer_parse_optionst::process_goto_program( // remove function pointers status() << "Removing function pointers and virtual functions" << eom; - remove_function_pointers(goto_model, cmdline.isset("pointer-check")); + remove_function_pointers( + get_message_handler(), goto_model, cmdline.isset("pointer-check")); // Java virtual functions -> explicit dispatch tables: remove_virtual_functions(goto_model); // remove Java throw and catch diff --git a/src/goto-diff/goto_diff_parse_options.cpp b/src/goto-diff/goto_diff_parse_options.cpp index a405178652f..b86eee9fea1 100644 --- a/src/goto-diff/goto_diff_parse_options.cpp +++ b/src/goto-diff/goto_diff_parse_options.cpp @@ -487,6 +487,7 @@ bool goto_diff_parse_optionst::process_goto_program( // remove function pointers status() << "Function Pointer Removal" << eom; remove_function_pointers( + get_message_handler(), symbol_table, goto_functions, cmdline.isset("pointer-check")); diff --git a/src/goto-instrument/goto_instrument_parse_options.cpp b/src/goto-instrument/goto_instrument_parse_options.cpp index b5486355277..3e923bd5103 100644 --- a/src/goto-instrument/goto_instrument_parse_options.cpp +++ b/src/goto-instrument/goto_instrument_parse_options.cpp @@ -806,6 +806,7 @@ void goto_instrument_parse_optionst::do_indirect_call_and_rtti_removal( status() << "Function Pointer Removal" << eom; remove_function_pointers( + get_message_handler(), symbol_table, goto_functions, cmdline.isset("pointer-check")); diff --git a/src/goto-programs/remove_function_pointers.cpp b/src/goto-programs/remove_function_pointers.cpp index 3893729a1e1..aee2dcae89b 100644 --- a/src/goto-programs/remove_function_pointers.cpp +++ b/src/goto-programs/remove_function_pointers.cpp @@ -14,6 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include #include +#include #include @@ -29,10 +30,11 @@ Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ -class remove_function_pointerst +class remove_function_pointerst:public messaget { public: remove_function_pointerst( + message_handlert &_message_handler, symbol_tablet &_symbol_table, bool _add_safety_assertion, const goto_functionst &goto_functions); @@ -92,9 +94,11 @@ Function: remove_function_pointerst::remove_function_pointerst \*******************************************************************/ remove_function_pointerst::remove_function_pointerst( + message_handlert &_message_handler, symbol_tablet &_symbol_table, bool _add_safety_assertion, const goto_functionst &goto_functions): + messaget(_message_handler), ns(_symbol_table), symbol_table(_symbol_table), add_safety_assertion(_add_safety_assertion) @@ -540,13 +544,14 @@ Function: remove_function_pointers \*******************************************************************/ bool remove_function_pointers( + message_handlert &_message_handler, symbol_tablet &symbol_table, const goto_functionst &goto_functions, goto_programt &goto_program, bool add_safety_assertion) { remove_function_pointerst - rfp(symbol_table, add_safety_assertion, goto_functions); + rfp(_message_handler, symbol_table, add_safety_assertion, goto_functions); return rfp.remove_function_pointers(goto_program); } @@ -564,12 +569,13 @@ Function: remove_function_pointers \*******************************************************************/ void remove_function_pointers( + message_handlert &_message_handler, symbol_tablet &symbol_table, goto_functionst &goto_functions, bool add_safety_assertion) { remove_function_pointerst - rfp(symbol_table, add_safety_assertion, goto_functions); + rfp(_message_handler, symbol_table, add_safety_assertion, goto_functions); rfp(goto_functions); } @@ -587,10 +593,13 @@ Function: remove_function_pointers \*******************************************************************/ void remove_function_pointers( + message_handlert &_message_handler, goto_modelt &goto_model, bool add_safety_assertion) { remove_function_pointers( - goto_model.symbol_table, goto_model.goto_functions, + _message_handler, + goto_model.symbol_table, + goto_model.goto_functions, add_safety_assertion); } diff --git a/src/goto-programs/remove_function_pointers.h b/src/goto-programs/remove_function_pointers.h index 6f1f26984df..125cda131e1 100644 --- a/src/goto-programs/remove_function_pointers.h +++ b/src/goto-programs/remove_function_pointers.h @@ -16,15 +16,18 @@ Date: June 2003 // remove indirect function calls // and replace by case-split void remove_function_pointers( + message_handlert &_message_handler, goto_modelt &goto_model, bool add_safety_assertion); void remove_function_pointers( + message_handlert &_message_handler, symbol_tablet &symbol_table, goto_functionst &goto_functions, bool add_safety_assertion); bool remove_function_pointers( + message_handlert &_message_handler, symbol_tablet &symbol_table, const goto_functionst &goto_functions, goto_programt &goto_program, From 563a3519f24b1f248a01a0e23fb76689d19886e5 Mon Sep 17 00:00:00 2001 From: thk123 Date: Thu, 2 Feb 2017 14:23:27 +0000 Subject: [PATCH 03/46] First implemention of the new approach --- src/goto-programs/Makefile | 4 +- .../remove_const_function_pointers.cpp | 500 ++++++++++++++++++ .../remove_const_function_pointers.h | 62 +++ .../remove_function_pointers.cpp | 57 +- 4 files changed, 598 insertions(+), 25 deletions(-) create mode 100644 src/goto-programs/remove_const_function_pointers.cpp create mode 100644 src/goto-programs/remove_const_function_pointers.h diff --git a/src/goto-programs/Makefile b/src/goto-programs/Makefile index d5cc5ea25eb..bf6abb39ab6 100644 --- a/src/goto-programs/Makefile +++ b/src/goto-programs/Makefile @@ -20,7 +20,9 @@ SRC = goto_convert.cpp goto_convert_function_call.cpp \ slice_global_inits.cpp goto_inline_class.cpp class_identifier.cpp \ show_goto_functions_json.cpp \ show_goto_functions_xml.cpp \ - remove_static_init_loops.cpp remove_instanceof.cpp + remove_static_init_loops.cpp remove_instanceof.cpp \ + remove_const_function_pointers.cpp \ + # Empty last line INCLUDES= -I .. diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp new file mode 100644 index 00000000000..ebf6840ecbc --- /dev/null +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -0,0 +1,500 @@ +/*******************************************************************\ + +Module: Goto Programs + +Author: Thomas Kiley, thomas.kiley@diffblue.com + +\*******************************************************************/ + +#include +#include +#include + +#include "remove_const_function_pointers.h" + +remove_const_function_pointerst::remove_const_function_pointerst( + message_handlert &message_handler, + const exprt &base_expression, + const namespacet &ns, + const symbol_tablet &symbol_table): + messaget(message_handler), + original_expression(base_expression), + ns(ns), + symbol_table(symbol_table) +{} + +bool remove_const_function_pointerst::operator()( + functionst &out_functions) +{ + return try_resolve_function_call(original_expression, out_functions); +} + +exprt remove_const_function_pointerst::resolve_symbol( + const symbol_exprt &symbol_expr) const +{ + const symbolt &symbol= + symbol_table.lookup(symbol_expr.get_identifier()); + return symbol.value; +} + +bool remove_const_function_pointerst::try_resolve_function_call( + const exprt &expr, remove_const_function_pointerst::functionst &out_functions) +{ + const exprt &simplified_expr=simplify_expr(expr, ns); + if(simplified_expr.id()==ID_index) + { + const index_exprt &index_expr=to_index_expr(simplified_expr); + return try_resolve_index_of_function_call(index_expr, out_functions); + } + else if(simplified_expr.id()==ID_member) + { + const member_exprt &member_expr=to_member_expr(simplified_expr); + const exprt &owner_expr=member_expr.compound(); + // Squash the struct + expressionst out_expressions; + bool is_const=false; + bool resolved=try_resolve_expression(owner_expr, out_expressions, is_const); + if(resolved) + { + for(const exprt &expression:out_expressions) + { + if(expression.id()!=ID_struct) + { + return false; + } + else + { + struct_exprt struct_expr=to_struct_expr(expression); + const exprt &component_value= + struct_expr.operands()[member_expr.get_component_number()]; + // TODO: copy into out_functions rather than supply direct like + bool resolved= + try_resolve_function_call(component_value, out_functions); + if(!resolved) + { + return false; + } + } + } + + return true; + + } + else + { + return false; + } + } + else if(simplified_expr.id()==ID_address_of) + { + address_of_exprt address_expr=to_address_of_expr(simplified_expr); + return try_resolve_function_call(address_expr.object(), out_functions); + } + else if(simplified_expr.id()==ID_symbol) + { + if(simplified_expr.type().id()==ID_code) + { + out_functions.insert(simplified_expr); + return true; + } + else + { + const c_qualifierst pointer_qualifers(simplified_expr.type()); + if(!pointer_qualifers.is_constant) + { + debug() << "Can't optimize FP since symbol " + << simplified_expr.get(ID_identifier) << " is not const" << eom; + return false; + } + + const exprt &symbol_value=resolve_symbol(to_symbol_expr(simplified_expr)); + return try_resolve_function_call(symbol_value, out_functions); + } + } + else + { + return false; + } +} + +// Take an index of, squash its array and squash its index +// If we can get a precise number, try_resolve_function_call on its value +// otherwise try_resolve_function_call on each and return the union of them all +bool remove_const_function_pointerst::try_resolve_index_of_function_call( + const index_exprt &index_expr, functionst &out_functions) +{ + // Get the array(s) it belongs to + expressionst potential_array_exprs; + bool is_const=false; + bool resolved_array= + try_resolve_expression(index_expr.array(), potential_array_exprs, is_const); + if(resolved_array) + { + for(const exprt &potential_array_expr : potential_array_exprs) + { + if(potential_array_expr.id()==ID_array) + { + // We require either the type of the values of the array or + // the array itself to be constant. + const typet &array_type=potential_array_expr.type(); + const typet &array_contents_type=array_type.subtype(); + c_qualifierst array_qaulifiers; + array_qaulifiers.read(array_contents_type); + + if(array_qaulifiers.is_constant || is_const) + { + // Get the index if we can + mp_integer value; + if(try_resolve_index_value(index_expr.index(), value)) + { + functionst array_out_functions; + const exprt &func_expr= + potential_array_expr.operands()[integer2size_t(value)]; + bool resolved_value= + try_resolve_function_call(func_expr, array_out_functions); + + if(resolved_value) + { + out_functions.insert( + array_out_functions.begin(), + array_out_functions.end()); + } + } + else + { + // We don't know what index it is, + // but we know the value is from the array + for(const exprt &array_entry : potential_array_expr.operands()) + { + functionst potential_functions; + bool resolved_value= + try_resolve_function_call(array_entry, potential_functions); + + if(resolved_value) + { + for(const exprt &potential_function : potential_functions) + { + if(potential_function.is_zero()) + { + continue; + } + else + { + out_functions.insert( + potential_functions.begin(), + potential_functions.end()); + } + } + } + else + { + return false; + } + } + } + } + else + { + return false; + } + } + else + { + return false; + } + } + + return true; + } + else + { + return false; + } +} + +bool remove_const_function_pointerst::try_resolve_expression( + const exprt &expr, expressionst &out_resolved_expression, bool &out_is_const) +{ + const exprt &simplified_expr=simplify_expr(expr, ns); + if(simplified_expr.id()==ID_index) + { + const index_exprt &index_expr=to_index_expr(simplified_expr); + expressionst out_array_expressions; + bool resolved_array= + try_resolve_index_of(index_expr, out_array_expressions, out_is_const); + if(resolved_array) + { + out_resolved_expression.insert( + out_resolved_expression.end(), + out_array_expressions.begin(), + out_array_expressions.end()); + } + + return resolved_array; + } + else if(simplified_expr.id()==ID_member) + { + // Get the component it belongs to + const member_exprt &member_expr=to_member_expr(simplified_expr); + + expressionst potential_structs; + bool is_struct_const; + try_resolve_expression( + member_expr.compound(), potential_structs, is_struct_const); + + bool all_components_const=true; + for(const exprt &potential_struct : potential_structs) + { + if(potential_struct.id()==ID_struct) + { + struct_exprt struct_expr=to_struct_expr(potential_struct); + const exprt &component_value= + struct_expr.operands()[member_expr.get_component_number()]; + expressionst out_expressions; + bool component_const=false; + bool resolved= + try_resolve_expression( + component_value, out_expressions, component_const); + if(resolved) + { + out_resolved_expression.insert( + out_resolved_expression.end(), + out_expressions.begin(), + out_expressions.end()); + + all_components_const= + all_components_const && component_const; + } + else + { + return false; + } + } + else + { + return false; + } + } + out_is_const=all_components_const||is_struct_const; + return true; + } + else if(simplified_expr.id()==ID_dereference) + { + // We had a pointer, we need to check both the pointer + // type can't be changed, and what it what pointing to + // can't be changed + const dereference_exprt &deref=to_dereference_expr(simplified_expr); + expressionst pointer_values; + bool pointer_const; + bool resolved= + try_resolve_expression(deref.pointer(), pointer_values, pointer_const); + if(resolved) + { + for(const exprt &pointer_val : pointer_values) + { + if(pointer_val.id()==ID_address_of) + { + address_of_exprt address_expr=to_address_of_expr(pointer_val); + bool object_const=false; + expressionst out_object_values; + bool resolved= + try_resolve_expression( + address_expr.object(), out_object_values, object_const); + + if(resolved) + { + out_resolved_expression.insert( + out_resolved_expression.end(), + out_object_values.begin(), + out_object_values.end()); + } + } + else + { + return false; + } + } + out_is_const=is_expression_const(deref) && pointer_const; + return true; + } + else + { + return false; + } + } + else if(simplified_expr.id()==ID_symbol) + { + const exprt &symbol_value=resolve_symbol(to_symbol_expr(simplified_expr)); + bool is_symbol_const=is_expression_const(simplified_expr); + bool is_symbol_value_const=false; + bool resolved_expression= + try_resolve_expression( + symbol_value, + out_resolved_expression, + is_symbol_value_const); + + // If we have a symbol, it is only const if the value it is assigned + // is const and it is in fact const. + out_is_const=is_symbol_const && is_symbol_const; + return resolved_expression; + } + // TOOD: probably need to do something with pointers or address_of + // and const since a const pointer to a non-const value is useless + else + { + out_is_const=is_expression_const(expr); + out_resolved_expression.push_back(expr); + return true; + } +} + +bool remove_const_function_pointerst::try_resolve_index_value( + const exprt &expr, mp_integer &out_array_index) +{ + expressionst index_value_expressions; + bool is_const=false; + bool resolved=try_resolve_expression(expr, index_value_expressions, is_const); + if(resolved) + { + if(index_value_expressions.size()==1 && + index_value_expressions.front().id()==ID_constant) + { + const constant_exprt &constant_expr= + to_constant_expr(index_value_expressions.front()); + mp_integer array_index; + bool errors=to_integer(constant_expr, array_index); + if(!errors) + { + out_array_index=array_index; + } + return !errors; + } + else + { + return false; + } + } + else + { + return false; + } +} + + +// Takes an index of, squashes its array and index +// if index is resolvable +bool remove_const_function_pointerst::try_resolve_index_of( + const index_exprt &index_expr, + expressionst &out_expressions, + bool &out_is_const) +{ + // Get the array(s) it belongs to + expressionst potential_array_exprs; + bool array_const=false; + bool resolved_array= + try_resolve_expression( + index_expr.array(), + potential_array_exprs, + array_const); + + if(resolved_array) + { + bool all_possible_const=true; + for(const exprt &potential_array_expr : potential_array_exprs) + { + all_possible_const= + all_possible_const && + is_type_const(potential_array_expr.type().subtype()); + + if(potential_array_expr.id()==ID_array) + { + // Get the index if we can + mp_integer value; + if(try_resolve_index_value(index_expr.index(), value)) + { + expressionst array_out_functions; + const exprt &func_expr= + potential_array_expr.operands()[integer2size_t(value)]; + bool value_const=false; + bool resolved_value= + try_resolve_expression(func_expr, array_out_functions, value_const); + + if(resolved_value) + { + out_expressions.insert( + out_expressions.end(), + array_out_functions.begin(), + array_out_functions.end()); + } + else + { + return false; + } + } + else + { + // We don't know what index it is, + // but we know the value is from the array + for(const exprt &array_entry : potential_array_expr.operands()) + { + expressionst array_contents; + bool is_entry_const; + bool resolved_value= + try_resolve_expression( + array_entry, array_contents, is_entry_const); + + if(resolved_value) + { + for(const exprt &resolved_array_entry : array_contents) + { + if(resolved_array_entry .is_zero()) + { + continue; + } + else + { + out_expressions.push_back(resolved_array_entry); + } + } + } + else + { + return false; + } + } + } + } + else + { + return false; + } + } + + out_is_const=all_possible_const || array_const; + return true; + } + else + { + return false; + } +} + +bool remove_const_function_pointerst::is_expression_const( + const exprt &expression) const +{ + return is_type_const(expression.type()); +} + +bool remove_const_function_pointerst::is_type_const(const typet &type) const +{ + c_qualifierst qualifers(type); + if(type.id()==ID_array) + { + c_qualifierst array_type_qualifers(type.subtype()); + return qualifers.is_constant || array_type_qualifers.is_constant; + } + else + { + return qualifers.is_constant; + } +} diff --git a/src/goto-programs/remove_const_function_pointers.h b/src/goto-programs/remove_const_function_pointers.h new file mode 100644 index 00000000000..cf7e85ca9a2 --- /dev/null +++ b/src/goto-programs/remove_const_function_pointers.h @@ -0,0 +1,62 @@ +/*******************************************************************\ + +Module: Goto Programs + +Author: Thomas Kiley, thomas.kiley@diffblue.com + +\*******************************************************************/ + +#ifndef CPROVER_GOTO_PROGRAMS_REMOVE_CONST_FUNCTION_POINTERS_H +#define CPROVER_GOTO_PROGRAMS_REMOVE_CONST_FUNCTION_POINTERS_H + +#include "goto_model.h" +#include +#include +#include + + +class remove_const_function_pointerst:public messaget +{ +public: + typedef std::set functionst; + typedef std::list expressionst; + remove_const_function_pointerst( + message_handlert &message_handler, + const exprt &base_expression, + const namespacet &ns, + const symbol_tablet &symbol_table); + + bool operator()(functionst &out_functions); + +private: + exprt resolve_symbol(const symbol_exprt &symbol_expr) const; + + // recursive functions for dealing with the function pointer + bool try_resolve_function_call(const exprt &expr, functionst &out_functions); + + bool try_resolve_index_of_function_call( + const index_exprt &index_expr, functionst &out_functions); + + // recursive functions for dealing with the auxiliary elements + bool try_resolve_expression( + const exprt &expr, + expressionst &out_resolved_expression, + bool &out_is_const); + + bool try_resolve_index_value( + const exprt &index_value_expr, mp_integer &out_array_index); + + bool try_resolve_index_of( + const index_exprt &index_expr, + expressionst &out_expressions, + bool &out_is_const); + + bool is_expression_const(const exprt &expression) const; + bool is_type_const(const typet &type) const; + + const exprt original_expression; + const namespacet &ns; + const symbol_tablet &symbol_table; +}; + +#endif // CPROVER_GOTO_PROGRAMS_REMOVE_CONST_FUNCTION_POINTERS_H diff --git a/src/goto-programs/remove_function_pointers.cpp b/src/goto-programs/remove_function_pointers.cpp index aee2dcae89b..1e63b25a9a6 100644 --- a/src/goto-programs/remove_function_pointers.cpp +++ b/src/goto-programs/remove_function_pointers.cpp @@ -21,6 +21,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "remove_skip.h" #include "remove_function_pointers.h" #include "compute_called_functions.h" +#include "remove_const_function_pointers.h" /*******************************************************************\ @@ -343,40 +344,48 @@ void remove_function_pointerst::remove_function_pointer( assert(function.operands().size()==1); const exprt &pointer=function.op0(); + remove_const_function_pointerst::functionst functions; + remove_const_function_pointerst fpr( + get_message_handler(), pointer, ns, symbol_table); - // Is this simple? - if(pointer.id()==ID_address_of && - to_address_of_expr(pointer).object().id()==ID_symbol) + bool found_functions=fpr(functions); + + if(functions.size()==1) { - to_code_function_call(target->code).function()= - to_address_of_expr(pointer).object(); + to_code_function_call(target->code).function()=*functions.cbegin(); return; } - typedef std::list functionst; - functionst functions; + if(!found_functions) + { + debug() << "Failed to optimize away the function pointer\n" + << "The type was " << pointer.id() << " " + << "irep dump:\n" + << pointer.pretty() + << eom; - bool return_value_used=code.lhs().is_not_nil(); + bool return_value_used=code.lhs().is_not_nil(); - // get all type-compatible functions - // whose address is ever taken - for(const auto &t : type_map) - { - // address taken? - if(address_taken.find(t.first)==address_taken.end()) - continue; + // get all type-compatible functions + // whose address is ever taken + for(const auto &t : type_map) + { + // address taken? + if(address_taken.find(t.first)==address_taken.end()) + continue; - // type-compatible? - if(!is_type_compatible(return_value_used, call_type, t.second)) - continue; + // type-compatible? + if(!is_type_compatible(return_value_used, call_type, t.second)) + continue; - if(t.first=="pthread_mutex_cleanup") - continue; + if(t.first=="pthread_mutex_cleanup") + continue; - symbol_exprt expr; - expr.type()=t.second; - expr.set_identifier(t.first); - functions.push_back(expr); + symbol_exprt expr; + expr.type()=t.second; + expr.set_identifier(t.first); + functions.insert(expr); + } } // the final target is a skip From 3b3acd641cca38e77e31571acb4ed6af0a915a0b Mon Sep 17 00:00:00 2001 From: thk123 Date: Thu, 2 Feb 2017 14:53:37 +0000 Subject: [PATCH 04/46] Support for removing the typecast --- .../remove_const_function_pointers.cpp | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index ebf6840ecbc..b5537365d0a 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -322,6 +322,33 @@ bool remove_const_function_pointerst::try_resolve_expression( return false; } } + else if(simplified_expr.id()==ID_typecast) + { + // We simply ignore typecasts and assume they are valid + // I thought simplify_expr would deal with this, but for example + // a cast from a 32 bit width int to a 64bit width int it doesn't seem + // to allow + typecast_exprt typecast_expr=to_typecast_expr(simplified_expr); + expressionst typecast_values; + bool typecast_const; + bool resolved= + try_resolve_expression( + typecast_expr.op(), typecast_values, typecast_const); + + if(resolved) + { + out_resolved_expression.insert( + out_resolved_expression.end(), + typecast_values.begin(), + typecast_values.end()); + out_is_const=typecast_const; + return true; + } + else + { + return false; + } + } else if(simplified_expr.id()==ID_symbol) { const exprt &symbol_value=resolve_symbol(to_symbol_expr(simplified_expr)); @@ -342,8 +369,8 @@ bool remove_const_function_pointerst::try_resolve_expression( // and const since a const pointer to a non-const value is useless else { - out_is_const=is_expression_const(expr); - out_resolved_expression.push_back(expr); + out_is_const=is_expression_const(simplified_expr); + out_resolved_expression.push_back(simplified_expr); return true; } } From e4829ebd7c8f5d70734713f7a8ebf6322a55f8e0 Mon Sep 17 00:00:00 2001 From: thk123 Date: Thu, 2 Feb 2017 15:25:03 +0000 Subject: [PATCH 05/46] Adding support for top level pointers and typecasts --- .../goto-analyzer/fp-removal12/test.desc | 11 ++-- .../goto-analyzer/fp-removal14/test.desc | 4 +- .../goto-analyzer/fp-removal20/test.desc | 8 +-- .../remove_const_function_pointers.cpp | 66 +++++++++++++++++++ 4 files changed, 76 insertions(+), 13 deletions(-) diff --git a/regression/goto-analyzer/fp-removal12/test.desc b/regression/goto-analyzer/fp-removal12/test.desc index 63ff819792f..701da09802e 100644 --- a/regression/goto-analyzer/fp-removal12/test.desc +++ b/regression/goto-analyzer/fp-removal12/test.desc @@ -1,6 +1,6 @@ -KNOWNBUG +CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*f3();$ @@ -8,8 +8,5 @@ main.c -- ^warning: ignoring -- -This test is marked as a KNOWNBUG as it is possible for the function -pointer to be optimized away. Currently goto-analyzer falls back to -assuming it could be any type compatible function. - -Issue: https://github.com/diffblue/cbmc/issues/476 +This is currently failing because the const is being ignored inside +the struct diff --git a/regression/goto-analyzer/fp-removal14/test.desc b/regression/goto-analyzer/fp-removal14/test.desc index 63ff819792f..649ba6fbedd 100644 --- a/regression/goto-analyzer/fp-removal14/test.desc +++ b/regression/goto-analyzer/fp-removal14/test.desc @@ -1,6 +1,6 @@ -KNOWNBUG +CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*f3();$ diff --git a/regression/goto-analyzer/fp-removal20/test.desc b/regression/goto-analyzer/fp-removal20/test.desc index f1dc8590822..81db0db6f9f 100644 --- a/regression/goto-analyzer/fp-removal20/test.desc +++ b/regression/goto-analyzer/fp-removal20/test.desc @@ -1,11 +1,11 @@ -KNOWNBUG +CORE main.c --show-goto-functions ^Removing function pointers and virtual functions$ -^\s*IF fp == f2 THEN GOTO 1$ -^\s*IF fp == f3 THEN GOTO 2$ -^\s*IF fp == f4 THEN GOTO 3$ +^\s*IF fp == (void (\*)(void))f2 THEN GOTO 1$ +^\s*IF fp == (void (\*)(void))f3 THEN GOTO 2$ +^\s*IF fp == (void (\*)(void))f4 THEN GOTO 3$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index b5537365d0a..8eb406eecf0 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -90,6 +90,72 @@ bool remove_const_function_pointerst::try_resolve_function_call( address_of_exprt address_expr=to_address_of_expr(simplified_expr); return try_resolve_function_call(address_expr.object(), out_functions); } + else if(simplified_expr.id()==ID_dereference) + { + // We had a pointer, we need to check both the pointer + // type can't be changed, and what it what pointing to + // can't be changed + const dereference_exprt &deref=to_dereference_expr(simplified_expr); + expressionst pointer_values; + bool pointer_const; + bool resolved= + try_resolve_expression(deref.pointer(), pointer_values, pointer_const); + if(resolved && is_expression_const(deref)) + { + for(const exprt &pointer_val : pointer_values) + { + if(pointer_val.id()==ID_address_of) + { + address_of_exprt address_expr=to_address_of_expr(pointer_val); + functionst out_object_values; + bool resolved= + try_resolve_function_call( + address_expr.object(), out_object_values); + + if(resolved) + { + out_functions.insert( + out_object_values.begin(), + out_object_values.end()); + } + else + { + return false; + } + } + else + { + return false; + } + } + return true; + } + else + { + return false; + } + } + else if(simplified_expr.id()==ID_typecast) + { + // We simply ignore typecasts and assume they are valid + // I thought simplify_expr would deal with this, but for example + // a cast from a 32 bit width int to a 64bit width int it doesn't seem + // to allow + typecast_exprt typecast_expr=to_typecast_expr(simplified_expr); + functionst typecast_values; + bool resolved= + try_resolve_function_call(typecast_expr.op(), typecast_values); + + if(resolved) + { + out_functions.insert(typecast_values.begin(), typecast_values.end()); + return true; + } + else + { + return false; + } + } else if(simplified_expr.id()==ID_symbol) { if(simplified_expr.type().id()==ID_code) From 11f15eeaea0a7361bf232997c8b77002c16d9cb5 Mon Sep 17 00:00:00 2001 From: thk123 Date: Thu, 2 Feb 2017 15:44:13 +0000 Subject: [PATCH 06/46] Fixing arrays containing null pointers --- .../remove_const_function_pointers.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 8eb406eecf0..2c51a3e96ca 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -232,25 +232,18 @@ bool remove_const_function_pointerst::try_resolve_index_of_function_call( // but we know the value is from the array for(const exprt &array_entry : potential_array_expr.operands()) { + if(array_entry.is_zero()) + { + continue; + } functionst potential_functions; bool resolved_value= try_resolve_function_call(array_entry, potential_functions); if(resolved_value) { - for(const exprt &potential_function : potential_functions) - { - if(potential_function.is_zero()) - { - continue; - } - else - { - out_functions.insert( - potential_functions.begin(), - potential_functions.end()); - } - } + out_functions.insert( + potential_functions.begin(), potential_functions.end()); } else { From a479c98a055f209e0d67fc06d496a8f9b3d70e3d Mon Sep 17 00:00:00 2001 From: thk123 Date: Thu, 2 Feb 2017 15:45:30 +0000 Subject: [PATCH 07/46] Correctly deal with const structures --- .../remove_const_function_pointers.cpp | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 2c51a3e96ca..8cd32ed35a0 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -52,8 +52,9 @@ bool remove_const_function_pointerst::try_resolve_function_call( const exprt &owner_expr=member_expr.compound(); // Squash the struct expressionst out_expressions; - bool is_const=false; - bool resolved=try_resolve_expression(owner_expr, out_expressions, is_const); + bool struct_is_const=false; + bool resolved= + try_resolve_expression(owner_expr, out_expressions, struct_is_const); if(resolved) { for(const exprt &expression:out_expressions) @@ -68,9 +69,18 @@ bool remove_const_function_pointerst::try_resolve_function_call( const exprt &component_value= struct_expr.operands()[member_expr.get_component_number()]; // TODO: copy into out_functions rather than supply direct like - bool resolved= - try_resolve_function_call(component_value, out_functions); - if(!resolved) + bool component_const=is_expression_const(component_value); + + if(component_const || struct_is_const) + { + bool resolved= + try_resolve_function_call(component_value, out_functions); + if(!resolved) + { + return false; + } + } + else { return false; } From 921f0b7af08ebc85f6a558cc7753b292a236b5e8 Mon Sep 17 00:00:00 2001 From: thk123 Date: Thu, 2 Feb 2017 18:01:05 +0000 Subject: [PATCH 08/46] Fixing component access and const access --- .../remove_const_function_pointers.cpp | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 8cd32ed35a0..bd49163817d 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -65,9 +65,14 @@ bool remove_const_function_pointerst::try_resolve_function_call( } else { - struct_exprt struct_expr=to_struct_expr(expression); + + struct_typet struct_type=to_struct_type(ns.follow(expression.type())); + size_t component_number= + struct_type.component_number(member_expr.get_component_name()); + + const struct_exprt &struct_expr=to_struct_expr(expression); const exprt &component_value= - struct_expr.operands()[member_expr.get_component_number()]; + struct_expr.operands()[component_number]; // TODO: copy into out_functions rather than supply direct like bool component_const=is_expression_const(component_value); @@ -383,7 +388,7 @@ bool remove_const_function_pointerst::try_resolve_expression( return false; } } - out_is_const=is_expression_const(deref) && pointer_const; + out_is_const=pointer_const; return true; } else @@ -422,17 +427,26 @@ bool remove_const_function_pointerst::try_resolve_expression( { const exprt &symbol_value=resolve_symbol(to_symbol_expr(simplified_expr)); bool is_symbol_const=is_expression_const(simplified_expr); - bool is_symbol_value_const=false; - bool resolved_expression= - try_resolve_expression( - symbol_value, - out_resolved_expression, - is_symbol_value_const); - - // If we have a symbol, it is only const if the value it is assigned - // is const and it is in fact const. - out_is_const=is_symbol_const && is_symbol_const; - return resolved_expression; + //if(is_symbol_const) + { + bool is_symbol_value_const=false; + bool resolved_expression= + try_resolve_expression( + symbol_value, + out_resolved_expression, + is_symbol_value_const); + + // If we have a symbol, it is only const if the value it is assigned + // is const and it is in fact const. + out_is_const=is_symbol_value_const && is_symbol_const; + return resolved_expression; + } + /*else + { + // If the symbol isn't const, we can't know what its value is so + // we carry on + return false; + }*/ } // TOOD: probably need to do something with pointers or address_of // and const since a const pointer to a non-const value is useless From b814d65ece0d793d04153ff9ec7b67afa2fc16d8 Mon Sep 17 00:00:00 2001 From: thk123 Date: Mon, 6 Feb 2017 15:23:29 +0000 Subject: [PATCH 09/46] Fixing todo to use separate array When trying to resolve the functions of a component, we don't use the array directly in case the step fails and therefore we shouldn't add them to our list. --- src/goto-programs/remove_const_function_pointers.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index bd49163817d..0804c273d0c 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -73,14 +73,19 @@ bool remove_const_function_pointerst::try_resolve_function_call( const struct_exprt &struct_expr=to_struct_expr(expression); const exprt &component_value= struct_expr.operands()[component_number]; - // TODO: copy into out_functions rather than supply direct like bool component_const=is_expression_const(component_value); if(component_const || struct_is_const) { + functionst component_functions; bool resolved= - try_resolve_function_call(component_value, out_functions); - if(!resolved) + try_resolve_function_call(component_value, component_functions); + if(resolved) + { + out_functions.insert( + component_functions.begin(), component_functions.end()); + } + else { return false; } From 22ca113d456dd11db53eaf32dd6597d89d1f002e Mon Sep 17 00:00:00 2001 From: thk123 Date: Tue, 7 Feb 2017 13:47:05 +0000 Subject: [PATCH 10/46] Corrected const-ness for components We require either the struct to be const, or the type of the component to be const (not the value the component is assigned, which will rarely be const). --- src/goto-programs/remove_const_function_pointers.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 0804c273d0c..77fcf22f07c 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -73,7 +73,12 @@ bool remove_const_function_pointerst::try_resolve_function_call( const struct_exprt &struct_expr=to_struct_expr(expression); const exprt &component_value= struct_expr.operands()[component_number]; - bool component_const=is_expression_const(component_value); + + // Find out if the component is constant + struct_union_typet::componentt component= + struct_type.components()[component_number]; + + bool component_const=is_type_const(component.type()); if(component_const || struct_is_const) { From d87dffdd827a9d67a6c29a9acad299428085e1bf Mon Sep 17 00:00:00 2001 From: thk123 Date: Tue, 7 Feb 2017 13:48:13 +0000 Subject: [PATCH 11/46] Handle failure to squash the value when getting out of an array --- src/goto-programs/remove_const_function_pointers.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 77fcf22f07c..47e2be1f40c 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -250,6 +250,10 @@ bool remove_const_function_pointerst::try_resolve_index_of_function_call( array_out_functions.begin(), array_out_functions.end()); } + else + { + return false; + } } else { From f51b2524d1afdffe88b3e57662551e7759b3f654 Mon Sep 17 00:00:00 2001 From: thk123 Date: Tue, 7 Feb 2017 13:50:00 +0000 Subject: [PATCH 12/46] Correcting const check for pointers --- .../remove_const_function_pointers.cpp | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 47e2be1f40c..4e7dd10928b 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -376,8 +376,9 @@ bool remove_const_function_pointerst::try_resolve_expression( bool pointer_const; bool resolved= try_resolve_expression(deref.pointer(), pointer_values, pointer_const); - if(resolved) + if(resolved && pointer_const) { + bool all_objects_const=true; for(const exprt &pointer_val : pointer_values) { if(pointer_val.id()==ID_address_of) @@ -395,6 +396,8 @@ bool remove_const_function_pointerst::try_resolve_expression( out_resolved_expression.end(), out_object_values.begin(), out_object_values.end()); + + all_objects_const&=object_const; } } else @@ -402,7 +405,7 @@ bool remove_const_function_pointerst::try_resolve_expression( return false; } } - out_is_const=pointer_const; + out_is_const=all_objects_const; return true; } else @@ -441,26 +444,17 @@ bool remove_const_function_pointerst::try_resolve_expression( { const exprt &symbol_value=resolve_symbol(to_symbol_expr(simplified_expr)); bool is_symbol_const=is_expression_const(simplified_expr); - //if(is_symbol_const) - { - bool is_symbol_value_const=false; - bool resolved_expression= - try_resolve_expression( - symbol_value, - out_resolved_expression, - is_symbol_value_const); - - // If we have a symbol, it is only const if the value it is assigned - // is const and it is in fact const. - out_is_const=is_symbol_value_const && is_symbol_const; - return resolved_expression; - } - /*else - { - // If the symbol isn't const, we can't know what its value is so - // we carry on - return false; - }*/ + bool is_symbol_value_const=false; + bool resolved_expression= + try_resolve_expression( + symbol_value, + out_resolved_expression, + is_symbol_value_const); + + // If we have a symbol, it is only const if the value it is assigned + // is const and it is in fact const. + out_is_const=is_symbol_const; + return resolved_expression; } // TOOD: probably need to do something with pointers or address_of // and const since a const pointer to a non-const value is useless From 1fbfbbc410ccaf54a72c265d3ac97610baf2c787 Mon Sep 17 00:00:00 2001 From: thk123 Date: Tue, 7 Feb 2017 13:50:27 +0000 Subject: [PATCH 13/46] Adding examples to tests of what the const prevents --- regression/goto-analyzer/fp-removal11/main.c | 4 ++++ regression/goto-analyzer/fp-removal23/main.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/regression/goto-analyzer/fp-removal11/main.c b/regression/goto-analyzer/fp-removal11/main.c index 19988eaf32a..3f90a10ab65 100644 --- a/regression/goto-analyzer/fp-removal11/main.c +++ b/regression/goto-analyzer/fp-removal11/main.c @@ -22,6 +22,10 @@ void func(){ fp_tbl[0]=f2; fp_tbl[1]=f3; fp_tbl[2]=f4; + + // Illegal + //fp_tbl = malloc(sizeof(void_fp) * 10); + const void_fp fp = fp_tbl[1]; fp(); } diff --git a/regression/goto-analyzer/fp-removal23/main.c b/regression/goto-analyzer/fp-removal23/main.c index 09937213470..e4f1ee8c491 100644 --- a/regression/goto-analyzer/fp-removal23/main.c +++ b/regression/goto-analyzer/fp-removal23/main.c @@ -24,6 +24,9 @@ const struct action rec = { .fun = f2 }; const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9}; void func(int i){ + + // Illegal: + //rec.fun = &f5; const void_fp fp = rec.fun; fp(); } From 5ab672ad3b906cbfb5a81ad9382bb978e3c5e268 Mon Sep 17 00:00:00 2001 From: thk123 Date: Tue, 7 Feb 2017 14:38:26 +0000 Subject: [PATCH 14/46] Corrected const check for no FP pointers --- src/goto-programs/remove_const_function_pointers.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 4e7dd10928b..cd3cf0dc91c 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -125,7 +125,11 @@ bool remove_const_function_pointerst::try_resolve_function_call( bool pointer_const; bool resolved= try_resolve_expression(deref.pointer(), pointer_values, pointer_const); - if(resolved && is_expression_const(deref)) + + // Here we require that the value we are dereferencing is const + // The actual type doesn't matter since we are on the RHS so what matters + // is where this gets stored, but the value stored matters + if(resolved && pointer_const) { for(const exprt &pointer_val : pointer_values) { From 0499b4400b1b3d9ed42f9ecaceb0e915216bcaa5 Mon Sep 17 00:00:00 2001 From: thk123 Date: Tue, 7 Feb 2017 17:48:01 +0000 Subject: [PATCH 15/46] Added tests to cover a couple of missed lines 42 also demonstrates a bug that this commit fixes with index accessed function calls that fail to resolve the array. Specifically, if squashing the struct failed, we still returned true. That happens in this instance as the pointer to the struct is not constant. --- regression/goto-analyzer/fp-removal42/main.c | 41 +++++++++++++ .../goto-analyzer/fp-removal42/test.desc | 17 ++++++ regression/goto-analyzer/fp-removal43/main.c | 50 ++++++++++++++++ .../goto-analyzer/fp-removal43/test.desc | 17 ++++++ .../remove_const_function_pointers.cpp | 60 +++++++++++-------- 5 files changed, 159 insertions(+), 26 deletions(-) create mode 100644 regression/goto-analyzer/fp-removal42/main.c create mode 100644 regression/goto-analyzer/fp-removal42/test.desc create mode 100644 regression/goto-analyzer/fp-removal43/main.c create mode 100644 regression/goto-analyzer/fp-removal43/test.desc diff --git a/regression/goto-analyzer/fp-removal42/main.c b/regression/goto-analyzer/fp-removal42/main.c new file mode 100644 index 00000000000..bd46ce92484 --- /dev/null +++ b/regression/goto-analyzer/fp-removal42/main.c @@ -0,0 +1,41 @@ +#include +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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}; + +typedef struct fp_container +{ + void_fp fp_tbl[3]; +} fp_container; + + + +void func(){ + const fp_container container = { .fp_tbl = {f2 ,f3, f4} }; + const void_fp alternatate_fp_tbl[] = {f5 ,f6, f7}; + const fp_container container2 = { .fp_tbl = {f5 ,f6, f7} }; + // Illegal: + // container.fp_tbl = alternatate_fp_tbl; + // container.fp_tbl[1] = f4; + const fp_container *container_ptr=&container; + container_ptr=&container2; + container_ptr->fp_tbl[1](); +} + +int main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal42/test.desc b/regression/goto-analyzer/fp-removal42/test.desc new file mode 100644 index 00000000000..b53053f12a4 --- /dev/null +++ b/regression/goto-analyzer/fp-removal42/test.desc @@ -0,0 +1,17 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f1 THEN GOTO 1$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f2 THEN GOTO 2$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f3 THEN GOTO 3$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f4 THEN GOTO 4$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f5 THEN GOTO 5$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f6 THEN GOTO 6$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f7 THEN GOTO 7$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f8 THEN GOTO 8$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f9 THEN GOTO 9$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal43/main.c b/regression/goto-analyzer/fp-removal43/main.c new file mode 100644 index 00000000000..e0b37fceb10 --- /dev/null +++ b/regression/goto-analyzer/fp-removal43/main.c @@ -0,0 +1,50 @@ +#include +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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}; + +typedef struct fp_container +{ + const void_fp* const fp_tbl[3]; +} fp_container; + + + +void func(){ + void_fp f2meta = &f2; + void_fp f3meta = &f3; + void_fp f4meta = &f4; + + void_fp f5meta = &f5; + void_fp f6meta = &f6; + void_fp f7meta = &f7; + + const fp_container container = { .fp_tbl = {&f2meta ,&f3meta, &f4meta} }; + const fp_container container2 = { .fp_tbl = {&f5meta ,&f6meta, &f7meta} }; + + f3meta = &f5; + // Illegal: + // container.fp_tbl = alternatate_fp_tbl; + // container.fp_tbl[1] = f4; + const fp_container * const container_ptr=&container; + //container_ptr=&container2; + (*container_ptr->fp_tbl[1])(); +} + +int main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal43/test.desc b/regression/goto-analyzer/fp-removal43/test.desc new file mode 100644 index 00000000000..94f1774abb7 --- /dev/null +++ b/regression/goto-analyzer/fp-removal43/test.desc @@ -0,0 +1,17 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f1 THEN GOTO 1$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f2 THEN GOTO 2$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f3 THEN GOTO 3$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f4 THEN GOTO 4$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f5 THEN GOTO 5$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f6 THEN GOTO 6$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f7 THEN GOTO 7$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f8 THEN GOTO 8$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f9 THEN GOTO 9$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index cd3cf0dc91c..c239a3f67d8 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -331,44 +331,52 @@ bool remove_const_function_pointerst::try_resolve_expression( expressionst potential_structs; bool is_struct_const; - try_resolve_expression( - member_expr.compound(), potential_structs, is_struct_const); + bool resolved_struct= + try_resolve_expression( + member_expr.compound(), potential_structs, is_struct_const); - bool all_components_const=true; - for(const exprt &potential_struct : potential_structs) + if(resolved_struct) { - if(potential_struct.id()==ID_struct) + bool all_components_const=true; + for(const exprt &potential_struct : potential_structs) { - struct_exprt struct_expr=to_struct_expr(potential_struct); - const exprt &component_value= - struct_expr.operands()[member_expr.get_component_number()]; - expressionst out_expressions; - bool component_const=false; - bool resolved= - try_resolve_expression( - component_value, out_expressions, component_const); - if(resolved) + if(potential_struct.id()==ID_struct) { - out_resolved_expression.insert( - out_resolved_expression.end(), - out_expressions.begin(), - out_expressions.end()); + struct_exprt struct_expr=to_struct_expr(potential_struct); + const exprt &component_value= + struct_expr.operands()[member_expr.get_component_number()]; + expressionst out_expressions; + bool component_const=false; + bool resolved= + try_resolve_expression( + component_value, out_expressions, component_const); + if(resolved) + { + out_resolved_expression.insert( + out_resolved_expression.end(), + out_expressions.begin(), + out_expressions.end()); - all_components_const= - all_components_const && component_const; + all_components_const= + all_components_const && component_const; + } + else + { + return false; + } } else { return false; } } - else - { - return false; - } + out_is_const=all_components_const||is_struct_const; + return true; + } + else + { + return false; } - out_is_const=all_components_const||is_struct_const; - return true; } else if(simplified_expr.id()==ID_dereference) { From 208ef2b91a02067aa2f53b4f2af8e3649b49cbb5 Mon Sep 17 00:00:00 2001 From: thk123 Date: Wed, 8 Feb 2017 13:30:39 +0000 Subject: [PATCH 16/46] Fixed issue with structs with other components If the component was not the top level thing (e.g., as in 44, it was a pointer to a FP) we weren't correctly resolving structs that had other components (the get_component_number does not in general work). Made the two different handlings of the ID_member behave consistently and correctly. Also would have failed on 46 where the component was const but the struct was not as was checking the type of the component value rather than the component type itself. --- regression/goto-analyzer/fp-removal44/main.c | 41 ++++++++++ .../goto-analyzer/fp-removal44/test.desc | 9 +++ regression/goto-analyzer/fp-removal45/main.c | 41 ++++++++++ .../goto-analyzer/fp-removal45/test.desc | 9 +++ regression/goto-analyzer/fp-removal46/main.c | 41 ++++++++++ .../goto-analyzer/fp-removal46/test.desc | 9 +++ .../remove_const_function_pointers.cpp | 78 +++++++++++++++---- .../remove_const_function_pointers.h | 6 ++ 8 files changed, 219 insertions(+), 15 deletions(-) create mode 100644 regression/goto-analyzer/fp-removal44/main.c create mode 100644 regression/goto-analyzer/fp-removal44/test.desc create mode 100644 regression/goto-analyzer/fp-removal45/main.c create mode 100644 regression/goto-analyzer/fp-removal45/test.desc create mode 100644 regression/goto-analyzer/fp-removal46/main.c create mode 100644 regression/goto-analyzer/fp-removal46/test.desc diff --git a/regression/goto-analyzer/fp-removal44/main.c b/regression/goto-analyzer/fp-removal44/main.c new file mode 100644 index 00000000000..c7237dee13f --- /dev/null +++ b/regression/goto-analyzer/fp-removal44/main.c @@ -0,0 +1,41 @@ +#include +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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}; + +typedef struct fp_cc +{ + int x; + const void_fp * const container; +} fp_cc; + + + +void func(){ + const void_fp meta_fp = &f3; + const fp_cc container_container = { .container = &meta_fp, .x = 4 }; + + // Illegal: + //meta_fp = &f4; + //container_container.container = &f4; + + (*container_container.container)(); +} + +int main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal44/test.desc b/regression/goto-analyzer/fp-removal44/test.desc new file mode 100644 index 00000000000..77c3b9a93d1 --- /dev/null +++ b/regression/goto-analyzer/fp-removal44/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*f3();$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal45/main.c b/regression/goto-analyzer/fp-removal45/main.c new file mode 100644 index 00000000000..7324bad0488 --- /dev/null +++ b/regression/goto-analyzer/fp-removal45/main.c @@ -0,0 +1,41 @@ +#include +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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}; + +typedef struct fp_cc +{ + int x; + const void_fp * container; +} fp_cc; + + + +void func(){ + const void_fp meta_fp = &f3; + const fp_cc container_container = { .container = &meta_fp, .x = 4 }; + + // Illegal: + //meta_fp = &f4; + //container_container.container = &f4; + + (*container_container.container)(); +} + +int main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal45/test.desc b/regression/goto-analyzer/fp-removal45/test.desc new file mode 100644 index 00000000000..77c3b9a93d1 --- /dev/null +++ b/regression/goto-analyzer/fp-removal45/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*f3();$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal46/main.c b/regression/goto-analyzer/fp-removal46/main.c new file mode 100644 index 00000000000..26770f0b1e7 --- /dev/null +++ b/regression/goto-analyzer/fp-removal46/main.c @@ -0,0 +1,41 @@ +#include +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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}; + +typedef struct fp_cc +{ + int x; + const void_fp * const container; +} fp_cc; + + + +void func(){ + const void_fp meta_fp = &f3; + fp_cc container_container = { .container = &meta_fp, .x = 4 }; + + // Illegal: + //meta_fp = &f4; + //container_container.container = &f4; + + (*container_container.container)(); +} + +int main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal46/test.desc b/regression/goto-analyzer/fp-removal46/test.desc new file mode 100644 index 00000000000..77c3b9a93d1 --- /dev/null +++ b/regression/goto-analyzer/fp-removal46/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*f3();$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index c239a3f67d8..1b6f0289510 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -65,20 +65,13 @@ bool remove_const_function_pointerst::try_resolve_function_call( } else { - - struct_typet struct_type=to_struct_type(ns.follow(expression.type())); - size_t component_number= - struct_type.component_number(member_expr.get_component_name()); - const struct_exprt &struct_expr=to_struct_expr(expression); const exprt &component_value= - struct_expr.operands()[component_number]; + get_component_value(struct_expr, member_expr); - // Find out if the component is constant - struct_union_typet::componentt component= - struct_type.components()[component_number]; - - bool component_const=is_type_const(component.type()); + const typet &component_type= + get_component_type(struct_expr, member_expr); + bool component_const=is_type_const(component_type); if(component_const || struct_is_const) { @@ -344,7 +337,12 @@ bool remove_const_function_pointerst::try_resolve_expression( { struct_exprt struct_expr=to_struct_expr(potential_struct); const exprt &component_value= - struct_expr.operands()[member_expr.get_component_number()]; + get_component_value(struct_expr, member_expr); + const typet &component_type= + get_component_type(struct_expr, member_expr); + + all_components_const&=is_type_const(component_type); + expressionst out_expressions; bool component_const=false; bool resolved= @@ -356,9 +354,6 @@ bool remove_const_function_pointerst::try_resolve_expression( out_resolved_expression.end(), out_expressions.begin(), out_expressions.end()); - - all_components_const= - all_components_const && component_const; } else { @@ -628,3 +623,56 @@ bool remove_const_function_pointerst::is_type_const(const typet &type) const return qualifers.is_constant; } } + +/*******************************************************************\ + +Function: remove_const_function_pointerst::get_component_value + + Inputs: + struct_expr - The expression of the structure being accessed + member_expr - The expression saying which component is being accessed + + Outputs: Returns the value of a specific component for a given struct + expression. + + Purpose: To extract the value of the specific component within a struct + +\*******************************************************************/ + +exprt remove_const_function_pointerst::get_component_value( + const struct_exprt &struct_expr, const member_exprt &member_expr) +{ + const struct_typet &struct_type=to_struct_type(ns.follow(struct_expr.type())); + size_t component_number= + struct_type.component_number(member_expr.get_component_name()); + + return struct_expr.operands()[component_number]; +} + +/*******************************************************************\ + +Function: remove_const_function_pointerst::get_component_type + + Inputs: + struct_expr - The expression of the structure being accessed + member_expr - The expression saying which component is being accessed + + Outputs: Returns the type of the component. Note this may be differenent to + the type of its value (e.g. it may be a const pointer but its value + could just be a pointer). + + Purpose: To extract the type of the specific component within a struct + +\*******************************************************************/ + +typet remove_const_function_pointerst::get_component_type( + const struct_exprt &struct_expr, const member_exprt &member_expr) +{ + const struct_typet &struct_type=to_struct_type(ns.follow(struct_expr.type())); + size_t component_number= + struct_type.component_number(member_expr.get_component_name()); + struct_union_typet::componentt component= + struct_type.components()[component_number]; + + return component.type(); +} diff --git a/src/goto-programs/remove_const_function_pointers.h b/src/goto-programs/remove_const_function_pointers.h index cf7e85ca9a2..f641b0ce7ee 100644 --- a/src/goto-programs/remove_const_function_pointers.h +++ b/src/goto-programs/remove_const_function_pointers.h @@ -54,6 +54,12 @@ class remove_const_function_pointerst:public messaget bool is_expression_const(const exprt &expression) const; bool is_type_const(const typet &type) const; + exprt get_component_value( + const struct_exprt &struct_expr, const member_exprt &member_expr); + + typet get_component_type( + const struct_exprt &struct_expr, const member_exprt &member_expr); + const exprt original_expression; const namespacet &ns; const symbol_tablet &symbol_table; From 3da26cd124ad1dbf9539136a43a4ef50ce7deb6f Mon Sep 17 00:00:00 2001 From: thk123 Date: Wed, 8 Feb 2017 14:32:32 +0000 Subject: [PATCH 17/46] Adding test for another way the previous bug could be exhibited --- regression/goto-analyzer/fp-removal47/main.c | 48 +++++++++++++++++++ .../goto-analyzer/fp-removal47/test.desc | 9 ++++ 2 files changed, 57 insertions(+) create mode 100644 regression/goto-analyzer/fp-removal47/main.c create mode 100644 regression/goto-analyzer/fp-removal47/test.desc diff --git a/regression/goto-analyzer/fp-removal47/main.c b/regression/goto-analyzer/fp-removal47/main.c new file mode 100644 index 00000000000..70b853a9dff --- /dev/null +++ b/regression/goto-analyzer/fp-removal47/main.c @@ -0,0 +1,48 @@ +#include +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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}; + +typedef struct fp_container +{ + int y; + const void_fp pointer; +} fp_container; + +typedef struct fp_cc +{ + int x; + const fp_container * const container; +} fp_cc; + + + +void func(){ + const fp_container container = {.y = 10, .pointer = f3}; + const fp_container container2 = {.y = 10, .pointer = f4}; + const fp_cc container_container = { .container = &container, .x = 4 }; + + // Illegal: + //container_container.container = &container2; + //container.pointer = f4; + + (*container_container.container).pointer(); +} + +int main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal47/test.desc b/regression/goto-analyzer/fp-removal47/test.desc new file mode 100644 index 00000000000..77c3b9a93d1 --- /dev/null +++ b/regression/goto-analyzer/fp-removal47/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*f3();$ +^SIGNAL=0$ +-- +^warning: ignoring From eefba98432405be583748eb1d264da74506c5fad Mon Sep 17 00:00:00 2001 From: thk123 Date: Wed, 8 Feb 2017 14:49:59 +0000 Subject: [PATCH 18/46] Adding a test variation of 44 without the consts that fails correctly --- regression/goto-analyzer/fp-removal48/main.c | 42 +++++++++++++++++++ .../goto-analyzer/fp-removal48/test.desc | 17 ++++++++ 2 files changed, 59 insertions(+) create mode 100644 regression/goto-analyzer/fp-removal48/main.c create mode 100644 regression/goto-analyzer/fp-removal48/test.desc diff --git a/regression/goto-analyzer/fp-removal48/main.c b/regression/goto-analyzer/fp-removal48/main.c new file mode 100644 index 00000000000..12949ed8d85 --- /dev/null +++ b/regression/goto-analyzer/fp-removal48/main.c @@ -0,0 +1,42 @@ +#include +#include + +void f1 (void) { printf("%i", 1); } +void f2 (void) { printf("%i", 2); } +void f3 (void) { printf("%i", 3); } +void f4 (void) { printf("%i", 4); } +void f5 (void) { printf("%i", 5); } +void f6 (void) { printf("%i", 6); } +void f7 (void) { printf("%i", 7); } +void f8 (void) { printf("%i", 8); } +void f9 (void) { printf("%i", 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}; + +typedef struct fp_cc +{ + int x; + const void_fp * container; +} fp_cc; + + + +void func(){ + const void_fp meta_fp = &f3; + const void_fp meta_fp2 = &f4; + fp_cc container_container = { .container = &meta_fp, .x = 4 }; + + // Illegal: + //meta_fp = &f4; + container_container.container = &meta_fp2; + + (*container_container.container)(); +} + +int main(){ + func(); +} diff --git a/regression/goto-analyzer/fp-removal48/test.desc b/regression/goto-analyzer/fp-removal48/test.desc new file mode 100644 index 00000000000..0899addb26a --- /dev/null +++ b/regression/goto-analyzer/fp-removal48/test.desc @@ -0,0 +1,17 @@ +CORE +main.c +--show-goto-functions --verbosity 10 + +^Removing function pointers and virtual functions$ +^\s*IF \*container_container\.container == f1 THEN GOTO 1$ +^\s*IF \*container_container\.container == f2 THEN GOTO 2$ +^\s*IF \*container_container\.container == f3 THEN GOTO 3$ +^\s*IF \*container_container\.container == f4 THEN GOTO 4$ +^\s*IF \*container_container\.container == f5 THEN GOTO 5$ +^\s*IF \*container_container\.container == f6 THEN GOTO 6$ +^\s*IF \*container_container\.container == f7 THEN GOTO 7$ +^\s*IF \*container_container\.container == f8 THEN GOTO 8$ +^\s*IF \*container_container\.container == f9 THEN GOTO 9$ +^SIGNAL=0$ +-- +^warning: ignoring From 132801a6a853376d93218ee80f23bbba1dd0d221 Mon Sep 17 00:00:00 2001 From: thk123 Date: Wed, 8 Feb 2017 16:25:20 +0000 Subject: [PATCH 19/46] Squash constant symbols first We squash all the symbols we can before running the full squashing of everything to remove FPs. This allows for example, computation of array indicies that have operators inside them. As such, enabling the test. --- .../goto-analyzer/fp-removal35/test.desc | 2 +- .../remove_const_function_pointers.cpp | 59 ++++++++++++++++++- .../remove_const_function_pointers.h | 1 + 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/regression/goto-analyzer/fp-removal35/test.desc b/regression/goto-analyzer/fp-removal35/test.desc index 5b566c321ca..a402b60e080 100644 --- a/regression/goto-analyzer/fp-removal35/test.desc +++ b/regression/goto-analyzer/fp-removal35/test.desc @@ -1,4 +1,4 @@ -KNOWNBUG +CORE main.c --show-goto-functions ^Removing function pointers and virtual functions$ diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 1b6f0289510..72b1a62e575 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -26,7 +26,64 @@ remove_const_function_pointerst::remove_const_function_pointerst( bool remove_const_function_pointerst::operator()( functionst &out_functions) { - return try_resolve_function_call(original_expression, out_functions); + // Replace all const symbols with their values + exprt non_symbol_expression=replace_const_symbols(original_expression); + return try_resolve_function_call(non_symbol_expression, out_functions); +} + +/*******************************************************************\ + +Function: remove_const_function_pointerst::replace_const_symbols + + Inputs: + expression - The expression to resolve symbols in + + Outputs: Returns a modified version of the expression, with all + const symbols resolved to their actual values. + + Purpose: To collapse the symbols down to their values where possible + This takes a very general approach, recreating the expr tree + exactly as it was and ignoring what type of expressions are found + and instead recurses over all the operands. + +\*******************************************************************/ + +exprt remove_const_function_pointerst::replace_const_symbols( + const exprt &expression) const +{ + if(expression.id()==ID_symbol) + { + if(is_expression_const(expression)) + { + const symbolt &symbol= + symbol_table.lookup(expression.get(ID_identifier)); + if(symbol.type.id()!=ID_code) + { + const exprt &symbol_value=symbol.value; + return replace_const_symbols(symbol_value); + } + else + { + return expression; + } + } + else + { + return expression; + } + } + else + { + exprt const_symbol_cleared_expr=expression; + const_symbol_cleared_expr.operands().clear(); + for(const exprt &op : expression.operands()) + { + exprt const_symbol_cleared_op=replace_const_symbols(op); + const_symbol_cleared_expr.operands().push_back(const_symbol_cleared_op); + } + + return const_symbol_cleared_expr; + } } exprt remove_const_function_pointerst::resolve_symbol( diff --git a/src/goto-programs/remove_const_function_pointers.h b/src/goto-programs/remove_const_function_pointers.h index f641b0ce7ee..1d56eee552a 100644 --- a/src/goto-programs/remove_const_function_pointers.h +++ b/src/goto-programs/remove_const_function_pointers.h @@ -29,6 +29,7 @@ class remove_const_function_pointerst:public messaget bool operator()(functionst &out_functions); private: + exprt replace_const_symbols(const exprt &expression) const; exprt resolve_symbol(const symbol_exprt &symbol_expr) const; // recursive functions for dealing with the function pointer From 931b2393f2b863a5cc988d06e61d94c7459932f4 Mon Sep 17 00:00:00 2001 From: thk123 Date: Wed, 8 Feb 2017 16:42:51 +0000 Subject: [PATCH 20/46] Fixed major bug with non const structs I had misunderstood and thought that a non const struct with a const member couldn't have the value changed, so this was sufficent. However, as I demonstrate in all the failing tests (which I've fixed) you can also overwrite the entire struct. Instead, we now require when squashing member access, that the struct itself be const (we don't care whether the member is or not, since if it is and the struct isn't, it can be overwritten, and if it isn't and the struct is, its value cannot be changed). Also, all the tests that rely on this have been modified to require no pointer optimization. --- regression/goto-analyzer/fp-removal12/main.c | 8 ++-- regression/goto-analyzer/fp-removal26/main.c | 1 + .../goto-analyzer/fp-removal26/test.desc | 10 ++++- .../goto-analyzer/fp-removal28/test.desc | 10 ++++- regression/goto-analyzer/fp-removal32/main.c | 2 + .../goto-analyzer/fp-removal32/test.desc | 10 ++++- regression/goto-analyzer/fp-removal46/main.c | 4 ++ .../goto-analyzer/fp-removal46/test.desc | 10 ++++- .../remove_const_function_pointers.cpp | 41 +------------------ .../remove_const_function_pointers.h | 3 -- 10 files changed, 49 insertions(+), 50 deletions(-) diff --git a/regression/goto-analyzer/fp-removal12/main.c b/regression/goto-analyzer/fp-removal12/main.c index be398e7f255..06ccc492469 100644 --- a/regression/goto-analyzer/fp-removal12/main.c +++ b/regression/goto-analyzer/fp-removal12/main.c @@ -25,14 +25,14 @@ typedef struct fp_container void func(){ - fp_container container = { .fp_tbl = {f2 ,f3, f4} }; - fp_container container2 = { .fp_tbl = {f5 ,f6, f7} }; + const fp_container container = { .fp_tbl = {f2 ,f3, f4} }; + const fp_container container2 = { .fp_tbl = {f5 ,f6, f7} }; // Illegal: - // container = container2; + //container = container2; const void_fp fp = container.fp_tbl[1]; fp(); } -void main(){ +int main(){ func(); } diff --git a/regression/goto-analyzer/fp-removal26/main.c b/regression/goto-analyzer/fp-removal26/main.c index 66b03305547..e7b62bc8b81 100644 --- a/regression/goto-analyzer/fp-removal26/main.c +++ b/regression/goto-analyzer/fp-removal26/main.c @@ -29,6 +29,7 @@ void func(int i){ // Illegal //pts=&other_thing; // thing.go=&f6; + thing = other_thing; const void_fp fp = pts->go; fp(); diff --git a/regression/goto-analyzer/fp-removal26/test.desc b/regression/goto-analyzer/fp-removal26/test.desc index 656246683a5..889299e9a3c 100644 --- a/regression/goto-analyzer/fp-removal26/test.desc +++ b/regression/goto-analyzer/fp-removal26/test.desc @@ -3,7 +3,15 @@ main.c --show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ -^\s*f2();$ +^\s*IF fp == f1 THEN GOTO 1$ +^\s*IF fp == f2 THEN GOTO 2$ +^\s*IF fp == f3 THEN GOTO 3$ +^\s*IF fp == f4 THEN GOTO 4$ +^\s*IF fp == f5 THEN GOTO 5$ +^\s*IF fp == f6 THEN GOTO 6$ +^\s*IF fp == f7 THEN GOTO 7$ +^\s*IF fp == f8 THEN GOTO 8$ +^\s*IF fp == f9 THEN GOTO 9$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal28/test.desc b/regression/goto-analyzer/fp-removal28/test.desc index 656246683a5..889299e9a3c 100644 --- a/regression/goto-analyzer/fp-removal28/test.desc +++ b/regression/goto-analyzer/fp-removal28/test.desc @@ -3,7 +3,15 @@ main.c --show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ -^\s*f2();$ +^\s*IF fp == f1 THEN GOTO 1$ +^\s*IF fp == f2 THEN GOTO 2$ +^\s*IF fp == f3 THEN GOTO 3$ +^\s*IF fp == f4 THEN GOTO 4$ +^\s*IF fp == f5 THEN GOTO 5$ +^\s*IF fp == f6 THEN GOTO 6$ +^\s*IF fp == f7 THEN GOTO 7$ +^\s*IF fp == f8 THEN GOTO 8$ +^\s*IF fp == f9 THEN GOTO 9$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/fp-removal32/main.c b/regression/goto-analyzer/fp-removal32/main.c index 6076e1f12be..210facf60bf 100644 --- a/regression/goto-analyzer/fp-removal32/main.c +++ b/regression/goto-analyzer/fp-removal32/main.c @@ -18,6 +18,7 @@ struct state const void_fp go; }; struct state thing = {0, &f2}; +struct state other_thing = {0, &f4}; struct state const * const pts = &thing; @@ -26,6 +27,7 @@ struct state const * const pts = &thing; const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9}; void func(int i){ + thing = other_thing; pts->go(); } diff --git a/regression/goto-analyzer/fp-removal32/test.desc b/regression/goto-analyzer/fp-removal32/test.desc index 0c27e7670ac..f199330660a 100644 --- a/regression/goto-analyzer/fp-removal32/test.desc +++ b/regression/goto-analyzer/fp-removal32/test.desc @@ -3,7 +3,15 @@ main.c --show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ -^\s*f2();$ +^\s*IF pts->go == f1 THEN GOTO 1$ +^\s*IF pts->go == f2 THEN GOTO 2$ +^\s*IF pts->go == f3 THEN GOTO 3$ +^\s*IF pts->go == f4 THEN GOTO 4$ +^\s*IF pts->go == f5 THEN GOTO 5$ +^\s*IF pts->go == f6 THEN GOTO 6$ +^\s*IF pts->go == f7 THEN GOTO 7$ +^\s*IF pts->go == f8 THEN GOTO 8$ +^\s*IF pts->go == f9 THEN GOTO 9$ ^SIGNAL=0$ -- ^warning: ignoring \ No newline at end of file diff --git a/regression/goto-analyzer/fp-removal46/main.c b/regression/goto-analyzer/fp-removal46/main.c index 26770f0b1e7..c1f4811bad8 100644 --- a/regression/goto-analyzer/fp-removal46/main.c +++ b/regression/goto-analyzer/fp-removal46/main.c @@ -27,7 +27,11 @@ typedef struct fp_cc void func(){ const void_fp meta_fp = &f3; + const void_fp meta_fp2 = &f4; + + fp_cc container_container2 = { .container = &meta_fp2, .x = 4 }; fp_cc container_container = { .container = &meta_fp, .x = 4 }; + container_container = container_container2; // Illegal: //meta_fp = &f4; diff --git a/regression/goto-analyzer/fp-removal46/test.desc b/regression/goto-analyzer/fp-removal46/test.desc index 77c3b9a93d1..0899addb26a 100644 --- a/regression/goto-analyzer/fp-removal46/test.desc +++ b/regression/goto-analyzer/fp-removal46/test.desc @@ -3,7 +3,15 @@ main.c --show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ -^\s*f3();$ +^\s*IF \*container_container\.container == f1 THEN GOTO 1$ +^\s*IF \*container_container\.container == f2 THEN GOTO 2$ +^\s*IF \*container_container\.container == f3 THEN GOTO 3$ +^\s*IF \*container_container\.container == f4 THEN GOTO 4$ +^\s*IF \*container_container\.container == f5 THEN GOTO 5$ +^\s*IF \*container_container\.container == f6 THEN GOTO 6$ +^\s*IF \*container_container\.container == f7 THEN GOTO 7$ +^\s*IF \*container_container\.container == f8 THEN GOTO 8$ +^\s*IF \*container_container\.container == f9 THEN GOTO 9$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 72b1a62e575..6d87765a6a0 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -126,11 +126,7 @@ bool remove_const_function_pointerst::try_resolve_function_call( const exprt &component_value= get_component_value(struct_expr, member_expr); - const typet &component_type= - get_component_type(struct_expr, member_expr); - bool component_const=is_type_const(component_type); - - if(component_const || struct_is_const) + if(struct_is_const) { functionst component_functions; bool resolved= @@ -387,7 +383,6 @@ bool remove_const_function_pointerst::try_resolve_expression( if(resolved_struct) { - bool all_components_const=true; for(const exprt &potential_struct : potential_structs) { if(potential_struct.id()==ID_struct) @@ -395,10 +390,6 @@ bool remove_const_function_pointerst::try_resolve_expression( struct_exprt struct_expr=to_struct_expr(potential_struct); const exprt &component_value= get_component_value(struct_expr, member_expr); - const typet &component_type= - get_component_type(struct_expr, member_expr); - - all_components_const&=is_type_const(component_type); expressionst out_expressions; bool component_const=false; @@ -422,7 +413,7 @@ bool remove_const_function_pointerst::try_resolve_expression( return false; } } - out_is_const=all_components_const||is_struct_const; + out_is_const=is_struct_const; return true; } else @@ -705,31 +696,3 @@ exprt remove_const_function_pointerst::get_component_value( return struct_expr.operands()[component_number]; } - -/*******************************************************************\ - -Function: remove_const_function_pointerst::get_component_type - - Inputs: - struct_expr - The expression of the structure being accessed - member_expr - The expression saying which component is being accessed - - Outputs: Returns the type of the component. Note this may be differenent to - the type of its value (e.g. it may be a const pointer but its value - could just be a pointer). - - Purpose: To extract the type of the specific component within a struct - -\*******************************************************************/ - -typet remove_const_function_pointerst::get_component_type( - const struct_exprt &struct_expr, const member_exprt &member_expr) -{ - const struct_typet &struct_type=to_struct_type(ns.follow(struct_expr.type())); - size_t component_number= - struct_type.component_number(member_expr.get_component_name()); - struct_union_typet::componentt component= - struct_type.components()[component_number]; - - return component.type(); -} diff --git a/src/goto-programs/remove_const_function_pointers.h b/src/goto-programs/remove_const_function_pointers.h index 1d56eee552a..e8600b9c3be 100644 --- a/src/goto-programs/remove_const_function_pointers.h +++ b/src/goto-programs/remove_const_function_pointers.h @@ -58,9 +58,6 @@ class remove_const_function_pointerst:public messaget exprt get_component_value( const struct_exprt &struct_expr, const member_exprt &member_expr); - typet get_component_type( - const struct_exprt &struct_expr, const member_exprt &member_expr); - const exprt original_expression; const namespacet &ns; const symbol_tablet &symbol_table; From 2e941258fe438458986ce4857d8b3b709eddb8df Mon Sep 17 00:00:00 2001 From: thk123 Date: Wed, 8 Feb 2017 16:49:16 +0000 Subject: [PATCH 21/46] Removing redundant code Since we now require all symbols to be const (the only exception before was structs with const components, but that is not sufficent), the preliminary sweep for symbols is sufficent to catch all valid ones. --- .../remove_const_function_pointers.cpp | 25 ++----------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 6d87765a6a0..b48c1d5de5a 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -240,16 +240,7 @@ bool remove_const_function_pointerst::try_resolve_function_call( } else { - const c_qualifierst pointer_qualifers(simplified_expr.type()); - if(!pointer_qualifers.is_constant) - { - debug() << "Can't optimize FP since symbol " - << simplified_expr.get(ID_identifier) << " is not const" << eom; - return false; - } - - const exprt &symbol_value=resolve_symbol(to_symbol_expr(simplified_expr)); - return try_resolve_function_call(symbol_value, out_functions); + return false; } } else @@ -497,19 +488,7 @@ bool remove_const_function_pointerst::try_resolve_expression( } else if(simplified_expr.id()==ID_symbol) { - const exprt &symbol_value=resolve_symbol(to_symbol_expr(simplified_expr)); - bool is_symbol_const=is_expression_const(simplified_expr); - bool is_symbol_value_const=false; - bool resolved_expression= - try_resolve_expression( - symbol_value, - out_resolved_expression, - is_symbol_value_const); - - // If we have a symbol, it is only const if the value it is assigned - // is const and it is in fact const. - out_is_const=is_symbol_const; - return resolved_expression; + return false; } // TOOD: probably need to do something with pointers or address_of // and const since a const pointer to a non-const value is useless From 63afb800eff369b346decd6bb16a63254a1de1c8 Mon Sep 17 00:00:00 2001 From: thk123 Date: Wed, 8 Feb 2017 17:44:29 +0000 Subject: [PATCH 22/46] Added logging for all the ways the FP removal might not complete --- .../remove_const_function_pointers.cpp | 72 ++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index b48c1d5de5a..6b7eda28a0e 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -12,6 +12,10 @@ Author: Thomas Kiley, thomas.kiley@diffblue.com #include "remove_const_function_pointers.h" +#define LOG(message, irep) \ + debug() << "Case " << __LINE__ << " : " << message << "\n" \ + << irep.pretty() << eom; + remove_const_function_pointerst::remove_const_function_pointerst( message_handlert &message_handler, const exprt &base_expression, @@ -118,6 +122,7 @@ bool remove_const_function_pointerst::try_resolve_function_call( { if(expression.id()!=ID_struct) { + LOG("Squash of member access didn't result in a struct", expression); return false; } else @@ -138,11 +143,17 @@ bool remove_const_function_pointerst::try_resolve_function_call( } else { + LOG( + "Couldn't resolve functions call from component value", + component_value); return false; } } else { + LOG( + "Struct was not const so can't resolve values on it", + struct_expr); return false; } } @@ -153,13 +164,20 @@ bool remove_const_function_pointerst::try_resolve_function_call( } else { + LOG("Failed to squash struct member access", owner_expr); return false; } } else if(simplified_expr.id()==ID_address_of) { address_of_exprt address_expr=to_address_of_expr(simplified_expr); - return try_resolve_function_call(address_expr.object(), out_functions); + bool resolved= + try_resolve_function_call(address_expr.object(), out_functions); + if(!resolved) + { + LOG("Failed to resolve address of", address_expr); + } + return resolved; } else if(simplified_expr.id()==ID_dereference) { @@ -195,11 +213,15 @@ bool remove_const_function_pointerst::try_resolve_function_call( } else { + LOG("Failed to resolver pointers value", address_expr); return false; } } else { + LOG( + "Squashing dereference did not result in an address of", + pointer_val); return false; } } @@ -207,6 +229,14 @@ bool remove_const_function_pointerst::try_resolve_function_call( } else { + if(!resolved) + { + LOG("Failed to squash dereference", deref); + } + else if(!pointer_const) + { + LOG("Dereferenced value was not const so can't dereference", deref); + } return false; } } @@ -228,6 +258,7 @@ bool remove_const_function_pointerst::try_resolve_function_call( } else { + LOG("Failed to squash typecast", simplified_expr); return false; } } @@ -240,11 +271,13 @@ bool remove_const_function_pointerst::try_resolve_function_call( } else { + LOG("Non const symbol wasn't squashed", simplified_expr); return false; } } else { + LOG("Unrecognised expression", simplified_expr); return false; } } @@ -293,6 +326,7 @@ bool remove_const_function_pointerst::try_resolve_index_of_function_call( } else { + LOG("Could not resolve expression in array", func_expr); return false; } } @@ -317,6 +351,7 @@ bool remove_const_function_pointerst::try_resolve_index_of_function_call( } else { + LOG("Could not resolve expression in array", array_entry); return false; } } @@ -324,11 +359,13 @@ bool remove_const_function_pointerst::try_resolve_index_of_function_call( } else { + LOG("Array and its contents are not const", potential_array_expr); return false; } } else { + LOG("Squashing index did not result in an array", potential_array_expr); return false; } } @@ -337,6 +374,7 @@ bool remove_const_function_pointerst::try_resolve_index_of_function_call( } else { + LOG("Could not resolve arary", index_expr); return false; } } @@ -351,6 +389,7 @@ bool remove_const_function_pointerst::try_resolve_expression( expressionst out_array_expressions; bool resolved_array= try_resolve_index_of(index_expr, out_array_expressions, out_is_const); + if(resolved_array) { out_resolved_expression.insert( @@ -358,6 +397,10 @@ bool remove_const_function_pointerst::try_resolve_expression( out_array_expressions.begin(), out_array_expressions.end()); } + else + { + LOG("Could not resolve array", index_expr); + } return resolved_array; } @@ -396,11 +439,15 @@ bool remove_const_function_pointerst::try_resolve_expression( } else { + LOG("Could not resolve component value", component_value); return false; } } else { + LOG( + "Squashing member access did not resolve in a struct", + potential_struct); return false; } } @@ -409,6 +456,7 @@ bool remove_const_function_pointerst::try_resolve_expression( } else { + LOG("Failed to squash struct access", member_expr); return false; } } @@ -445,9 +493,15 @@ bool remove_const_function_pointerst::try_resolve_expression( all_objects_const&=object_const; } + else + { + LOG("Failed to resolve value of a dereference", address_expr); + } } else { + LOG( + "Squashing dereference did not result in an address", pointer_val); return false; } } @@ -456,6 +510,14 @@ bool remove_const_function_pointerst::try_resolve_expression( } else { + if(!resolved) + { + LOG("Failed to resolve pointer of dereference", deref); + } + else if(!pointer_const) + { + LOG("Pointer value not const so can't squash", deref); + } return false; } } @@ -483,11 +545,13 @@ bool remove_const_function_pointerst::try_resolve_expression( } else { + LOG("Could not resolve typecast value", typecast_expr); return false; } } else if(simplified_expr.id()==ID_symbol) { + LOG("Non const symbol will not be squashed", simplified_expr); return false; } // TOOD: probably need to do something with pointers or address_of @@ -580,6 +644,7 @@ bool remove_const_function_pointerst::try_resolve_index_of( } else { + LOG("Failed to resolve array value", func_expr); return false; } } @@ -611,6 +676,7 @@ bool remove_const_function_pointerst::try_resolve_index_of( } else { + LOG("Failed to resolve array value", array_entry); return false; } } @@ -618,6 +684,9 @@ bool remove_const_function_pointerst::try_resolve_index_of( } else { + LOG( + "Squashing index of did not result in an array", + potential_array_expr); return false; } } @@ -627,6 +696,7 @@ bool remove_const_function_pointerst::try_resolve_index_of( } else { + LOG("Failed to squash index of to array expression", index_expr); return false; } } From 9da5ba2f34687e9cbe0b76ed2dc44f1c9aa36ccf Mon Sep 17 00:00:00 2001 From: thk123 Date: Thu, 9 Feb 2017 11:26:19 +0000 Subject: [PATCH 23/46] Adding consistency checks for the output If the output of removing the FPs is true, then we expect at least one function to replace the call with. If it is false, then we don't expect any functions. If these fail, it probably indicates a bug in the remove_const_function_pointerst class. --- src/goto-programs/remove_function_pointers.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/goto-programs/remove_function_pointers.cpp b/src/goto-programs/remove_function_pointers.cpp index 1e63b25a9a6..4c505cdc191 100644 --- a/src/goto-programs/remove_function_pointers.cpp +++ b/src/goto-programs/remove_function_pointers.cpp @@ -350,6 +350,14 @@ void remove_function_pointerst::remove_function_pointer( bool found_functions=fpr(functions); + // Consistency checks + // Reported optimized function pointer call, but didn't find any functions + assert(!found_functions || !functions.empty()); + + // Reported didn't optimize function pointer call, but did find some + // functions to replace with + assert(found_functions || functions.empty()); + if(functions.size()==1) { to_code_function_call(target->code).function()=*functions.cbegin(); @@ -358,12 +366,6 @@ void remove_function_pointerst::remove_function_pointer( if(!found_functions) { - debug() << "Failed to optimize away the function pointer\n" - << "The type was " << pointer.id() << " " - << "irep dump:\n" - << pointer.pretty() - << eom; - bool return_value_used=code.lhs().is_not_nil(); // get all type-compatible functions From d81f6cba3a2dd469992e321c9f1a8a8d662a64de Mon Sep 17 00:00:00 2001 From: thk123 Date: Thu, 9 Feb 2017 12:14:07 +0000 Subject: [PATCH 24/46] Adding comments to remove_const_function_pointers --- .../remove_const_function_pointers.cpp | 191 +++++++++++++++++- 1 file changed, 186 insertions(+), 5 deletions(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 6b7eda28a0e..3e04103c964 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -16,6 +16,23 @@ Author: Thomas Kiley, thomas.kiley@diffblue.com debug() << "Case " << __LINE__ << " : " << message << "\n" \ << irep.pretty() << eom; +/*******************************************************************\ + +Function: remove_const_function_pointerst::remove_const_function_pointerst + + Inputs: + message_handler - The message handler for messaget + base_expression - The function call through a function pointer + ns - The namespace to use to resolve types + symbol_table - The symbol table to look up symbols in + + Outputs: + + Purpose: To take a function call on a function pointer, and if possible + resolve it to a small collection of possible values. + +\*******************************************************************/ + remove_const_function_pointerst::remove_const_function_pointerst( message_handlert &message_handler, const exprt &base_expression, @@ -27,6 +44,28 @@ remove_const_function_pointerst::remove_const_function_pointerst( symbol_table(symbol_table) {} +/*******************************************************************\ + +Function: remove_const_function_pointerst::operator() + + Inputs: + out_functions - The functions that (symbols of type ID_code) the base + expression could take. + + Outputs: Returns true if it was able to resolve the call, false if not. + If it returns true, out_functions will be populated by all the + possible values the function pointer could be. + + Purpose: To take a function call on a function pointer, and if possible + resolve it to a small collection of possible values. It will + resolve function pointers that are const and: + - assigned directly to a function + - assigned to a value in an array of functions + - assigned to a const struct component + Or variations within. + +\*******************************************************************/ + bool remove_const_function_pointerst::operator()( functionst &out_functions) { @@ -90,6 +129,19 @@ exprt remove_const_function_pointerst::replace_const_symbols( } } +/*******************************************************************\ + +Function: remove_const_function_pointerst::resolve_symbol + + Inputs: + symbol_expr - The symbol expression + + Outputs: The expression value of the symbol. + + Purpose: Look up a symbol in the symbol table and return its value + +\*******************************************************************/ + exprt remove_const_function_pointerst::resolve_symbol( const symbol_exprt &symbol_expr) const { @@ -98,6 +150,25 @@ exprt remove_const_function_pointerst::resolve_symbol( return symbol.value; } +/*******************************************************************\ + +Function: remove_const_function_pointerst::try_resolve_function_call + + Inputs: + expr - The expression to get the possible function calls + out_functions - The functions this expression could be resolved to + + Outputs: Returns true if it was able to resolve the expression to some + specific functions. If this is the case, out_functions will contain + the possible functions. + + Purpose: To resolve an expression to the specific function calls it can + be. This is different to try_resolve_expression which isn't + explicitly looking for functions and is instead just trying + to squash particular exprt structures. + +\*******************************************************************/ + bool remove_const_function_pointerst::try_resolve_function_call( const exprt &expr, remove_const_function_pointerst::functionst &out_functions) { @@ -282,9 +353,27 @@ bool remove_const_function_pointerst::try_resolve_function_call( } } -// Take an index of, squash its array and squash its index -// If we can get a precise number, try_resolve_function_call on its value -// otherwise try_resolve_function_call on each and return the union of them all +/*******************************************************************\ + +Function: remove_const_function_pointerst::try_resolve_index_of_function_call + + Inputs: + index_expr - The index expression to resolve to possible function calls + out_functions - The functions this expression could be + + Outputs: Returns true if it was able to resolve the index expression to some + specific functions. If this is the case, out_functions will contain + the possible functions. + + Purpose: To resolve an expression to the specific function calls it can + be. Specifically, this function deals with index expressions + where it squashes its array and squash its index + If we can get a precise number for the index, we + try_resolve_function_call on its value otherwise + try_resolve_function_call on each and return the union of them all + +\*******************************************************************/ + bool remove_const_function_pointerst::try_resolve_index_of_function_call( const index_exprt &index_expr, functionst &out_functions) { @@ -379,6 +468,33 @@ bool remove_const_function_pointerst::try_resolve_index_of_function_call( } } +/*******************************************************************\ + +Function: remove_const_function_pointerst::try_resolve_expression + + Inputs: + expr - The expression to try and squash + out_resolved_expression - The squashed version of this expression + out_is_const - Is the squashed expression constant + + Outputs: Returns true providing the squashing went OK (note it + may not have squashed anything). The out_resolved_expression will in + this case be all the possible squashed versions of the supplied + expression. + The out_is_const will return whether the squashed value is suitably + const (e.g. if we squashed a struct access, was the struct const). + + Purpose: To squash various expr types to simplify the expression. + ID_index -> dig to find ID_array and get the values out of it + ID_member -> dig to find ID_struct and extract the component value + ID_dereference -> dig to find ID_address_of and extract the value + ID_typecast -> return the value + ID_symbol -> return false, const symbols are squashed first and + non const symbols cannot be squashed + Everything else -> unchanged + +\*******************************************************************/ + bool remove_const_function_pointerst::try_resolve_expression( const exprt &expr, expressionst &out_resolved_expression, bool &out_is_const) { @@ -564,6 +680,25 @@ bool remove_const_function_pointerst::try_resolve_expression( } } +/*******************************************************************\ + +Function: remove_const_function_pointerst::try_resolve_index_value + + Inputs: + expr - The expression of the index of the index expression (e.g. + index_exprt::index()) + out_array_index - The constant value the index takes + + Outputs: Returns true if was able to find a constant value for the index + expression. If true, then out_array_index will be the index within + the array that the function pointer is pointing to. + + Purpose: Given an index into an array, resolve, if possible, the index + that is being accessed. This deals with symbols and typecasts to + constant values. + +\*******************************************************************/ + bool remove_const_function_pointerst::try_resolve_index_value( const exprt &expr, mp_integer &out_array_index) { @@ -596,9 +731,28 @@ bool remove_const_function_pointerst::try_resolve_index_value( } } +/*******************************************************************\ + +Function: remove_const_function_pointerst::try_resolve_index_of + + Inputs: + index_expr - The index expression to to resolve to possible function calls + out_expressions - The functions this expression could be + out_is_const - Is the squashed expression constant + + Outputs: Returns true if it was able to squash the index expression + If this is the case, out_expressions will contain + the possible values this index_of could return + The out_is_const will return whether either the array itself + is const, or the values of the array are const. + + Purpose: To squash an index access by first finding the array it is accessing + Then if the index can be resolved, return the squashed value. If + the index can't be determined then squash each value in the array + and return them all. + +\*******************************************************************/ -// Takes an index of, squashes its array and index -// if index is resolvable bool remove_const_function_pointerst::try_resolve_index_of( const index_exprt &index_expr, expressionst &out_expressions, @@ -701,12 +855,39 @@ bool remove_const_function_pointerst::try_resolve_index_of( } } +/*******************************************************************\ + +Function: remove_const_function_pointerst::is_expression_const + + Inputs: + expression - The expression to check + + Outputs: Returns true if the type of the expression is constant. + + Purpose: To evaluate the const-ness of the expression type. + +\*******************************************************************/ + bool remove_const_function_pointerst::is_expression_const( const exprt &expression) const { return is_type_const(expression.type()); } +/*******************************************************************\ + +Function: remove_const_function_pointerst::is_type_const + + Inputs: + type - The type to check + + Outputs: Returns true if the type has ID_C_constant or is an array + since arrays are implicitly const in C. + + Purpose: To evaluate the const-ness of the type. + +\*******************************************************************/ + bool remove_const_function_pointerst::is_type_const(const typet &type) const { c_qualifierst qualifers(type); From 3e669c0231075a5c39abd217c4afd978bc6f9fde Mon Sep 17 00:00:00 2001 From: thk123 Date: Thu, 9 Feb 2017 15:13:04 +0000 Subject: [PATCH 25/46] Renamed all the tests Gave all the regression tests sensible names so relevant cases can be found and missing cases identified. --- .../{fp-removal34 => approx-array-variable-const-fp}/main.c | 0 .../{fp-removal34 => approx-array-variable-const-fp}/test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 2 +- .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../{fp-removal15 => no-match-non-const-fp}/main.c | 0 .../{fp-removal7 => no-match-non-const-fp}/test.desc | 2 +- .../{fp-removal40 => no-match-parameter-const-fp}/main.c | 0 .../{fp-removal40 => no-match-parameter-const-fp}/test.desc | 0 .../goto-analyzer/{fp-removal7 => no-match-parameter-fp}/main.c | 0 .../{fp-removal41 => no-match-parameter-fp}/test.desc | 0 .../main.c | 0 .../test.desc | 0 .../{fp-removal35 => precise-array-calculation-const-fp}/main.c | 0 .../test.desc | 0 .../{fp-removal33 => precise-array-literal-const-fp}/main.c | 0 .../{fp-removal3 => precise-array-literal-const-fp}/test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 1 + .../test.desc | 0 .../{fp-removal2 => precise-const-fp-const-fp}/main.c | 0 .../{fp-removal2 => precise-const-fp-const-fp}/test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../goto-analyzer/{fp-removal1 => precise-const-fp}/main.c | 0 .../goto-analyzer/{fp-removal1 => precise-const-fp}/test.desc | 0 .../{fp-removal30 => precise-const-struct-non-const-fp}/main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../goto-analyzer/{fp-removal17 => precise-derefence}/main.c | 0 .../goto-analyzer/{fp-removal17 => precise-derefence}/test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 .../main.c | 0 .../test.desc | 0 92 files changed, 3 insertions(+), 2 deletions(-) rename regression/goto-analyzer/{fp-removal34 => approx-array-variable-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal34 => approx-array-variable-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal19 => approx-const-fp-array-variable-cast-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal19 => approx-const-fp-array-variable-cast-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal22 => approx-const-fp-array-variable-const-fp-with-null}/main.c (100%) rename regression/goto-analyzer/{fp-removal22 => approx-const-fp-array-variable-const-fp-with-null}/test.desc (100%) rename regression/goto-analyzer/{fp-removal5 => approx-const-fp-array-variable-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal5 => approx-const-fp-array-variable-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal24 => approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp1}/main.c (100%) rename regression/goto-analyzer/{fp-removal23 => approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp1}/test.desc (100%) rename regression/goto-analyzer/{fp-removal25 => approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp2}/main.c (100%) rename regression/goto-analyzer/{fp-removal25 => approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp2}/test.desc (100%) rename regression/goto-analyzer/{fp-removal21 => approx-const-fp-array-variable-const-struct-non-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal21 => approx-const-fp-array-variable-const-struct-non-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal20 => approx-const-fp-array-variable-invalid-cast-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal20 => approx-const-fp-array-variable-invalid-cast-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal41 => no-match-const-fp-array-literal-const-fp-run-time}/main.c (100%) rename regression/goto-analyzer/{fp-removal11 => no-match-const-fp-array-literal-const-fp-run-time}/test.desc (100%) rename regression/goto-analyzer/{fp-removal6 => no-match-const-fp-array-literal-non-const-fp-run-time}/main.c (100%) rename regression/goto-analyzer/{fp-removal15 => no-match-const-fp-array-literal-non-const-fp-run-time}/test.desc (100%) rename regression/goto-analyzer/{fp-removal8 => no-match-const-fp-array-literal-non-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal10 => no-match-const-fp-array-literal-non-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal10 => no-match-const-fp-array-non-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal8 => no-match-const-fp-array-non-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal26 => no-match-const-fp-const-pointer-non-const-struct-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal26 => no-match-const-fp-const-pointer-non-const-struct-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal39 => no-match-const-fp-dereference-non-const-pointer-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal39 => no-match-const-fp-dereference-non-const-pointer-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal11 => no-match-const-fp-dynamic-array-non-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal29 => no-match-const-fp-dynamic-array-non-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal27 => no-match-const-fp-non-const-fp-direct-assignment}/main.c (100%) rename regression/goto-analyzer/{fp-removal16 => no-match-const-fp-non-const-fp-direct-assignment}/test.desc (100%) rename regression/goto-analyzer/{fp-removal36 => no-match-const-fp-non-const-pointer-non-const-struct-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal36 => no-match-const-fp-non-const-pointer-non-const-struct-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal28 => no-match-const-fp-non-const-struct-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal28 => no-match-const-fp-non-const-struct-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal29 => no-match-const-fp-non-const-struct-non-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal6 => no-match-const-fp-non-const-struct-non-const-fp}/test.desc (90%) rename regression/goto-analyzer/{fp-removal32 => no-match-const-pointer-non-const-struct-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal32 => no-match-const-pointer-non-const-struct-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal43 => no-match-dereference-const-pointer-const-array-literal-pointer-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal43 => no-match-dereference-const-pointer-const-array-literal-pointer-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal46 => no-match-dereference-non-const-struct-const-pointer-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal46 => no-match-dereference-non-const-struct-const-pointer-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal48 => no-match-dereference-non-const-struct-non-const-pointer-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal48 => no-match-dereference-non-const-struct-non-const-pointer-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal16 => no-match-non-const-fp-const-fp-direct-assignment}/main.c (100%) rename regression/goto-analyzer/{fp-removal27 => no-match-non-const-fp-const-fp-direct-assignment}/test.desc (100%) rename regression/goto-analyzer/{fp-removal15 => no-match-non-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal7 => no-match-non-const-fp}/test.desc (90%) rename regression/goto-analyzer/{fp-removal40 => no-match-parameter-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal40 => no-match-parameter-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal7 => no-match-parameter-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal41 => no-match-parameter-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal42 => no-match-pointer-const-struct-array-literal-non-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal42 => no-match-pointer-const-struct-array-literal-non-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal35 => precise-array-calculation-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal35 => precise-array-calculation-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal33 => precise-array-literal-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal3 => precise-array-literal-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal4 => precise-const-fp-array-const-variable-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal33 => precise-const-fp-array-const-variable-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal3 => precise-const-fp-array-literal-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal4 => precise-const-fp-array-literal-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal37 => precise-const-fp-array-literal-const-struct-non-const-fp}/main.c (96%) rename regression/goto-analyzer/{fp-removal37 => precise-const-fp-array-literal-const-struct-non-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal2 => precise-const-fp-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal2 => precise-const-fp-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal12 => precise-const-fp-const-struct-const-array-literal-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal12 => precise-const-fp-const-struct-const-array-literal-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal13 => precise-const-fp-const-struct-non-const-array-literal-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal13 => precise-const-fp-const-struct-non-const-array-literal-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal23 => precise-const-fp-const-struct-non-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal24 => precise-const-fp-const-struct-non-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal38 => precise-const-fp-dereference-const-pointer-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal14 => precise-const-fp-dereference-const-pointer-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal1 => precise-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal1 => precise-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal30 => precise-const-struct-non-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal30 => precise-const-struct-non-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal14 => precise-derefence-const-pointer-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal31 => precise-derefence-const-pointer-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal17 => precise-derefence}/main.c (100%) rename regression/goto-analyzer/{fp-removal17 => precise-derefence}/test.desc (100%) rename regression/goto-analyzer/{fp-removal31 => precise-dereference-address-pointer-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal38 => precise-dereference-address-pointer-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal44 => precise-dereference-const-struct-const-pointer-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal44 => precise-dereference-const-struct-const-pointer-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal47 => precise-dereference-const-struct-const-pointer-const-struct-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal45 => precise-dereference-const-struct-const-pointer-const-struct-const-fp}/test.desc (100%) rename regression/goto-analyzer/{fp-removal45 => precise-dereference-const-struct-pointer-const-fp}/main.c (100%) rename regression/goto-analyzer/{fp-removal47 => precise-dereference-const-struct-pointer-const-fp}/test.desc (100%) diff --git a/regression/goto-analyzer/fp-removal34/main.c b/regression/goto-analyzer/approx-array-variable-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal34/main.c rename to regression/goto-analyzer/approx-array-variable-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal34/test.desc b/regression/goto-analyzer/approx-array-variable-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal34/test.desc rename to regression/goto-analyzer/approx-array-variable-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal19/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal19/main.c rename to regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal19/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal19/test.desc rename to regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal22/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal22/main.c rename to regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/main.c diff --git a/regression/goto-analyzer/fp-removal22/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal22/test.desc rename to regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc diff --git a/regression/goto-analyzer/fp-removal5/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal5/main.c rename to regression/goto-analyzer/approx-const-fp-array-variable-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal5/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal5/test.desc rename to regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal24/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp1/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal24/main.c rename to regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp1/main.c diff --git a/regression/goto-analyzer/fp-removal23/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp1/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal23/test.desc rename to regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp1/test.desc diff --git a/regression/goto-analyzer/fp-removal25/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp2/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal25/main.c rename to regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp2/main.c diff --git a/regression/goto-analyzer/fp-removal25/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp2/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal25/test.desc rename to regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp2/test.desc diff --git a/regression/goto-analyzer/fp-removal21/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal21/main.c rename to regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal21/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal21/test.desc rename to regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal20/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal20/main.c rename to regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal20/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal20/test.desc rename to regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal41/main.c b/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal41/main.c rename to regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/main.c diff --git a/regression/goto-analyzer/fp-removal11/test.desc b/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal11/test.desc rename to regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/test.desc diff --git a/regression/goto-analyzer/fp-removal6/main.c b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal6/main.c rename to regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/main.c diff --git a/regression/goto-analyzer/fp-removal15/test.desc b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal15/test.desc rename to regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/test.desc diff --git a/regression/goto-analyzer/fp-removal8/main.c b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal8/main.c rename to regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal10/test.desc b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal10/test.desc rename to regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal10/main.c b/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal10/main.c rename to regression/goto-analyzer/no-match-const-fp-array-non-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal8/test.desc b/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal8/test.desc rename to regression/goto-analyzer/no-match-const-fp-array-non-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal26/main.c b/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal26/main.c rename to regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal26/test.desc b/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal26/test.desc rename to regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal39/main.c b/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal39/main.c rename to regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal39/test.desc b/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal39/test.desc rename to regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal11/main.c b/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal11/main.c rename to regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal29/test.desc b/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal29/test.desc rename to regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal27/main.c b/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal27/main.c rename to regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/main.c diff --git a/regression/goto-analyzer/fp-removal16/test.desc b/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal16/test.desc rename to regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/test.desc diff --git a/regression/goto-analyzer/fp-removal36/main.c b/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal36/main.c rename to regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal36/test.desc b/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal36/test.desc rename to regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal28/main.c b/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal28/main.c rename to regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal28/test.desc b/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal28/test.desc rename to regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal29/main.c b/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal29/main.c rename to regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal6/test.desc b/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/test.desc similarity index 90% rename from regression/goto-analyzer/fp-removal6/test.desc rename to regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/test.desc index 3c735d48a55..deda28d213f 100644 --- a/regression/goto-analyzer/fp-removal6/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*IF fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/fp-removal32/main.c b/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal32/main.c rename to regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal32/test.desc b/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal32/test.desc rename to regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal43/main.c b/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal43/main.c rename to regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal43/test.desc b/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal43/test.desc rename to regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal46/main.c b/regression/goto-analyzer/no-match-dereference-non-const-struct-const-pointer-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal46/main.c rename to regression/goto-analyzer/no-match-dereference-non-const-struct-const-pointer-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal46/test.desc b/regression/goto-analyzer/no-match-dereference-non-const-struct-const-pointer-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal46/test.desc rename to regression/goto-analyzer/no-match-dereference-non-const-struct-const-pointer-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal48/main.c b/regression/goto-analyzer/no-match-dereference-non-const-struct-non-const-pointer-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal48/main.c rename to regression/goto-analyzer/no-match-dereference-non-const-struct-non-const-pointer-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal48/test.desc b/regression/goto-analyzer/no-match-dereference-non-const-struct-non-const-pointer-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal48/test.desc rename to regression/goto-analyzer/no-match-dereference-non-const-struct-non-const-pointer-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal16/main.c b/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal16/main.c rename to regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/main.c diff --git a/regression/goto-analyzer/fp-removal27/test.desc b/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal27/test.desc rename to regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/test.desc diff --git a/regression/goto-analyzer/fp-removal15/main.c b/regression/goto-analyzer/no-match-non-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal15/main.c rename to regression/goto-analyzer/no-match-non-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal7/test.desc b/regression/goto-analyzer/no-match-non-const-fp/test.desc similarity index 90% rename from regression/goto-analyzer/fp-removal7/test.desc rename to regression/goto-analyzer/no-match-non-const-fp/test.desc index 3c735d48a55..deda28d213f 100644 --- a/regression/goto-analyzer/fp-removal7/test.desc +++ b/regression/goto-analyzer/no-match-non-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*IF fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/fp-removal40/main.c b/regression/goto-analyzer/no-match-parameter-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal40/main.c rename to regression/goto-analyzer/no-match-parameter-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal40/test.desc b/regression/goto-analyzer/no-match-parameter-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal40/test.desc rename to regression/goto-analyzer/no-match-parameter-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal7/main.c b/regression/goto-analyzer/no-match-parameter-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal7/main.c rename to regression/goto-analyzer/no-match-parameter-fp/main.c diff --git a/regression/goto-analyzer/fp-removal41/test.desc b/regression/goto-analyzer/no-match-parameter-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal41/test.desc rename to regression/goto-analyzer/no-match-parameter-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal42/main.c b/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal42/main.c rename to regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal42/test.desc b/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal42/test.desc rename to regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal35/main.c b/regression/goto-analyzer/precise-array-calculation-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal35/main.c rename to regression/goto-analyzer/precise-array-calculation-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal35/test.desc b/regression/goto-analyzer/precise-array-calculation-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal35/test.desc rename to regression/goto-analyzer/precise-array-calculation-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal33/main.c b/regression/goto-analyzer/precise-array-literal-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal33/main.c rename to regression/goto-analyzer/precise-array-literal-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal3/test.desc b/regression/goto-analyzer/precise-array-literal-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal3/test.desc rename to regression/goto-analyzer/precise-array-literal-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal4/main.c b/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal4/main.c rename to regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal33/test.desc b/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal33/test.desc rename to regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal3/main.c b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal3/main.c rename to regression/goto-analyzer/precise-const-fp-array-literal-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal4/test.desc b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal4/test.desc rename to regression/goto-analyzer/precise-const-fp-array-literal-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal37/main.c b/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/main.c similarity index 96% rename from regression/goto-analyzer/fp-removal37/main.c rename to regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/main.c index 7e50789f2ad..0c8c7e86046 100644 --- a/regression/goto-analyzer/fp-removal37/main.c +++ b/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/main.c @@ -35,6 +35,7 @@ void func(int i){ // Illegal // stable_table[1] = another_table; + // stable_table[1].fp = f5; fp(); } diff --git a/regression/goto-analyzer/fp-removal37/test.desc b/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal37/test.desc rename to regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal2/main.c b/regression/goto-analyzer/precise-const-fp-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal2/main.c rename to regression/goto-analyzer/precise-const-fp-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal2/test.desc b/regression/goto-analyzer/precise-const-fp-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal2/test.desc rename to regression/goto-analyzer/precise-const-fp-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal12/main.c b/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal12/main.c rename to regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/main.c diff --git a/regression/goto-analyzer/fp-removal12/test.desc b/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal12/test.desc rename to regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal13/main.c b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal13/main.c rename to regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/main.c diff --git a/regression/goto-analyzer/fp-removal13/test.desc b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal13/test.desc rename to regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal23/main.c b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal23/main.c rename to regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal24/test.desc b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal24/test.desc rename to regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal38/main.c b/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal38/main.c rename to regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal14/test.desc b/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal14/test.desc rename to regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal1/main.c b/regression/goto-analyzer/precise-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal1/main.c rename to regression/goto-analyzer/precise-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal1/test.desc b/regression/goto-analyzer/precise-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal1/test.desc rename to regression/goto-analyzer/precise-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal30/main.c b/regression/goto-analyzer/precise-const-struct-non-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal30/main.c rename to regression/goto-analyzer/precise-const-struct-non-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal30/test.desc b/regression/goto-analyzer/precise-const-struct-non-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal30/test.desc rename to regression/goto-analyzer/precise-const-struct-non-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal14/main.c b/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal14/main.c rename to regression/goto-analyzer/precise-derefence-const-pointer-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal31/test.desc b/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal31/test.desc rename to regression/goto-analyzer/precise-derefence-const-pointer-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal17/main.c b/regression/goto-analyzer/precise-derefence/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal17/main.c rename to regression/goto-analyzer/precise-derefence/main.c diff --git a/regression/goto-analyzer/fp-removal17/test.desc b/regression/goto-analyzer/precise-derefence/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal17/test.desc rename to regression/goto-analyzer/precise-derefence/test.desc diff --git a/regression/goto-analyzer/fp-removal31/main.c b/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal31/main.c rename to regression/goto-analyzer/precise-dereference-address-pointer-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal38/test.desc b/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal38/test.desc rename to regression/goto-analyzer/precise-dereference-address-pointer-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal44/main.c b/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal44/main.c rename to regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal44/test.desc b/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal44/test.desc rename to regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal47/main.c b/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-struct-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal47/main.c rename to regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-struct-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal45/test.desc b/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-struct-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal45/test.desc rename to regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-struct-const-fp/test.desc diff --git a/regression/goto-analyzer/fp-removal45/main.c b/regression/goto-analyzer/precise-dereference-const-struct-pointer-const-fp/main.c similarity index 100% rename from regression/goto-analyzer/fp-removal45/main.c rename to regression/goto-analyzer/precise-dereference-const-struct-pointer-const-fp/main.c diff --git a/regression/goto-analyzer/fp-removal47/test.desc b/regression/goto-analyzer/precise-dereference-const-struct-pointer-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/fp-removal47/test.desc rename to regression/goto-analyzer/precise-dereference-const-struct-pointer-const-fp/test.desc From a6e71e04591e95364a7533bab16edddc89892155 Mon Sep 17 00:00:00 2001 From: thk123 Date: Fri, 10 Feb 2017 11:47:10 +0000 Subject: [PATCH 26/46] Tidied up tests Consistent indentation Consistent functions for the function pointers. Made braces appear on the next line. Made all structs include at least two components. Corrected the name of two of the tests. Remove unused imports. Made all the mains return int so they compile with clang with no warnings. Enabling debug output for all tests so can see the output Removing out of date comments from the tests Missing empty lines --- .../approx-array-variable-const-fp/main.c | 39 +++++++++------ .../approx-array-variable-const-fp/test.desc | 2 +- .../main.c | 42 +++++++++------- .../test.desc | 2 +- .../main.c | 41 +++++++++------- .../test.desc | 2 +- .../main.c | 41 +++++++++------- .../test.desc | 2 +- .../main.c | 39 ++++++++------- .../test.desc | 0 .../main.c | 43 ---------------- .../main.c | 47 ++++++++++-------- .../test.desc | 2 +- .../main.c | 40 ++++++++------- .../test.desc | 2 +- .../main.c | 37 ++++++++------ .../test.desc | 2 +- .../main.c | 37 ++++++++------ .../test.desc | 2 +- .../main.c | 35 +++++++------ .../test.desc | 2 +- .../main.c | 35 +++++++------ .../test.desc | 2 +- .../main.c | 35 +++++++------ .../test.desc | 2 - .../main.c | 31 ++++++------ .../test.desc | 6 --- .../main.c | 28 ++++++----- .../main.c | 24 ++++----- .../test.desc | 2 +- .../main.c | 28 ++++++----- .../test.desc | 3 -- .../main.c | 39 ++++++++------- .../test.desc | 2 - .../main.c | 38 ++++++++------ .../main.c | 37 ++++++++------ .../main.c | 32 ++++++------ .../main.c | 27 +++++----- .../main.c | 27 +++++----- .../main.c | 24 ++++----- .../test.desc | 2 +- .../no-match-non-const-fp/main.c | 25 +++++----- .../no-match-parameter-const-fp/main.c | 39 +++++++++------ .../no-match-parameter-const-fp/test.desc | 2 +- .../no-match-parameter-fp/main.c | 39 +++++++++------ .../no-match-parameter-fp/test.desc | 2 +- .../main.c | 27 +++++----- .../precise-array-calculation-const-fp/main.c | 25 +++++----- .../test.desc | 5 +- .../precise-array-literal-const-fp/main.c | 25 +++++----- .../precise-array-literal-const-fp/test.desc | 2 +- .../main.c | 25 +++++----- .../test.desc | 2 +- .../main.c | 25 +++++----- .../test.desc | 2 +- .../main.c | 49 ++++++++++--------- .../test.desc | 2 +- .../main.c | 49 +++++++++++++++++++ .../test.desc | 0 .../precise-const-fp-const-fp/main.c | 24 ++++----- .../precise-const-fp-const-fp/test.desc | 2 +- .../main.c | 27 +++++----- .../test.desc | 3 -- .../main.c | 36 ++++++++------ .../test.desc | 6 --- .../main.c | 42 +++++++++------- .../main.c | 29 ++++++----- .../test.desc | 6 --- .../goto-analyzer/precise-const-fp/main.c | 25 +++++----- .../goto-analyzer/precise-const-fp/test.desc | 2 +- .../precise-const-struct-non-const-fp/main.c | 40 ++++++++------- .../main.c | 29 ++++++----- .../test.desc | 6 --- .../goto-analyzer/precise-derefence/main.c | 24 ++++----- .../goto-analyzer/precise-derefence/test.desc | 2 +- .../main.c | 29 ++++++----- .../test.desc | 6 --- .../main.c | 27 +++++----- .../main.c | 27 +++++----- .../main.c | 27 +++++----- 80 files changed, 893 insertions(+), 754 deletions(-) rename regression/goto-analyzer/{approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp2 => approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp}/main.c (50%) rename regression/goto-analyzer/{approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp2 => approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp}/test.desc (100%) delete mode 100644 regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp1/main.c create mode 100644 regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/main.c rename regression/goto-analyzer/{approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp1 => precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp}/test.desc (100%) diff --git a/regression/goto-analyzer/approx-array-variable-const-fp/main.c b/regression/goto-analyzer/approx-array-variable-const-fp/main.c index 8fc4036e201..3fb230c83fd 100644 --- a/regression/goto-analyzer/approx-array-variable-const-fp/main.c +++ b/regression/goto-analyzer/approx-array-variable-const-fp/main.c @@ -1,12 +1,14 @@ -void f1 (void) { int tk = 1; } -void f2 (void) { int tk = 2; } -void f3 (void) { int tk = 3; } -void f4 (void) { int tk = 4; } -void f5 (void) { int tk = 5; } -void f6 (void) { int tk = 6; } -void f7 (void) { int tk = 7; } -void f8 (void) { int tk = 8; } -void f9 (void) { int tk = 9; } +#include + +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); @@ -16,12 +18,17 @@ const void_fp fp_tbl[] = {f2, f3 ,f4}; // 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](); +void func(int i) +{ + fp_tbl[i](); } -void main(){ - for(int i=0;i<3;i++){ - func(i); - } -} +int main() +{ + for(int i=0;i<3;i++) + { + func(i); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/approx-array-variable-const-fp/test.desc b/regression/goto-analyzer/approx-array-variable-const-fp/test.desc index cf845be0316..13cac884101 100644 --- a/regression/goto-analyzer/approx-array-variable-const-fp/test.desc +++ b/regression/goto-analyzer/approx-array-variable-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*IF fp_tbl\[(signed long int)i\] == f2 THEN GOTO 1$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/main.c index 45865b9599e..3d968a5e243 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/main.c +++ b/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -16,20 +16,26 @@ typedef void(*void_fp)(void); // 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(* const fp_tbl[3])(void) = +{ (void(*)())f2, (void(*)())f3, (void(*)())f4, }; -void func(int i){ - const void_fp fp = fp_tbl[i]; - fp(); +void func(int i) +{ + const void_fp fp = fp_tbl[i]; + fp(); } -void main(){ - for(int i=0;i<3;i++){ - func(i); - } -} +int main() +{ + for(int i=0;i<3;i++) + { + func(i); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc index 15840e69fe3..05b7ce7e581 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*IF fp == f2 THEN GOTO 1$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/main.c index 7bbfed5fd8b..a777bce3a48 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/main.c +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/main.c @@ -1,12 +1,14 @@ -void f1 (void) { int tk = 1; } -void f2 (void) { int tk = 2; } -void f3 (void) { int tk = 3; } -void f4 (void) { int tk = 4; } -void f5 (void) { int tk = 5; } -void f6 (void) { int tk = 6; } -void f7 (void) { int tk = 7; } -void f8 (void) { int tk = 8; } -void f9 (void) { int tk = 9; } +#include + +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); @@ -16,13 +18,18 @@ const void_fp fp_tbl[] = {f2, f3 ,f4, 0}; // 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(); +void func(int i) +{ + const void_fp fp = fp_tbl[i]; + fp(); } -void main(){ - for(int i=0;i<3;i++){ - func(i); - } -} +int main() +{ + for(int i=0;i<3;i++) + { + func(i); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc index 15840e69fe3..05b7ce7e581 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*IF fp == f2 THEN GOTO 1$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/main.c index 20cf98fb59a..d426bba269e 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/main.c +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/main.c @@ -1,12 +1,14 @@ -void f1 (void) { int tk = 1; } -void f2 (void) { int tk = 2; } -void f3 (void) { int tk = 3; } -void f4 (void) { int tk = 4; } -void f5 (void) { int tk = 5; } -void f6 (void) { int tk = 6; } -void f7 (void) { int tk = 7; } -void f8 (void) { int tk = 8; } -void f9 (void) { int tk = 9; } +#include + +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); @@ -16,13 +18,18 @@ const void_fp fp_tbl[] = {f2, f3 ,f4}; // 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(); +void func(int i) +{ + const void_fp fp = fp_tbl[i]; + fp(); } -void main(){ - for(int i=0;i<3;i++){ - func(i); - } -} +int main() +{ + for(int i=0;i<3;i++) + { + func(i); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc index 15840e69fe3..05b7ce7e581 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*IF fp == f2 THEN GOTO 1$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp2/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/main.c similarity index 50% rename from regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp2/main.c rename to regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/main.c index 51f8de1de9e..c27aee68bd8 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp2/main.c +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -33,13 +33,18 @@ const struct action * const action_list[4] = // 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(); +void func(int i) +{ + const void_fp fp = action_list[i]->fun; + fp(); } -void main(){ - for(int i=0;i<3;i++){ - func(i); - } -} +int main() +{ + for(int i=0;i<3;i++) + { + func(i); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp2/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp2/test.desc rename to regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp1/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp1/main.c deleted file mode 100644 index 6cf0b7ee3ce..00000000000 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp1/main.c +++ /dev/null @@ -1,43 +0,0 @@ -#include - -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } - -typedef void(*void_fp)(void); - -struct action -{ - void_fp fun; -}; - -const struct action rec = { .fun = f2 }; - -const struct action * const action_list[4] = -{ - &rec, - &rec, - &rec, - &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(); -} - -void main(){ - for(int i=0;i<4;i++){ - func(i); - } -} diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/main.c index 1e9deb388c1..e058e5f3c4f 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/main.c +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -16,12 +16,14 @@ typedef void(*void_fp)(void); // 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 { +struct stable +{ int x; void (*fp)(void); }; -const struct stable stable_table [3] = { +const struct stable stable_table [3] = +{ { 1, f2 }, { 2, f3 }, { 3, f4 } @@ -30,17 +32,20 @@ const struct stable stable_table [3] = { const struct stable another_table = { 4, f5 }; -void func(int i){ - const void_fp fp = stable_table[i].fp; +void func(int i) +{ + const void_fp fp = stable_table[i].fp; - // Illegal - // stable_table[1] = another_table; - fp(); + // Illegal + // stable_table[1] = another_table; + fp(); } -int main(){ - for(int i=0;i<3;i++){ - func(i); - } - return 0; +int main() +{ + for(int i=0;i<3;i++) + { + func(i); + } + return 0; } diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc index 4f3168057fa..05b7ce7e581 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc @@ -8,4 +8,4 @@ main.c ^\s*IF fp == f4 THEN GOTO 3$ ^SIGNAL=0$ -- -^warning: ignoring \ No newline at end of file +^warning: ignoring diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/main.c index 0abcd656db1..ca882ffd6b3 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/main.c +++ b/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/main.c @@ -2,47 +2,47 @@ int f1 (void) { - printf("%i", 1); + printf("%i\n", 1); return 1; } int f2 (void) { - printf("%i", 2); + printf("%i\n", 2); return 2; } int f3 (void) { - printf("%i", 3); + printf("%i\n", 3); return 3; } int f4 (void) { - printf("%i", 4); + printf("%i\n", 4); return 4; } int f5 (void) { - printf("%i", 5); + printf("%i\n", 5); return 5; } int f6 (void) { - printf("%i", 6); + printf("%i\n", 6); return 6; } int f7 (void) { - printf("%i", 7); + printf("%i\n", 7); return 7; } int f8 (void) { - printf("%i", 8); + printf("%i\n", 8); return 8; } int f9 (void) { - printf("%i", 9); + printf("%i\n", 9); return 9; } @@ -53,21 +53,25 @@ typedef int(*int_fp)(void); // This ensures that check can't work in this example const int_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9}; -void(* const fp_tbl[3])(void) = { +void(* const fp_tbl[3])(void) = +{ (void(*)())f2, (void(*)())f3, (void(*)())f4, }; -void func(int i){ - const void_fp fp = fp_tbl[i]; - fp(); +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; +int main() +{ + for(int i=0;i<3;i++) + { + func(i); + } + return 0; } diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc index 81db0db6f9f..00cd5d6eafd 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*IF fp == (void (\*)(void))f2 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/main.c b/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/main.c index fd73934e83c..16b0221e740 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/main.c +++ b/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/main.c @@ -1,12 +1,14 @@ -void f1 (void) { int tk = 1; } -void f2 (void) { int tk = 2; } -void f3 (void) { int tk = 3; } -void f4 (void) { int tk = 4; } -void f5 (void) { int tk = 5; } -void f6 (void) { int tk = 6; } -void f7 (void) { int tk = 7; } -void f8 (void) { int tk = 8; } -void f9 (void) { int tk = 9; } +#include + +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); @@ -14,7 +16,8 @@ typedef void(*void_fp)(void); // 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, int j){ +void func(int i, int j) +{ const void_fp fp_tbl[] = {fp_all[i*2], fp_all[j+1]}; // Illegal: //fp_tbl[1] = f4; @@ -22,8 +25,12 @@ void func(int i, int j){ fp(); } -void main(){ - for(int i=0;i<3;i++){ - func(i,0); - } -} +int main() +{ + for(int i=0;i<3;i++) + { + func(i,0); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/test.desc b/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/test.desc index 3c735d48a55..deda28d213f 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*IF fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/main.c b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/main.c index 68ddffa073e..a67cf750d5e 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/main.c +++ b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/main.c @@ -1,12 +1,14 @@ -void f1 (void) { int tk = 1; } -void f2 (void) { int tk = 2; } -void f3 (void) { int tk = 3; } -void f4 (void) { int tk = 4; } -void f5 (void) { int tk = 5; } -void f6 (void) { int tk = 6; } -void f7 (void) { int tk = 7; } -void f8 (void) { int tk = 8; } -void f9 (void) { int tk = 9; } +#include + +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); @@ -14,14 +16,19 @@ typedef void(*void_fp)(void); // 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, int j){ +void func(int i, int j) +{ void_fp fp_tbl[] = {fp_all[i*2], fp_all[j+1]}; const void_fp fp = fp_tbl[1]; fp(); } -void main(){ - for(int i=0;i<3;i++){ - func(i,0); - } -} +int main() +{ + for(int i=0;i<3;i++) + { + func(i,0); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/test.desc b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/test.desc index 3c735d48a55..deda28d213f 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*IF fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/main.c b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/main.c index 26d09257aaf..d649b1dd056 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -18,7 +18,8 @@ void_fp fp_tbl[] = {f2, f3, f4}; // 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(void_fp fp, int i){ +void func(void_fp fp, int i) +{ // It is concievable this could be checked and seen the first value // of the array is unchanged but is kind of a weird edge case. fp_tbl[2] = fp; @@ -26,8 +27,12 @@ void func(void_fp fp, int i){ fp2(); } -void main(){ - for(int i=0;i<3;i++){ - func(fp_all[i+3], i); - } -} +int main() +{ + for(int i=0;i<3;i++) + { + func(fp_all[i+3], i); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/test.desc index 7f4fb53760e..1942b6b867b 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*IF fp2 == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/main.c b/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/main.c index 56729ff428a..189bd8c036d 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -18,14 +18,19 @@ void_fp fp_tbl[] = {f2, f3, f4}; // 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(void_fp fp, int i){ +void func(void_fp fp, int i) +{ fp_tbl[2] = fp; const void_fp fp2 = fp_tbl[2]; fp2(); } -void main(){ - for(int i=0;i<3;i++){ - func(fp_all[i+3], i); - } -} +int main() +{ + for(int i=0;i<3;i++) + { + func(fp_all[i+3], i); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/test.desc index 7f4fb53760e..1942b6b867b 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*IF fp2 == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/main.c b/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/main.c index e7b62bc8b81..1420490b0a6 100644 --- a/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -25,18 +25,23 @@ struct state * const pts = &thing; // 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){ +void func(int i) +{ // Illegal //pts=&other_thing; // thing.go=&f6; thing = other_thing; - const void_fp fp = pts->go; + const void_fp fp = pts->go; - fp(); + fp(); } -void main(){ - for(int i=0;i<3;i++){ +int main() +{ + for(int i=0;i<3;i++) + { func(i); } -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/test.desc index 889299e9a3c..deda28d213f 100644 --- a/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/test.desc @@ -15,5 +15,3 @@ main.c ^SIGNAL=0$ -- ^warning: ignoring --- -Mutable struct but const pointer inside it, not yet supported diff --git a/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/main.c b/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/main.c index 1510abceb69..f9750966b58 100644 --- a/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/main.c @@ -1,15 +1,14 @@ #include -#include - -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } + +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); @@ -17,7 +16,8 @@ typedef void(*void_fp)(void); // 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(){ +void func() +{ const void_fp fp = f3; const void_fp fp2 = f4; const void_fp* p2fp = &fp; @@ -32,6 +32,9 @@ void func(){ final_fp(); } -void main(){ +int main() +{ func(); -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/test.desc index c60094eebd3..ff7c3cc2b07 100644 --- a/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/test.desc @@ -15,9 +15,3 @@ main.c ^SIGNAL=0$ -- ^warning: ignoring --- -This test is marked as a KNOWNBUG as it is possible for the function -pointer to be optimized away. Currently goto-analyzer falls back to -assuming it could be any type compatible function. - -Issue: https://github.com/diffblue/cbmc/issues/476 diff --git a/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/main.c b/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/main.c index 3f90a10ab65..f468113ac16 100644 --- a/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/main.c @@ -1,15 +1,15 @@ #include #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -17,7 +17,8 @@ typedef void(*void_fp)(void); // 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(){ +void func() +{ void_fp * const fp_tbl= malloc(sizeof(void_fp) * 3); fp_tbl[0]=f2; fp_tbl[1]=f3; @@ -30,6 +31,9 @@ void func(){ fp(); } -void main(){ +int main() +{ func(); -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/main.c b/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/main.c index 1ed1a4c6511..98c7f0619b6 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/main.c +++ b/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -24,7 +24,9 @@ void func() fp2(); } -void main() +int main() { func(); -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/test.desc b/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/test.desc index 9ea2dfbbc29..722b6878ab5 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*IF fp2 == f1 THEN GOTO 1$ ^\s*IF fp2 == f2 THEN GOTO 2$ diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/main.c b/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/main.c index 2f828e830ce..1da907916bd 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -36,8 +36,12 @@ void func(int i) } -void main(){ - for(int i=0;i<3;i++){ +int main() +{ + for(int i=0;i<3;i++) + { func(i); } -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/test.desc index b31b9aedfa1..deda28d213f 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/test.desc @@ -15,6 +15,3 @@ main.c ^SIGNAL=0$ -- ^warning: ignoring --- -This shouldn't work because the pointer can be assigned to a different -struct after initial assignment. diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/main.c b/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/main.c index cba5ae9bfc7..3952169b535 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -25,14 +25,19 @@ struct state other_thing = {0, &f4}; // 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){ +void func(int i) +{ thing = other_thing; - const void_fp fp = thing.go; - fp(); + const void_fp fp = thing.go; + fp(); } -void main(){ - for(int i=0;i<3;i++){ - func(i); - } -} +int main() +{ + for(int i=0;i<3;i++) + { + func(i); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/test.desc index 889299e9a3c..deda28d213f 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/test.desc @@ -15,5 +15,3 @@ main.c ^SIGNAL=0$ -- ^warning: ignoring --- -Mutable struct but const pointer inside it, not yet supported diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/main.c b/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/main.c index 87e79cdb5d9..9c1af7d8d83 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/main.c @@ -1,37 +1,43 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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 { + int x; void_fp fun; }; -struct action rec = { .fun = f2 }; +struct action rec = { .x = 4, .fun = f2 }; // 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){ +void func(int i) +{ // Can mutate rec.fun=f4; const void_fp fp = rec.fun; fp(); } -void main(){ - for(int i=0;i<3;i++){ - func(i); - } -} +int main() +{ + for(int i=0;i<3;i++) + { + func(i); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/main.c b/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/main.c index 210facf60bf..f626942ef8b 100644 --- a/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -26,13 +26,18 @@ struct state const * const pts = &thing; // 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){ +void func(int i) +{ thing = other_thing; - pts->go(); + pts->go(); } -void main(){ - for(int i=0;i<3;i++){ - func(i); - } -} +int main() +{ + for(int i=0;i<3;i++) + { + func(i); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/main.c b/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/main.c index e0b37fceb10..5d857ffcfe7 100644 --- a/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/main.c +++ b/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/main.c @@ -1,15 +1,14 @@ #include -#include - -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } + +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); @@ -19,12 +18,14 @@ const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9}; typedef struct fp_container { + int x; const void_fp* const fp_tbl[3]; } fp_container; -void func(){ +void func() +{ void_fp f2meta = &f2; void_fp f3meta = &f3; void_fp f4meta = &f4; @@ -33,8 +34,8 @@ void func(){ void_fp f6meta = &f6; void_fp f7meta = &f7; - const fp_container container = { .fp_tbl = {&f2meta ,&f3meta, &f4meta} }; - const fp_container container2 = { .fp_tbl = {&f5meta ,&f6meta, &f7meta} }; + const fp_container container = { .x = 4, .fp_tbl = {&f2meta ,&f3meta, &f4meta} }; + const fp_container container2 = { .x = 5, .fp_tbl = {&f5meta ,&f6meta, &f7meta} }; f3meta = &f5; // Illegal: @@ -45,6 +46,7 @@ void func(){ (*container_ptr->fp_tbl[1])(); } -int main(){ +int main() +{ func(); } diff --git a/regression/goto-analyzer/no-match-dereference-non-const-struct-const-pointer-const-fp/main.c b/regression/goto-analyzer/no-match-dereference-non-const-struct-const-pointer-const-fp/main.c index c1f4811bad8..b0be4e4837c 100644 --- a/regression/goto-analyzer/no-match-dereference-non-const-struct-const-pointer-const-fp/main.c +++ b/regression/goto-analyzer/no-match-dereference-non-const-struct-const-pointer-const-fp/main.c @@ -1,15 +1,14 @@ #include -#include - -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } + +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); @@ -25,7 +24,8 @@ typedef struct fp_cc -void func(){ +void func() +{ const void_fp meta_fp = &f3; const void_fp meta_fp2 = &f4; @@ -40,6 +40,7 @@ void func(){ (*container_container.container)(); } -int main(){ +int main() +{ func(); } diff --git a/regression/goto-analyzer/no-match-dereference-non-const-struct-non-const-pointer-const-fp/main.c b/regression/goto-analyzer/no-match-dereference-non-const-struct-non-const-pointer-const-fp/main.c index 12949ed8d85..28110c56d01 100644 --- a/regression/goto-analyzer/no-match-dereference-non-const-struct-non-const-pointer-const-fp/main.c +++ b/regression/goto-analyzer/no-match-dereference-non-const-struct-non-const-pointer-const-fp/main.c @@ -1,15 +1,14 @@ #include -#include - -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } + +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); @@ -25,7 +24,8 @@ typedef struct fp_cc -void func(){ +void func() +{ const void_fp meta_fp = &f3; const void_fp meta_fp2 = &f4; fp_cc container_container = { .container = &meta_fp, .x = 4 }; @@ -37,6 +37,7 @@ void func(){ (*container_container.container)(); } -int main(){ +int main() +{ func(); } diff --git a/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/main.c b/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/main.c index f1d35373e15..a9a31b98a70 100644 --- a/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/main.c +++ b/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -25,7 +25,9 @@ void func() fp2(); } -void main() +int main() { func(); -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/test.desc b/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/test.desc index 9ea2dfbbc29..722b6878ab5 100644 --- a/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/test.desc +++ b/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*IF fp2 == f1 THEN GOTO 1$ ^\s*IF fp2 == f2 THEN GOTO 2$ diff --git a/regression/goto-analyzer/no-match-non-const-fp/main.c b/regression/goto-analyzer/no-match-non-const-fp/main.c index 4b81bffdb30..a5d81d9959d 100644 --- a/regression/goto-analyzer/no-match-non-const-fp/main.c +++ b/regression/goto-analyzer/no-match-non-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -23,6 +23,9 @@ void func() fp(); } -void main(){ +int main() +{ func(); -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-parameter-const-fp/main.c b/regression/goto-analyzer/no-match-parameter-const-fp/main.c index 080f1affcc8..340373af407 100644 --- a/regression/goto-analyzer/no-match-parameter-const-fp/main.c +++ b/regression/goto-analyzer/no-match-parameter-const-fp/main.c @@ -1,12 +1,14 @@ -void f1 (void) { int tk = 1; } -void f2 (void) { int tk = 2; } -void f3 (void) { int tk = 3; } -void f4 (void) { int tk = 4; } -void f5 (void) { int tk = 5; } -void f6 (void) { int tk = 6; } -void f7 (void) { int tk = 7; } -void f8 (void) { int tk = 8; } -void f9 (void) { int tk = 9; } +#include + +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); @@ -14,12 +16,17 @@ typedef void(*void_fp)(void); // 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(const void_fp fp){ - fp(); +void func(const void_fp fp) +{ + fp(); } -void main(){ - for(int i=0;i<3;i++){ - func(fp_all[i]); - } -} +int main() +{ + for(int i=0;i<3;i++) + { + func(fp_all[i]); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-parameter-const-fp/test.desc b/regression/goto-analyzer/no-match-parameter-const-fp/test.desc index 3c735d48a55..deda28d213f 100644 --- a/regression/goto-analyzer/no-match-parameter-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-parameter-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*IF fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-parameter-fp/main.c b/regression/goto-analyzer/no-match-parameter-fp/main.c index 8bbd6ee15d6..fe392e11f0e 100644 --- a/regression/goto-analyzer/no-match-parameter-fp/main.c +++ b/regression/goto-analyzer/no-match-parameter-fp/main.c @@ -1,12 +1,14 @@ -void f1 (void) { int tk = 1; } -void f2 (void) { int tk = 2; } -void f3 (void) { int tk = 3; } -void f4 (void) { int tk = 4; } -void f5 (void) { int tk = 5; } -void f6 (void) { int tk = 6; } -void f7 (void) { int tk = 7; } -void f8 (void) { int tk = 8; } -void f9 (void) { int tk = 9; } +#include + +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); @@ -14,12 +16,17 @@ typedef void(*void_fp)(void); // 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(void_fp fp){ - fp(); +void func(void_fp fp) +{ + fp(); } -void main(){ - for(int i=0;i<3;i++){ - func(fp_all[i]); - } -} +int main() +{ + for(int i=0;i<3;i++) + { + func(fp_all[i]); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-parameter-fp/test.desc b/regression/goto-analyzer/no-match-parameter-fp/test.desc index 3c735d48a55..deda28d213f 100644 --- a/regression/goto-analyzer/no-match-parameter-fp/test.desc +++ b/regression/goto-analyzer/no-match-parameter-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*IF fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/main.c b/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/main.c index bd46ce92484..c9d632f43b9 100644 --- a/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/main.c +++ b/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/main.c @@ -1,15 +1,14 @@ #include -#include - -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } + +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); @@ -24,7 +23,8 @@ typedef struct fp_container -void func(){ +void func() +{ const fp_container container = { .fp_tbl = {f2 ,f3, f4} }; const void_fp alternatate_fp_tbl[] = {f5 ,f6, f7}; const fp_container container2 = { .fp_tbl = {f5 ,f6, f7} }; @@ -36,6 +36,7 @@ void func(){ container_ptr->fp_tbl[1](); } -int main(){ +int main() +{ func(); } diff --git a/regression/goto-analyzer/precise-array-calculation-const-fp/main.c b/regression/goto-analyzer/precise-array-calculation-const-fp/main.c index cbe9e504df2..be8d02bff78 100644 --- a/regression/goto-analyzer/precise-array-calculation-const-fp/main.c +++ b/regression/goto-analyzer/precise-array-calculation-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -24,6 +24,9 @@ void func() fp_tbl[(signed long int)((signed int)short_const_variable & 0x1)](); } -void main(){ +int main() +{ func(); -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/precise-array-calculation-const-fp/test.desc b/regression/goto-analyzer/precise-array-calculation-const-fp/test.desc index a402b60e080..3fb0a47980c 100644 --- a/regression/goto-analyzer/precise-array-calculation-const-fp/test.desc +++ b/regression/goto-analyzer/precise-array-calculation-const-fp/test.desc @@ -1,11 +1,8 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*f3();$ ^SIGNAL=0$ -- ^warning: ignoring --- -Fails because of the non-trivial index expression can be evaluated -constantly but isn't \ No newline at end of file diff --git a/regression/goto-analyzer/precise-array-literal-const-fp/main.c b/regression/goto-analyzer/precise-array-literal-const-fp/main.c index bd650bd01ae..31cc52a7403 100644 --- a/regression/goto-analyzer/precise-array-literal-const-fp/main.c +++ b/regression/goto-analyzer/precise-array-literal-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -23,6 +23,9 @@ void func() fp_tbl[1](); } -void main(){ +int main() +{ func(); -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/precise-array-literal-const-fp/test.desc b/regression/goto-analyzer/precise-array-literal-const-fp/test.desc index a36fb208c69..3fb0a47980c 100644 --- a/regression/goto-analyzer/precise-array-literal-const-fp/test.desc +++ b/regression/goto-analyzer/precise-array-literal-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*f3();$ ^SIGNAL=0$ diff --git a/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/main.c b/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/main.c index fbbd4f34259..a43a189f96f 100644 --- a/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -25,6 +25,9 @@ void func() fp(); } -void main(){ +int main() +{ func(); -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/test.desc index a36fb208c69..3fb0a47980c 100644 --- a/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*f3();$ ^SIGNAL=0$ diff --git a/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/main.c b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/main.c index 4d057be3a08..d061734174f 100644 --- a/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -24,6 +24,9 @@ void func() fp(); } -void main(){ +int main() +{ func(); -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/test.desc index a36fb208c69..3fb0a47980c 100644 --- a/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*f3();$ ^SIGNAL=0$ diff --git a/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/main.c b/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/main.c index 0c8c7e86046..26f13fc4c28 100644 --- a/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -16,12 +16,14 @@ typedef void(*void_fp)(void); // 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 { +struct stable +{ int x; void (*fp)(void); }; -const struct stable stable_table [3] = { +const struct stable stable_table [3] = +{ { 1, f2 }, { 2, f3 }, { 3, f4 } @@ -30,18 +32,21 @@ const struct stable stable_table [3] = { const struct stable another_table = { 4, f5 }; -void func(int i){ - const void_fp fp = stable_table[1].fp; +void func(int i) +{ + const void_fp fp = stable_table[1].fp; - // Illegal - // stable_table[1] = another_table; - // stable_table[1].fp = f5; - fp(); + // Illegal + // stable_table[1] = another_table; + // stable_table[1].fp = f5; + fp(); } -int main(){ - for(int i=0;i<3;i++){ - func(i); - } - return 0; +int main() +{ + for(int i=0;i<3;i++) + { + func(i); + } + return 0; } diff --git a/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/test.desc index bfc412d2705..77c3b9a93d1 100644 --- a/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/test.desc @@ -6,4 +6,4 @@ main.c ^\s*f3();$ ^SIGNAL=0$ -- -^warning: ignoring \ No newline at end of file +^warning: ignoring diff --git a/regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/main.c b/regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/main.c new file mode 100644 index 00000000000..c1bcb0dc951 --- /dev/null +++ b/regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/main.c @@ -0,0 +1,49 @@ +#include + +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 +{ + int x; + void_fp fun; +}; + +const struct action rec = { .x = 4, .fun = f2 }; + +const struct action * const action_list[4] = +{ + &rec, + &rec, + &rec, + &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<4;i++) +{ + func(i); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp1/test.desc b/regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc similarity index 100% rename from regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp1/test.desc rename to regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc diff --git a/regression/goto-analyzer/precise-const-fp-const-fp/main.c b/regression/goto-analyzer/precise-const-fp-const-fp/main.c index 85f6fc5b79e..d3a61d828e1 100644 --- a/regression/goto-analyzer/precise-const-fp-const-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -23,7 +23,9 @@ void func() fp2(); } -void main() +int main() { func(); -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/precise-const-fp-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-const-fp/test.desc index 9ba26c84989..653466e87fb 100644 --- a/regression/goto-analyzer/precise-const-fp-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*f2();$ ^SIGNAL=0$ diff --git a/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/main.c b/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/main.c index 06ccc492469..8a05a9b7d4c 100644 --- a/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/main.c @@ -1,15 +1,14 @@ #include -#include - -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } + +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); @@ -24,7 +23,8 @@ typedef struct fp_container -void func(){ +void func() +{ const fp_container container = { .fp_tbl = {f2 ,f3, f4} }; const fp_container container2 = { .fp_tbl = {f5 ,f6, f7} }; // Illegal: @@ -33,6 +33,7 @@ void func(){ fp(); } -int main(){ +int main() +{ func(); } diff --git a/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/test.desc b/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/test.desc index 701da09802e..77c3b9a93d1 100644 --- a/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/test.desc @@ -7,6 +7,3 @@ main.c ^SIGNAL=0$ -- ^warning: ignoring --- -This is currently failing because the const is being ignored inside -the struct diff --git a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/main.c b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/main.c index a64ca581ae5..5cf1602c854 100644 --- a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/main.c @@ -1,15 +1,14 @@ #include -#include - -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } + +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); @@ -19,14 +18,16 @@ const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9}; typedef struct fp_container { + int x; void_fp fp_tbl[3]; } fp_container; -void func(){ - const fp_container container = { .fp_tbl = {f2 ,f3, f4} }; - fp_container container2 = { .fp_tbl = {f5 ,f6, f7} }; +void func() +{ + const fp_container container = { .x = 4, .fp_tbl = {f2 ,f3, f4} }; + fp_container container2 = { .x = 5, .fp_tbl = {f5 ,f6, f7} }; const void_fp alternatate_fp_tbl[] = {f5 ,f6, f7}; // Illegal: // container = container2; @@ -36,6 +37,9 @@ void func(){ fp(); } -void main(){ +int main() +{ func(); -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/test.desc b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/test.desc index 649ba6fbedd..77c3b9a93d1 100644 --- a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/test.desc @@ -7,9 +7,3 @@ main.c ^SIGNAL=0$ -- ^warning: ignoring --- -This test is marked as a KNOWNBUG as it is possible for the function -pointer to be optimized away. Currently goto-analyzer falls back to -assuming it could be any type compatible function. - -Issue: https://github.com/diffblue/cbmc/issues/476 diff --git a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/main.c b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/main.c index e4f1ee8c491..02cbb17f851 100644 --- a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/main.c @@ -1,38 +1,44 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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 { + int x; void_fp fun; }; -const struct action rec = { .fun = f2 }; +const struct action rec = { .x = 4, .fun = f2 }; // 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){ +void func(int i) +{ // Illegal: //rec.fun = &f5; - const void_fp fp = rec.fun; - fp(); + const void_fp fp = rec.fun; + fp(); } -void main(){ - for(int i=0;i<3;i++){ - func(i); - } -} +int main() +{ + for(int i=0;i<3;i++) + { + func(i); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/main.c b/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/main.c index c90c9bb9585..c18a7fe3256 100644 --- a/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/main.c @@ -1,15 +1,14 @@ #include -#include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -17,7 +16,8 @@ typedef void(*void_fp)(void); // 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(){ +void func() +{ const void_fp fp = f3; const void_fp fp2 = f4; const void_fp* const p2fp = &fp; @@ -28,6 +28,9 @@ void func(){ final_fp(); } -void main(){ +int main() +{ func(); -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/test.desc index 649ba6fbedd..77c3b9a93d1 100644 --- a/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/test.desc @@ -7,9 +7,3 @@ main.c ^SIGNAL=0$ -- ^warning: ignoring --- -This test is marked as a KNOWNBUG as it is possible for the function -pointer to be optimized away. Currently goto-analyzer falls back to -assuming it could be any type compatible function. - -Issue: https://github.com/diffblue/cbmc/issues/476 diff --git a/regression/goto-analyzer/precise-const-fp/main.c b/regression/goto-analyzer/precise-const-fp/main.c index f9b5908bce2..f4d21dc2588 100644 --- a/regression/goto-analyzer/precise-const-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -22,6 +22,9 @@ void func() fp(); } -void main(){ +int main() +{ func(); -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/precise-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp/test.desc index c3065239e49..eb4d61d9d9c 100644 --- a/regression/goto-analyzer/precise-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*f2(); diff --git a/regression/goto-analyzer/precise-const-struct-non-const-fp/main.c b/regression/goto-analyzer/precise-const-struct-non-const-fp/main.c index 8fbd4796975..aa534a96e93 100644 --- a/regression/goto-analyzer/precise-const-struct-non-const-fp/main.c +++ b/regression/goto-analyzer/precise-const-struct-non-const-fp/main.c @@ -1,34 +1,40 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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 { + int x; void_fp fun; }; -const struct action rec = { .fun = f2 }; +const struct action rec = { .x = 4, .fun = f2 }; // 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){ - rec.fun(); +void func(int i) +{ + rec.fun(); } -void main(){ - for(int i=0;i<3;i++){ - func(i); - } -} +int main() +{ + for(int i=0;i<3;i++) + { + func(i); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/main.c b/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/main.c index b5599183e11..1e2fd83fd6b 100644 --- a/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/main.c +++ b/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/main.c @@ -1,15 +1,14 @@ #include -#include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -17,7 +16,8 @@ typedef void(*void_fp)(void); // 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(){ +void func() +{ const void_fp fp = f3; const void_fp fp2 = f4; const void_fp* const p2fp = &fp; @@ -27,6 +27,9 @@ void func(){ (*p2fp)(); } -void main(){ +int main() +{ func(); -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/test.desc b/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/test.desc index 649ba6fbedd..77c3b9a93d1 100644 --- a/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/test.desc @@ -7,9 +7,3 @@ main.c ^SIGNAL=0$ -- ^warning: ignoring --- -This test is marked as a KNOWNBUG as it is possible for the function -pointer to be optimized away. Currently goto-analyzer falls back to -assuming it could be any type compatible function. - -Issue: https://github.com/diffblue/cbmc/issues/476 diff --git a/regression/goto-analyzer/precise-derefence/main.c b/regression/goto-analyzer/precise-derefence/main.c index 16df50eeb11..318676c712e 100644 --- a/regression/goto-analyzer/precise-derefence/main.c +++ b/regression/goto-analyzer/precise-derefence/main.c @@ -1,14 +1,14 @@ #include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -23,7 +23,9 @@ void func() (*(&f2))(); } -void main() +int main() { func(); -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/precise-derefence/test.desc b/regression/goto-analyzer/precise-derefence/test.desc index c3065239e49..eb4d61d9d9c 100644 --- a/regression/goto-analyzer/precise-derefence/test.desc +++ b/regression/goto-analyzer/precise-derefence/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions +--show-goto-functions --verbosity 10 ^Removing function pointers and virtual functions$ ^\s*f2(); diff --git a/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/main.c b/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/main.c index e27d618cea9..56a7a7d7c4e 100644 --- a/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/main.c +++ b/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/main.c @@ -1,15 +1,14 @@ #include -#include -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } +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); @@ -17,11 +16,15 @@ typedef void(*void_fp)(void); // 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(){ +void func() +{ const void_fp fp = f3; (*(&fp))(); } -void main(){ +int main() +{ func(); -} + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/test.desc b/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/test.desc index 649ba6fbedd..77c3b9a93d1 100644 --- a/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/test.desc @@ -7,9 +7,3 @@ main.c ^SIGNAL=0$ -- ^warning: ignoring --- -This test is marked as a KNOWNBUG as it is possible for the function -pointer to be optimized away. Currently goto-analyzer falls back to -assuming it could be any type compatible function. - -Issue: https://github.com/diffblue/cbmc/issues/476 diff --git a/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-fp/main.c b/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-fp/main.c index c7237dee13f..c8694d74a08 100644 --- a/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-fp/main.c +++ b/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-fp/main.c @@ -1,15 +1,14 @@ #include -#include - -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } + +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); @@ -25,7 +24,8 @@ typedef struct fp_cc -void func(){ +void func() +{ const void_fp meta_fp = &f3; const fp_cc container_container = { .container = &meta_fp, .x = 4 }; @@ -36,6 +36,7 @@ void func(){ (*container_container.container)(); } -int main(){ +int main() +{ func(); } diff --git a/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-struct-const-fp/main.c b/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-struct-const-fp/main.c index 70b853a9dff..4f00ca80765 100644 --- a/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-struct-const-fp/main.c +++ b/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-struct-const-fp/main.c @@ -1,15 +1,14 @@ #include -#include - -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } + +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); @@ -31,7 +30,8 @@ typedef struct fp_cc -void func(){ +void func() +{ const fp_container container = {.y = 10, .pointer = f3}; const fp_container container2 = {.y = 10, .pointer = f4}; const fp_cc container_container = { .container = &container, .x = 4 }; @@ -43,6 +43,7 @@ void func(){ (*container_container.container).pointer(); } -int main(){ +int main() +{ func(); } diff --git a/regression/goto-analyzer/precise-dereference-const-struct-pointer-const-fp/main.c b/regression/goto-analyzer/precise-dereference-const-struct-pointer-const-fp/main.c index 7324bad0488..1d562a42dc8 100644 --- a/regression/goto-analyzer/precise-dereference-const-struct-pointer-const-fp/main.c +++ b/regression/goto-analyzer/precise-dereference-const-struct-pointer-const-fp/main.c @@ -1,15 +1,14 @@ #include -#include - -void f1 (void) { printf("%i", 1); } -void f2 (void) { printf("%i", 2); } -void f3 (void) { printf("%i", 3); } -void f4 (void) { printf("%i", 4); } -void f5 (void) { printf("%i", 5); } -void f6 (void) { printf("%i", 6); } -void f7 (void) { printf("%i", 7); } -void f8 (void) { printf("%i", 8); } -void f9 (void) { printf("%i", 9); } + +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); @@ -25,7 +24,8 @@ typedef struct fp_cc -void func(){ +void func() +{ const void_fp meta_fp = &f3; const fp_cc container_container = { .container = &meta_fp, .x = 4 }; @@ -36,6 +36,7 @@ void func(){ (*container_container.container)(); } -int main(){ +int main() +{ func(); } From ea5c15172235d78f1d9387cd9eb1090e9bbf6845 Mon Sep 17 00:00:00 2001 From: thk123 Date: Fri, 10 Feb 2017 11:59:38 +0000 Subject: [PATCH 27/46] Fixing compile errors for musketeer --- src/goto-programs/remove_function_pointers.h | 1 + src/musketeer/musketeer_parse_options.cpp | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/goto-programs/remove_function_pointers.h b/src/goto-programs/remove_function_pointers.h index 125cda131e1..0320a77c9a2 100644 --- a/src/goto-programs/remove_function_pointers.h +++ b/src/goto-programs/remove_function_pointers.h @@ -12,6 +12,7 @@ Date: June 2003 #define CPROVER_GOTO_PROGRAMS_REMOVE_FUNCTION_POINTERS_H #include "goto_model.h" +#include // remove indirect function calls // and replace by case-split diff --git a/src/musketeer/musketeer_parse_options.cpp b/src/musketeer/musketeer_parse_options.cpp index 707ec50bd0b..de8696d449c 100644 --- a/src/musketeer/musketeer_parse_options.cpp +++ b/src/musketeer/musketeer_parse_options.cpp @@ -215,7 +215,10 @@ void goto_fence_inserter_parse_optionst::instrument_goto_program( if(cmdline.isset("remove-function-pointers")) { status() << "remove soundly function pointers" << eom; - remove_function_pointers(symbol_table, goto_functions, + remove_function_pointers( + get_message_handler(), + symbol_table, + goto_functions, cmdline.isset("pointer-check")); } From f68ff26a3d361bcefc43d8fcaaaa852bac4f51da Mon Sep 17 00:00:00 2001 From: thk123 Date: Fri, 10 Feb 2017 15:28:36 +0000 Subject: [PATCH 28/46] Refactored resolve_index_of_function_call resolve_index_of and resolve_index_of_function_call both involved squashing down an array, the function call just made a different recurssive call at the end. Therefore it is equivalent to squash the entry and call the resolve function call on the final result. --- .../remove_const_function_pointers.cpp | 87 +++---------------- 1 file changed, 14 insertions(+), 73 deletions(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 3e04103c964..3c29666f86b 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -377,88 +377,29 @@ Function: remove_const_function_pointerst::try_resolve_index_of_function_call bool remove_const_function_pointerst::try_resolve_index_of_function_call( const index_exprt &index_expr, functionst &out_functions) { - // Get the array(s) it belongs to - expressionst potential_array_exprs; - bool is_const=false; - bool resolved_array= - try_resolve_expression(index_expr.array(), potential_array_exprs, is_const); - if(resolved_array) + expressionst potential_array_values; + bool array_const; + try_resolve_index_of(index_expr, potential_array_values, array_const); + if(array_const) { - for(const exprt &potential_array_expr : potential_array_exprs) + for(const exprt &array_value : potential_array_values) { - if(potential_array_expr.id()==ID_array) - { - // We require either the type of the values of the array or - // the array itself to be constant. - const typet &array_type=potential_array_expr.type(); - const typet &array_contents_type=array_type.subtype(); - c_qualifierst array_qaulifiers; - array_qaulifiers.read(array_contents_type); - - if(array_qaulifiers.is_constant || is_const) - { - // Get the index if we can - mp_integer value; - if(try_resolve_index_value(index_expr.index(), value)) - { - functionst array_out_functions; - const exprt &func_expr= - potential_array_expr.operands()[integer2size_t(value)]; - bool resolved_value= - try_resolve_function_call(func_expr, array_out_functions); + functionst array_out_functions; + bool resolved_value= + try_resolve_function_call(array_value, array_out_functions); - if(resolved_value) - { - out_functions.insert( - array_out_functions.begin(), - array_out_functions.end()); - } - else - { - LOG("Could not resolve expression in array", func_expr); - return false; - } - } - else - { - // We don't know what index it is, - // but we know the value is from the array - for(const exprt &array_entry : potential_array_expr.operands()) - { - if(array_entry.is_zero()) - { - continue; - } - functionst potential_functions; - bool resolved_value= - try_resolve_function_call(array_entry, potential_functions); - - if(resolved_value) - { - out_functions.insert( - potential_functions.begin(), potential_functions.end()); - } - else - { - LOG("Could not resolve expression in array", array_entry); - return false; - } - } - } - } - else - { - LOG("Array and its contents are not const", potential_array_expr); - return false; - } + if(resolved_value) + { + out_functions.insert( + array_out_functions.begin(), + array_out_functions.end()); } else { - LOG("Squashing index did not result in an array", potential_array_expr); + LOG("Could not resolve expression in array", array_value); return false; } } - return true; } else From 6298feaf6574d860141b3a001c87bd7679ed1ebc Mon Sep 17 00:00:00 2001 From: thk123 Date: Fri, 10 Feb 2017 15:39:21 +0000 Subject: [PATCH 29/46] Split out functions from try_resolve_function_call --- .../remove_const_function_pointers.cpp | 375 +++++++++++------- .../remove_const_function_pointers.h | 12 + 2 files changed, 248 insertions(+), 139 deletions(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 3c29666f86b..0ffff170e0b 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -181,157 +181,23 @@ bool remove_const_function_pointerst::try_resolve_function_call( else if(simplified_expr.id()==ID_member) { const member_exprt &member_expr=to_member_expr(simplified_expr); - const exprt &owner_expr=member_expr.compound(); - // Squash the struct - expressionst out_expressions; - bool struct_is_const=false; - bool resolved= - try_resolve_expression(owner_expr, out_expressions, struct_is_const); - if(resolved) - { - for(const exprt &expression:out_expressions) - { - if(expression.id()!=ID_struct) - { - LOG("Squash of member access didn't result in a struct", expression); - return false; - } - else - { - const struct_exprt &struct_expr=to_struct_expr(expression); - const exprt &component_value= - get_component_value(struct_expr, member_expr); - - if(struct_is_const) - { - functionst component_functions; - bool resolved= - try_resolve_function_call(component_value, component_functions); - if(resolved) - { - out_functions.insert( - component_functions.begin(), component_functions.end()); - } - else - { - LOG( - "Couldn't resolve functions call from component value", - component_value); - return false; - } - } - else - { - LOG( - "Struct was not const so can't resolve values on it", - struct_expr); - return false; - } - } - } - - return true; - - } - else - { - LOG("Failed to squash struct member access", owner_expr); - return false; - } + return try_resolve_member_function_call(member_expr, out_functions); } else if(simplified_expr.id()==ID_address_of) { address_of_exprt address_expr=to_address_of_expr(simplified_expr); - bool resolved= - try_resolve_function_call(address_expr.object(), out_functions); - if(!resolved) - { - LOG("Failed to resolve address of", address_expr); - } - return resolved; + return try_resolve_address_of_function_call( + address_expr, out_functions); } else if(simplified_expr.id()==ID_dereference) { - // We had a pointer, we need to check both the pointer - // type can't be changed, and what it what pointing to - // can't be changed const dereference_exprt &deref=to_dereference_expr(simplified_expr); - expressionst pointer_values; - bool pointer_const; - bool resolved= - try_resolve_expression(deref.pointer(), pointer_values, pointer_const); - - // Here we require that the value we are dereferencing is const - // The actual type doesn't matter since we are on the RHS so what matters - // is where this gets stored, but the value stored matters - if(resolved && pointer_const) - { - for(const exprt &pointer_val : pointer_values) - { - if(pointer_val.id()==ID_address_of) - { - address_of_exprt address_expr=to_address_of_expr(pointer_val); - functionst out_object_values; - bool resolved= - try_resolve_function_call( - address_expr.object(), out_object_values); - - if(resolved) - { - out_functions.insert( - out_object_values.begin(), - out_object_values.end()); - } - else - { - LOG("Failed to resolver pointers value", address_expr); - return false; - } - } - else - { - LOG( - "Squashing dereference did not result in an address of", - pointer_val); - return false; - } - } - return true; - } - else - { - if(!resolved) - { - LOG("Failed to squash dereference", deref); - } - else if(!pointer_const) - { - LOG("Dereferenced value was not const so can't dereference", deref); - } - return false; - } + return try_resolve_dereference_function_call(deref, out_functions); } else if(simplified_expr.id()==ID_typecast) { - // We simply ignore typecasts and assume they are valid - // I thought simplify_expr would deal with this, but for example - // a cast from a 32 bit width int to a 64bit width int it doesn't seem - // to allow typecast_exprt typecast_expr=to_typecast_expr(simplified_expr); - functionst typecast_values; - bool resolved= - try_resolve_function_call(typecast_expr.op(), typecast_values); - - if(resolved) - { - out_functions.insert(typecast_values.begin(), typecast_values.end()); - return true; - } - else - { - LOG("Failed to squash typecast", simplified_expr); - return false; - } + return try_resolve_typecast_function_call(typecast_expr, out_functions); } else if(simplified_expr.id()==ID_symbol) { @@ -411,6 +277,237 @@ bool remove_const_function_pointerst::try_resolve_index_of_function_call( /*******************************************************************\ +Function: remove_const_function_pointerst::try_resolve_member_function_call + + Inputs: + member_expr - The member expression to resolve to possible function calls + out_functions - The functions this expression could be + + Outputs: Returns true if it was able to resolve the member expression to some + specific functions. If this is the case, out_functions will contain + the possible functions. + + Purpose: To resolve an expression to the specific function calls it can + be. Specifically, this function deals with member expressions + by using try_resolve_member and then recursing on its value. + +\*******************************************************************/ + +bool remove_const_function_pointerst::try_resolve_member_function_call( + const member_exprt &member_expr, functionst &out_functions) +{ + const exprt &owner_expr=member_expr.compound(); + // Squash the struct + expressionst out_expressions; + bool struct_is_const=false; + bool resolved= + try_resolve_expression(owner_expr, out_expressions, struct_is_const); + if(resolved) + { + for(const exprt &expression:out_expressions) + { + if(expression.id()!=ID_struct) + { + LOG("Squash of member access didn't result in a struct", expression); + return false; + } + else + { + const struct_exprt &struct_expr=to_struct_expr(expression); + const exprt &component_value= + get_component_value(struct_expr, member_expr); + + if(struct_is_const) + { + functionst component_functions; + bool resolved= + try_resolve_function_call(component_value, component_functions); + if(resolved) + { + out_functions.insert( + component_functions.begin(), component_functions.end()); + } + else + { + LOG( + "Couldn't resolve functions call from component value", + component_value); + return false; + } + } + else + { + LOG( + "Struct was not const so can't resolve values on it", + struct_expr); + return false; + } + } + } + + return true; + + } + else + { + LOG("Failed to squash struct member access", owner_expr); + return false; + } +} + +/*******************************************************************\ + +Function: remove_const_function_pointerst::try_resolve_address_of_function_call + + Inputs: + address_expr - The address_of expression to resolve to possible function + calls + out_functions - The functions this expression could be + + Outputs: Returns true if it was able to resolve the address_of expression to + some specific functions. If this is the case, out_functions will + contain the possible functions. + + Purpose: To resolve an expression to the specific function calls it can + be. Specifically, this function deals with address_os expressions. + +\*******************************************************************/ + +bool remove_const_function_pointerst::try_resolve_address_of_function_call( + const address_of_exprt &address_expr, functionst &out_functions) +{ + bool resolved= + try_resolve_function_call(address_expr.object(), out_functions); + if(!resolved) + { + LOG("Failed to resolve address of", address_expr); + } + return resolved; +} + +/*******************************************************************\ + +Function: remove_const_function_pointerst::try_resolve_dereference_function_call + + Inputs: + deref_expr - The dereference expression to resolve to possible function calls + out_functions - The functions this expression could be + + Outputs: Returns true if it was able to resolve the dereference expression to + some specific functions. If this is the case, out_functions will + contain the possible functions. + + Purpose: To resolve an expression to the specific function calls it can + be. Specifically, this function deals with dereference expressions + by using try_resolve_dereferebce and then recursing on its value. + +\*******************************************************************/ + +bool remove_const_function_pointerst::try_resolve_dereference_function_call( + const dereference_exprt &deref, functionst &out_functions) +{ + // We had a pointer, we need to check both the pointer + // type can't be changed, and what it what pointing to + // can't be changed + expressionst pointer_values; + bool pointer_const; + bool resolved= + try_resolve_expression(deref.pointer(), pointer_values, pointer_const); + + // Here we require that the value we are dereferencing is const + // The actual type doesn't matter since we are on the RHS so what matters + // is where this gets stored, but the value stored matters + if(resolved && pointer_const) + { + for(const exprt &pointer_val : pointer_values) + { + if(pointer_val.id()==ID_address_of) + { + address_of_exprt address_expr=to_address_of_expr(pointer_val); + functionst out_object_values; + bool resolved= + try_resolve_function_call( + address_expr.object(), out_object_values); + + if(resolved) + { + out_functions.insert( + out_object_values.begin(), + out_object_values.end()); + } + else + { + LOG("Failed to resolver pointers value", address_expr); + return false; + } + } + else + { + LOG( + "Squashing dereference did not result in an address of", + pointer_val); + return false; + } + } + return true; + } + else + { + if(!resolved) + { + LOG("Failed to squash dereference", deref); + } + else if(!pointer_const) + { + LOG("Dereferenced value was not const so can't dereference", deref); + } + return false; + } +} + +/*******************************************************************\ + +Function: remove_const_function_pointerst::try_resolve_typecast_function_call + + Inputs: + typecast_expr - The typecast expression to resolve to possible function calls + out_functions - The functions this expression could be + + Outputs: Returns true if it was able to resolve the typecast expression to + some specific functions. If this is the case, out_functions will + contain the possible functions. + + Purpose: To resolve an expression to the specific function calls it can + be. Specifically, this function deals with typecast expressions + by looking at the type cast values. + +\*******************************************************************/ + +bool remove_const_function_pointerst::try_resolve_typecast_function_call( + const typecast_exprt &typecast_expr, functionst &out_functions) +{ + // We simply ignore typecasts and assume they are valid + // I thought simplify_expr would deal with this, but for example + // a cast from a 32 bit width int to a 64bit width int it doesn't seem + // to allow + functionst typecast_values; + bool resolved= + try_resolve_function_call(typecast_expr.op(), typecast_values); + + if(resolved) + { + out_functions.insert(typecast_values.begin(), typecast_values.end()); + return true; + } + else + { + LOG("Failed to squash typecast", typecast_expr); + return false; + } +} + +/*******************************************************************\ + Function: remove_const_function_pointerst::try_resolve_expression Inputs: diff --git a/src/goto-programs/remove_const_function_pointers.h b/src/goto-programs/remove_const_function_pointers.h index e8600b9c3be..be7a18badbc 100644 --- a/src/goto-programs/remove_const_function_pointers.h +++ b/src/goto-programs/remove_const_function_pointers.h @@ -38,6 +38,18 @@ class remove_const_function_pointerst:public messaget bool try_resolve_index_of_function_call( const index_exprt &index_expr, functionst &out_functions); + bool try_resolve_member_function_call( + const member_exprt &member_expr, functionst &out_functions); + + bool try_resolve_address_of_function_call( + const address_of_exprt &address_expr, functionst &out_functions); + + bool try_resolve_dereference_function_call( + const dereference_exprt &deref, functionst &out_functions); + + bool try_resolve_typecast_function_call( + const typecast_exprt &typecast_expr, functionst &out_functions); + // recursive functions for dealing with the auxiliary elements bool try_resolve_expression( const exprt &expr, From 5d33d4d576aeff79cf55543017ccb9256e7acf7b Mon Sep 17 00:00:00 2001 From: thk123 Date: Fri, 10 Feb 2017 16:14:04 +0000 Subject: [PATCH 30/46] Made the behaviour of try_resolve_function_call clearer Rather than sometimes using the array directly, other times checking it, use and having lots of exit points to the function, all steps use same interface and work in the same way with arrays. --- .../remove_const_function_pointers.cpp | 42 ++++++++++++------- .../remove_const_function_pointers.h | 2 +- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 0ffff170e0b..1711e0ed3fa 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -170,51 +170,65 @@ Function: remove_const_function_pointerst::try_resolve_function_call \*******************************************************************/ bool remove_const_function_pointerst::try_resolve_function_call( - const exprt &expr, remove_const_function_pointerst::functionst &out_functions) + const exprt &expr, functionst &out_functions) { + assert(out_functions.empty()); const exprt &simplified_expr=simplify_expr(expr, ns); + bool resolved=false; + functionst resolved_functions; if(simplified_expr.id()==ID_index) { const index_exprt &index_expr=to_index_expr(simplified_expr); - return try_resolve_index_of_function_call(index_expr, out_functions); + resolved=try_resolve_index_of_function_call(index_expr, resolved_functions); } else if(simplified_expr.id()==ID_member) { const member_exprt &member_expr=to_member_expr(simplified_expr); - return try_resolve_member_function_call(member_expr, out_functions); + resolved=try_resolve_member_function_call(member_expr, resolved_functions); } else if(simplified_expr.id()==ID_address_of) { address_of_exprt address_expr=to_address_of_expr(simplified_expr); - return try_resolve_address_of_function_call( - address_expr, out_functions); + resolved=try_resolve_address_of_function_call( + address_expr, resolved_functions); } else if(simplified_expr.id()==ID_dereference) { const dereference_exprt &deref=to_dereference_expr(simplified_expr); - return try_resolve_dereference_function_call(deref, out_functions); + resolved=try_resolve_dereference_function_call(deref, resolved_functions); } else if(simplified_expr.id()==ID_typecast) { typecast_exprt typecast_expr=to_typecast_expr(simplified_expr); - return try_resolve_typecast_function_call(typecast_expr, out_functions); + resolved= + try_resolve_typecast_function_call(typecast_expr, resolved_functions); } else if(simplified_expr.id()==ID_symbol) { if(simplified_expr.type().id()==ID_code) { - out_functions.insert(simplified_expr); - return true; + resolved_functions.insert(simplified_expr); + resolved=true; } else { LOG("Non const symbol wasn't squashed", simplified_expr); - return false; + resolved=false; } } else { LOG("Unrecognised expression", simplified_expr); + resolved=false; + } + + if(resolved) + { + out_functions.insert(resolved_functions.begin(), resolved_functions.end()); + return true; + } + else + { return false; } } @@ -404,7 +418,7 @@ Function: remove_const_function_pointerst::try_resolve_dereference_function_call \*******************************************************************/ bool remove_const_function_pointerst::try_resolve_dereference_function_call( - const dereference_exprt &deref, functionst &out_functions) + const dereference_exprt &deref_expr, functionst &out_functions) { // We had a pointer, we need to check both the pointer // type can't be changed, and what it what pointing to @@ -412,7 +426,7 @@ bool remove_const_function_pointerst::try_resolve_dereference_function_call( expressionst pointer_values; bool pointer_const; bool resolved= - try_resolve_expression(deref.pointer(), pointer_values, pointer_const); + try_resolve_expression(deref_expr.pointer(), pointer_values, pointer_const); // Here we require that the value we are dereferencing is const // The actual type doesn't matter since we are on the RHS so what matters @@ -455,11 +469,11 @@ bool remove_const_function_pointerst::try_resolve_dereference_function_call( { if(!resolved) { - LOG("Failed to squash dereference", deref); + LOG("Failed to squash dereference", deref_expr); } else if(!pointer_const) { - LOG("Dereferenced value was not const so can't dereference", deref); + LOG("Dereferenced value was not const so can't dereference", deref_expr); } return false; } diff --git a/src/goto-programs/remove_const_function_pointers.h b/src/goto-programs/remove_const_function_pointers.h index be7a18badbc..3d47e0d5f94 100644 --- a/src/goto-programs/remove_const_function_pointers.h +++ b/src/goto-programs/remove_const_function_pointers.h @@ -45,7 +45,7 @@ class remove_const_function_pointerst:public messaget const address_of_exprt &address_expr, functionst &out_functions); bool try_resolve_dereference_function_call( - const dereference_exprt &deref, functionst &out_functions); + const dereference_exprt &deref_expr, functionst &out_functions); bool try_resolve_typecast_function_call( const typecast_exprt &typecast_expr, functionst &out_functions); From a75957bf3fed937568b0ccf977c113426df2a8c4 Mon Sep 17 00:00:00 2001 From: thk123 Date: Fri, 10 Feb 2017 16:14:45 +0000 Subject: [PATCH 31/46] Split up try_resolve_expression into functions --- .../remove_const_function_pointers.cpp | 398 +++++++++++------- .../remove_const_function_pointers.h | 21 +- 2 files changed, 258 insertions(+), 161 deletions(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 1711e0ed3fa..0cd450a3935 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -383,7 +383,7 @@ Function: remove_const_function_pointerst::try_resolve_address_of_function_call contain the possible functions. Purpose: To resolve an expression to the specific function calls it can - be. Specifically, this function deals with address_os expressions. + be. Specifically, this function deals with address_of expressions. \*******************************************************************/ @@ -551,185 +551,61 @@ bool remove_const_function_pointerst::try_resolve_expression( const exprt &expr, expressionst &out_resolved_expression, bool &out_is_const) { const exprt &simplified_expr=simplify_expr(expr, ns); + bool resolved; + expressionst resolved_expressions; + bool is_resolved_expression_const; if(simplified_expr.id()==ID_index) { const index_exprt &index_expr=to_index_expr(simplified_expr); - expressionst out_array_expressions; - bool resolved_array= - try_resolve_index_of(index_expr, out_array_expressions, out_is_const); - - if(resolved_array) - { - out_resolved_expression.insert( - out_resolved_expression.end(), - out_array_expressions.begin(), - out_array_expressions.end()); - } - else - { - LOG("Could not resolve array", index_expr); - } - - return resolved_array; + resolved= + try_resolve_index_of( + index_expr, resolved_expressions, is_resolved_expression_const); } else if(simplified_expr.id()==ID_member) { - // Get the component it belongs to const member_exprt &member_expr=to_member_expr(simplified_expr); - - expressionst potential_structs; - bool is_struct_const; - bool resolved_struct= - try_resolve_expression( - member_expr.compound(), potential_structs, is_struct_const); - - if(resolved_struct) - { - for(const exprt &potential_struct : potential_structs) - { - if(potential_struct.id()==ID_struct) - { - struct_exprt struct_expr=to_struct_expr(potential_struct); - const exprt &component_value= - get_component_value(struct_expr, member_expr); - - expressionst out_expressions; - bool component_const=false; - bool resolved= - try_resolve_expression( - component_value, out_expressions, component_const); - if(resolved) - { - out_resolved_expression.insert( - out_resolved_expression.end(), - out_expressions.begin(), - out_expressions.end()); - } - else - { - LOG("Could not resolve component value", component_value); - return false; - } - } - else - { - LOG( - "Squashing member access did not resolve in a struct", - potential_struct); - return false; - } - } - out_is_const=is_struct_const; - return true; - } - else - { - LOG("Failed to squash struct access", member_expr); - return false; - } + resolved=try_resolve_member( + member_expr, resolved_expressions, is_resolved_expression_const); } else if(simplified_expr.id()==ID_dereference) { - // We had a pointer, we need to check both the pointer - // type can't be changed, and what it what pointing to - // can't be changed const dereference_exprt &deref=to_dereference_expr(simplified_expr); - expressionst pointer_values; - bool pointer_const; - bool resolved= - try_resolve_expression(deref.pointer(), pointer_values, pointer_const); - if(resolved && pointer_const) - { - bool all_objects_const=true; - for(const exprt &pointer_val : pointer_values) - { - if(pointer_val.id()==ID_address_of) - { - address_of_exprt address_expr=to_address_of_expr(pointer_val); - bool object_const=false; - expressionst out_object_values; - bool resolved= - try_resolve_expression( - address_expr.object(), out_object_values, object_const); - - if(resolved) - { - out_resolved_expression.insert( - out_resolved_expression.end(), - out_object_values.begin(), - out_object_values.end()); - - all_objects_const&=object_const; - } - else - { - LOG("Failed to resolve value of a dereference", address_expr); - } - } - else - { - LOG( - "Squashing dereference did not result in an address", pointer_val); - return false; - } - } - out_is_const=all_objects_const; - return true; - } - else - { - if(!resolved) - { - LOG("Failed to resolve pointer of dereference", deref); - } - else if(!pointer_const) - { - LOG("Pointer value not const so can't squash", deref); - } - return false; - } + resolved= + try_resolve_dereference( + deref, resolved_expressions, is_resolved_expression_const); } else if(simplified_expr.id()==ID_typecast) { - // We simply ignore typecasts and assume they are valid - // I thought simplify_expr would deal with this, but for example - // a cast from a 32 bit width int to a 64bit width int it doesn't seem - // to allow typecast_exprt typecast_expr=to_typecast_expr(simplified_expr); - expressionst typecast_values; - bool typecast_const; - bool resolved= - try_resolve_expression( - typecast_expr.op(), typecast_values, typecast_const); - - if(resolved) - { - out_resolved_expression.insert( - out_resolved_expression.end(), - typecast_values.begin(), - typecast_values.end()); - out_is_const=typecast_const; - return true; - } - else - { - LOG("Could not resolve typecast value", typecast_expr); - return false; - } + resolved= + try_resolve_typecast( + typecast_expr, resolved_expressions, is_resolved_expression_const); } else if(simplified_expr.id()==ID_symbol) { LOG("Non const symbol will not be squashed", simplified_expr); - return false; + resolved=false; } - // TOOD: probably need to do something with pointers or address_of - // and const since a const pointer to a non-const value is useless else { - out_is_const=is_expression_const(simplified_expr); - out_resolved_expression.push_back(simplified_expr); + resolved_expressions.push_back(simplified_expr); + is_resolved_expression_const=is_expression_const(simplified_expr); + resolved=true; + } + + if(resolved) + { + out_resolved_expression.insert( + out_resolved_expression.end(), + resolved_expressions.begin(), + resolved_expressions.end()); + out_is_const=is_resolved_expression_const; return true; } + else + { + return false; + } } /*******************************************************************\ @@ -788,8 +664,8 @@ bool remove_const_function_pointerst::try_resolve_index_value( Function: remove_const_function_pointerst::try_resolve_index_of Inputs: - index_expr - The index expression to to resolve to possible function calls - out_expressions - The functions this expression could be + index_expr - The index expression to to resolve + out_expressions - The expressions this expression could be out_is_const - Is the squashed expression constant Outputs: Returns true if it was able to squash the index expression @@ -909,6 +785,212 @@ bool remove_const_function_pointerst::try_resolve_index_of( /*******************************************************************\ +Function: remove_const_function_pointerst::try_resolve_member + + Inputs: + member_expr - The member expression to resolve. + out_expressions - The expressions this component could be + out_is_const - Is the squashed expression constant + + Outputs: Returns true if it was able to squash the member expression + If this is the case, out_expressions will contain + the possible values this member could return + The out_is_const will return whether the struct + is const. + + Purpose: To squash an member access by first finding the struct it is accessing + Then return the squashed value of the relevant component. + +\*******************************************************************/ + +bool remove_const_function_pointerst::try_resolve_member( + const member_exprt &member_expr, + expressionst &out_expressions, + bool &out_is_const) +{ + expressionst potential_structs; + bool is_struct_const; + + // Get the struct it belongs to + bool resolved_struct= + try_resolve_expression( + member_expr.compound(), potential_structs, is_struct_const); + if(resolved_struct) + { + for(const exprt &potential_struct : potential_structs) + { + if(potential_struct.id()==ID_struct) + { + struct_exprt struct_expr=to_struct_expr(potential_struct); + const exprt &component_value= + get_component_value(struct_expr, member_expr); + expressionst resolved_expressions; + bool component_const=false; + bool resolved= + try_resolve_expression( + component_value, resolved_expressions, component_const); + if(resolved) + { + out_expressions.insert( + out_expressions.end(), + resolved_expressions.begin(), + resolved_expressions.end()); + } + else + { + LOG("Could not resolve component value", component_value); + return false; + } + } + else + { + LOG( + "Squashing member access did not resolve in a struct", + potential_struct); + return false; + } + } + out_is_const=is_struct_const; + return true; + } + else + { + LOG("Failed to squash struct access", member_expr); + return false; + } +} + +/*******************************************************************\ + +Function: remove_const_function_pointerst::try_resolve_dereference + + Inputs: + deref_expr - The dereference expression to resolve. + out_expressions - The expressions this dereference could be + out_is_const - Is the squashed expression constant + + Outputs: Returns true if it was able to squash the dereference expression + If this is the case, out_expressions will contain + the possible values this dereference could return + The out_is_const will return whether the object that gets + dereferenced is constant. + + Purpose: To squash a dereference access by first finding the address_of + the dereference is dereferencing. + Then return the squashed value of the relevant component. + +\*******************************************************************/ + +bool remove_const_function_pointerst::try_resolve_dereference( + const dereference_exprt &deref_expr, + expressionst &out_expressions, + bool &out_is_const) +{ + // We had a pointer, we need to check both the pointer + // type can't be changed, and what it what pointing to + // can't be changed + expressionst pointer_values; + bool pointer_const; + bool resolved= + try_resolve_expression(deref_expr.pointer(), pointer_values, pointer_const); + if(resolved && pointer_const) + { + bool all_objects_const=true; + for(const exprt &pointer_val : pointer_values) + { + if(pointer_val.id()==ID_address_of) + { + address_of_exprt address_expr=to_address_of_expr(pointer_val); + bool object_const=false; + expressionst out_object_values; + bool resolved= + try_resolve_expression( + address_expr.object(), out_object_values, object_const); + + if(resolved) + { + out_expressions.insert( + out_expressions.end(), + out_object_values.begin(), + out_object_values.end()); + + all_objects_const&=object_const; + } + else + { + LOG("Failed to resolve value of a dereference", address_expr); + } + } + else + { + LOG( + "Squashing dereference did not result in an address", pointer_val); + return false; + } + } + out_is_const=all_objects_const; + return true; + } + else + { + if(!resolved) + { + LOG("Failed to resolve pointer of dereference", deref_expr); + } + else if(!pointer_const) + { + LOG("Pointer value not const so can't squash", deref_expr); + } + return false; + } +} + +/*******************************************************************\ + +Function: remove_const_function_pointerst::try_resolve_dereference + + Inputs: + typecast_expr - The typecast expression to resolve. + out_expressions - The expressions this typecast could be + out_is_const - Is the squashed expression constant + + Outputs: Returns true if it was able to squash the typecast expression + If this is the case, out_expressions will contain + the possible values after removing the typecast. + + Purpose: To squash a typecast access. + +\*******************************************************************/ + +bool remove_const_function_pointerst::try_resolve_typecast( + const typecast_exprt &typecast_expr, + expressionst &out_expressions, + bool &out_is_const) +{ + expressionst typecast_values; + bool typecast_const; + bool resolved= + try_resolve_expression( + typecast_expr.op(), typecast_values, typecast_const); + + if(resolved) + { + out_expressions.insert( + out_expressions.end(), + typecast_values.begin(), + typecast_values.end()); + out_is_const=typecast_const; + return true; + } + else + { + LOG("Could not resolve typecast value", typecast_expr); + return false; + } +} + +/*******************************************************************\ + Function: remove_const_function_pointerst::is_expression_const Inputs: diff --git a/src/goto-programs/remove_const_function_pointers.h b/src/goto-programs/remove_const_function_pointers.h index 3d47e0d5f94..ae212e863f1 100644 --- a/src/goto-programs/remove_const_function_pointers.h +++ b/src/goto-programs/remove_const_function_pointers.h @@ -56,17 +56,32 @@ class remove_const_function_pointerst:public messaget expressionst &out_resolved_expression, bool &out_is_const); - bool try_resolve_index_value( - const exprt &index_value_expr, mp_integer &out_array_index); - bool try_resolve_index_of( const index_exprt &index_expr, expressionst &out_expressions, bool &out_is_const); + bool try_resolve_member( + const member_exprt &member_expr, + expressionst &out_expressions, + bool &out_is_const); + + bool try_resolve_dereference( + const dereference_exprt &deref_expr, + expressionst &out_expressions, + bool &out_is_const); + + bool try_resolve_typecast( + const typecast_exprt &typecast_expr, + expressionst &out_expressions, + bool &out_is_const); + bool is_expression_const(const exprt &expression) const; bool is_type_const(const typet &type) const; + bool try_resolve_index_value( + const exprt &index_value_expr, mp_integer &out_array_index); + exprt get_component_value( const struct_exprt &struct_expr, const member_exprt &member_expr); From 37660b16674d7c7547804050523ef2ac5c862e10 Mon Sep 17 00:00:00 2001 From: thk123 Date: Fri, 10 Feb 2017 16:37:25 +0000 Subject: [PATCH 32/46] Made other try_resolve*_function_call use the normal method --- .../remove_const_function_pointers.cpp | 202 +++++++----------- 1 file changed, 82 insertions(+), 120 deletions(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 0cd450a3935..989dd6c57de 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -259,34 +259,40 @@ bool remove_const_function_pointerst::try_resolve_index_of_function_call( { expressionst potential_array_values; bool array_const; - try_resolve_index_of(index_expr, potential_array_values, array_const); - if(array_const) - { - for(const exprt &array_value : potential_array_values) - { - functionst array_out_functions; - bool resolved_value= - try_resolve_function_call(array_value, array_out_functions); + bool resolved= + try_resolve_index_of(index_expr, potential_array_values, array_const); - if(resolved_value) - { - out_functions.insert( - array_out_functions.begin(), - array_out_functions.end()); - } - else - { - LOG("Could not resolve expression in array", array_value); - return false; - } - } - return true; + if(!resolved) + { + LOG("Could not resolve array", index_expr); + return false; } - else + + if(!array_const) { - LOG("Could not resolve arary", index_expr); + LOG("Array not const", index_expr); return false; } + + for(const exprt &array_value : potential_array_values) + { + functionst array_out_functions; + bool resolved_value= + try_resolve_function_call(array_value, array_out_functions); + + if(resolved_value) + { + out_functions.insert( + array_out_functions.begin(), + array_out_functions.end()); + } + else + { + LOG("Could not resolve expression in array", array_value); + return false; + } + } + return true; } /*******************************************************************\ @@ -310,63 +316,41 @@ Function: remove_const_function_pointerst::try_resolve_member_function_call bool remove_const_function_pointerst::try_resolve_member_function_call( const member_exprt &member_expr, functionst &out_functions) { - const exprt &owner_expr=member_expr.compound(); - // Squash the struct - expressionst out_expressions; - bool struct_is_const=false; + expressionst potential_component_values; + bool struct_const; bool resolved= - try_resolve_expression(owner_expr, out_expressions, struct_is_const); - if(resolved) - { - for(const exprt &expression:out_expressions) - { - if(expression.id()!=ID_struct) - { - LOG("Squash of member access didn't result in a struct", expression); - return false; - } - else - { - const struct_exprt &struct_expr=to_struct_expr(expression); - const exprt &component_value= - get_component_value(struct_expr, member_expr); - - if(struct_is_const) - { - functionst component_functions; - bool resolved= - try_resolve_function_call(component_value, component_functions); - if(resolved) - { - out_functions.insert( - component_functions.begin(), component_functions.end()); - } - else - { - LOG( - "Couldn't resolve functions call from component value", - component_value); - return false; - } - } - else - { - LOG( - "Struct was not const so can't resolve values on it", - struct_expr); - return false; - } - } - } - - return true; + try_resolve_member(member_expr, potential_component_values, struct_const); + if(!resolved) + { + LOG("Could not resolve struct", member_expr); + return false; } - else + + if(!struct_const) { - LOG("Failed to squash struct member access", owner_expr); + LOG("Struct was not const so can't resolve values on it", member_expr); return false; } + + for(const exprt &struct_component_value : potential_component_values) + { + functionst struct_out_functions; + bool resolved_value= + try_resolve_function_call(struct_component_value, struct_out_functions); + + if(resolved_value) + { + out_functions.insert( + struct_out_functions.begin(), struct_out_functions.end()); + } + else + { + LOG("Could not resolve expression in array", struct_component_value); + return false; + } + } + return true; } /*******************************************************************\ @@ -420,63 +404,41 @@ Function: remove_const_function_pointerst::try_resolve_dereference_function_call bool remove_const_function_pointerst::try_resolve_dereference_function_call( const dereference_exprt &deref_expr, functionst &out_functions) { - // We had a pointer, we need to check both the pointer - // type can't be changed, and what it what pointing to - // can't be changed - expressionst pointer_values; - bool pointer_const; + expressionst potential_deref_values; + bool deref_const; bool resolved= - try_resolve_expression(deref_expr.pointer(), pointer_values, pointer_const); + try_resolve_dereference(deref_expr, potential_deref_values, deref_const); - // Here we require that the value we are dereferencing is const - // The actual type doesn't matter since we are on the RHS so what matters - // is where this gets stored, but the value stored matters - if(resolved && pointer_const) + if(!resolved) { - for(const exprt &pointer_val : pointer_values) - { - if(pointer_val.id()==ID_address_of) - { - address_of_exprt address_expr=to_address_of_expr(pointer_val); - functionst out_object_values; - bool resolved= - try_resolve_function_call( - address_expr.object(), out_object_values); + LOG("Failed to squash dereference", deref_expr); + return false; + } - if(resolved) - { - out_functions.insert( - out_object_values.begin(), - out_object_values.end()); - } - else - { - LOG("Failed to resolver pointers value", address_expr); - return false; - } - } - else - { - LOG( - "Squashing dereference did not result in an address of", - pointer_val); - return false; - } - } - return true; + if(!deref_const) + { + LOG("Dereferenced value was not const so can't dereference", deref_expr); + return false; } - else + + for(const exprt &deref_value : potential_deref_values) { - if(!resolved) + functionst struct_out_functions; + bool resolved_value= + try_resolve_function_call(deref_value, struct_out_functions); + + if(resolved_value) { - LOG("Failed to squash dereference", deref_expr); + out_functions.insert( + struct_out_functions.begin(), struct_out_functions.end()); } - else if(!pointer_const) + else { - LOG("Dereferenced value was not const so can't dereference", deref_expr); + LOG("Could not resolve expression after dereference", deref_value); + return false; } - return false; } + return true; } /*******************************************************************\ From 83622336d158763218e90ee547e8e91d95321f3c Mon Sep 17 00:00:00 2001 From: thk123 Date: Fri, 10 Feb 2017 16:53:06 +0000 Subject: [PATCH 33/46] Extracted element dealing with calling resolve on each result --- .../remove_const_function_pointers.cpp | 99 +++++++++---------- .../remove_const_function_pointers.h | 3 + 2 files changed, 47 insertions(+), 55 deletions(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index 989dd6c57de..f61aa2c86e5 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -235,6 +235,47 @@ bool remove_const_function_pointerst::try_resolve_function_call( /*******************************************************************\ +Function: remove_const_function_pointerst::try_resolve_function_calls + + Inputs: + exprs - The expressions to evaluate + out_functions - The functions these expressions resolve to + + Outputs: Returns true if able to resolve each of the expressions down + to one or more functions. + + Purpose: To resolve a collection of expressions to the specific function + calls they can be. Returns a collection if and only if all of + them can be resolved. + +\*******************************************************************/ + +bool remove_const_function_pointerst::try_resolve_function_calls( + const expressionst &exprs, functionst &out_functions) +{ + for(const exprt &value : exprs) + { + functionst potential_out_functions; + bool resolved_value= + try_resolve_function_call(value, potential_out_functions); + + if(resolved_value) + { + out_functions.insert( + potential_out_functions.begin(), + potential_out_functions.end()); + } + else + { + LOG("Could not resolve expression in array", value); + return false; + } + } + return true; +} + +/*******************************************************************\ + Function: remove_const_function_pointerst::try_resolve_index_of_function_call Inputs: @@ -274,25 +315,7 @@ bool remove_const_function_pointerst::try_resolve_index_of_function_call( return false; } - for(const exprt &array_value : potential_array_values) - { - functionst array_out_functions; - bool resolved_value= - try_resolve_function_call(array_value, array_out_functions); - - if(resolved_value) - { - out_functions.insert( - array_out_functions.begin(), - array_out_functions.end()); - } - else - { - LOG("Could not resolve expression in array", array_value); - return false; - } - } - return true; + return try_resolve_function_calls(potential_array_values, out_functions); } /*******************************************************************\ @@ -333,24 +356,7 @@ bool remove_const_function_pointerst::try_resolve_member_function_call( return false; } - for(const exprt &struct_component_value : potential_component_values) - { - functionst struct_out_functions; - bool resolved_value= - try_resolve_function_call(struct_component_value, struct_out_functions); - - if(resolved_value) - { - out_functions.insert( - struct_out_functions.begin(), struct_out_functions.end()); - } - else - { - LOG("Could not resolve expression in array", struct_component_value); - return false; - } - } - return true; + return try_resolve_function_calls(potential_component_values, out_functions); } /*******************************************************************\ @@ -421,24 +427,7 @@ bool remove_const_function_pointerst::try_resolve_dereference_function_call( return false; } - for(const exprt &deref_value : potential_deref_values) - { - functionst struct_out_functions; - bool resolved_value= - try_resolve_function_call(deref_value, struct_out_functions); - - if(resolved_value) - { - out_functions.insert( - struct_out_functions.begin(), struct_out_functions.end()); - } - else - { - LOG("Could not resolve expression after dereference", deref_value); - return false; - } - } - return true; + return try_resolve_function_calls(potential_deref_values, out_functions); } /*******************************************************************\ diff --git a/src/goto-programs/remove_const_function_pointers.h b/src/goto-programs/remove_const_function_pointers.h index ae212e863f1..74b34a28e9d 100644 --- a/src/goto-programs/remove_const_function_pointers.h +++ b/src/goto-programs/remove_const_function_pointers.h @@ -35,6 +35,9 @@ class remove_const_function_pointerst:public messaget // recursive functions for dealing with the function pointer bool try_resolve_function_call(const exprt &expr, functionst &out_functions); + bool try_resolve_function_calls( + const expressionst &exprs, functionst &out_functions); + bool try_resolve_index_of_function_call( const index_exprt &index_expr, functionst &out_functions); From e57677ee603bbd877dcb5aff23c38332c8d4f293 Mon Sep 17 00:00:00 2001 From: thk123 Date: Mon, 13 Feb 2017 10:20:17 +0000 Subject: [PATCH 34/46] Adding the pointer check flag To handle the cases where the function pointer is null, we enable the pointer--check flag. This asserts that one of the branches is taken (e.g. a valid function pointer). This wasn't supported by goto-analyze so added the option to it. --- .../goto-analyzer/approx-array-variable-const-fp/test.desc | 2 +- .../approx-const-fp-array-variable-cast-const-fp/test.desc | 2 +- .../test.desc | 2 +- .../approx-const-fp-array-variable-const-fp/test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../no-match-const-fp-array-literal-non-const-fp/test.desc | 2 +- .../no-match-const-fp-array-non-const-fp/test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../no-match-const-fp-dynamic-array-non-const-fp/test.desc | 2 +- .../no-match-const-fp-non-const-fp-direct-assignment/test.desc | 2 +- .../test.desc | 2 +- .../no-match-const-fp-non-const-struct-const-fp/test.desc | 2 +- .../no-match-const-fp-non-const-struct-non-const-fp/test.desc | 2 +- .../no-match-const-pointer-non-const-struct-const-fp/test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../no-match-non-const-fp-const-fp-direct-assignment/test.desc | 2 +- regression/goto-analyzer/no-match-non-const-fp/test.desc | 2 +- regression/goto-analyzer/no-match-parameter-const-fp/test.desc | 2 +- regression/goto-analyzer/no-match-parameter-fp/test.desc | 2 +- .../test.desc | 2 +- .../goto-analyzer/precise-array-calculation-const-fp/test.desc | 2 +- .../goto-analyzer/precise-array-literal-const-fp/test.desc | 2 +- .../precise-const-fp-array-const-variable-const-fp/test.desc | 2 +- .../precise-const-fp-array-literal-const-fp/test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- regression/goto-analyzer/precise-const-fp-const-fp/test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../precise-const-fp-const-struct-non-const-fp/test.desc | 2 +- .../test.desc | 2 +- regression/goto-analyzer/precise-const-fp/test.desc | 2 +- .../goto-analyzer/precise-const-struct-non-const-fp/test.desc | 2 +- .../precise-derefence-const-pointer-const-fp/test.desc | 2 +- regression/goto-analyzer/precise-derefence/test.desc | 2 +- .../precise-dereference-address-pointer-const-fp/test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- src/goto-analyzer/goto_analyzer_parse_options.cpp | 3 +++ src/goto-analyzer/goto_analyzer_parse_options.h | 3 +++ 48 files changed, 52 insertions(+), 46 deletions(-) diff --git a/regression/goto-analyzer/approx-array-variable-const-fp/test.desc b/regression/goto-analyzer/approx-array-variable-const-fp/test.desc index 13cac884101..e8d2128a0d0 100644 --- a/regression/goto-analyzer/approx-array-variable-const-fp/test.desc +++ b/regression/goto-analyzer/approx-array-variable-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp_tbl\[(signed long int)i\] == f2 THEN GOTO 1$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc index 05b7ce7e581..20eb8d6a109 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp == f2 THEN GOTO 1$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc index 05b7ce7e581..20eb8d6a109 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp == f2 THEN GOTO 1$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc index 05b7ce7e581..20eb8d6a109 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp == f2 THEN GOTO 1$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc index 05b7ce7e581..20eb8d6a109 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp == f2 THEN GOTO 1$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc index 05b7ce7e581..20eb8d6a109 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp == f2 THEN GOTO 1$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc index 00cd5d6eafd..082acf9a6f2 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp == (void (\*)(void))f2 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/test.desc b/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/test.desc index deda28d213f..a90040a0f82 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/test.desc b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/test.desc index deda28d213f..a90040a0f82 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/test.desc index 1942b6b867b..328eefd5fd0 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp2 == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/test.desc index 1942b6b867b..328eefd5fd0 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp2 == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/test.desc index deda28d213f..a90040a0f82 100644 --- a/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/test.desc index ff7c3cc2b07..a726957f5ee 100644 --- a/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF final_fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/test.desc index deda28d213f..a90040a0f82 100644 --- a/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/test.desc b/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/test.desc index 722b6878ab5..06f3395c5fa 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp2 == f1 THEN GOTO 1$ ^\s*IF fp2 == f2 THEN GOTO 2$ diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/test.desc index deda28d213f..a90040a0f82 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/test.desc index deda28d213f..a90040a0f82 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/test.desc index deda28d213f..a90040a0f82 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/test.desc b/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/test.desc index f199330660a..b038fb608e3 100644 --- a/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF pts->go == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/test.desc b/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/test.desc index 94f1774abb7..2fa1d08dd26 100644 --- a/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-dereference-non-const-struct-const-pointer-const-fp/test.desc b/regression/goto-analyzer/no-match-dereference-non-const-struct-const-pointer-const-fp/test.desc index 0899addb26a..1eb1dc36059 100644 --- a/regression/goto-analyzer/no-match-dereference-non-const-struct-const-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-dereference-non-const-struct-const-pointer-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF \*container_container\.container == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-dereference-non-const-struct-non-const-pointer-const-fp/test.desc b/regression/goto-analyzer/no-match-dereference-non-const-struct-non-const-pointer-const-fp/test.desc index 0899addb26a..1eb1dc36059 100644 --- a/regression/goto-analyzer/no-match-dereference-non-const-struct-non-const-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-dereference-non-const-struct-non-const-pointer-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF \*container_container\.container == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/test.desc b/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/test.desc index 722b6878ab5..06f3395c5fa 100644 --- a/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/test.desc +++ b/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp2 == f1 THEN GOTO 1$ ^\s*IF fp2 == f2 THEN GOTO 2$ diff --git a/regression/goto-analyzer/no-match-non-const-fp/test.desc b/regression/goto-analyzer/no-match-non-const-fp/test.desc index deda28d213f..a90040a0f82 100644 --- a/regression/goto-analyzer/no-match-non-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-non-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-parameter-const-fp/test.desc b/regression/goto-analyzer/no-match-parameter-const-fp/test.desc index deda28d213f..a90040a0f82 100644 --- a/regression/goto-analyzer/no-match-parameter-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-parameter-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-parameter-fp/test.desc b/regression/goto-analyzer/no-match-parameter-fp/test.desc index deda28d213f..a90040a0f82 100644 --- a/regression/goto-analyzer/no-match-parameter-fp/test.desc +++ b/regression/goto-analyzer/no-match-parameter-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF fp == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/test.desc b/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/test.desc index b53053f12a4..9ae7c264af7 100644 --- a/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f1 THEN GOTO 1$ diff --git a/regression/goto-analyzer/precise-array-calculation-const-fp/test.desc b/regression/goto-analyzer/precise-array-calculation-const-fp/test.desc index 3fb0a47980c..9716d23800e 100644 --- a/regression/goto-analyzer/precise-array-calculation-const-fp/test.desc +++ b/regression/goto-analyzer/precise-array-calculation-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f3();$ ^SIGNAL=0$ diff --git a/regression/goto-analyzer/precise-array-literal-const-fp/test.desc b/regression/goto-analyzer/precise-array-literal-const-fp/test.desc index 3fb0a47980c..9716d23800e 100644 --- a/regression/goto-analyzer/precise-array-literal-const-fp/test.desc +++ b/regression/goto-analyzer/precise-array-literal-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f3();$ ^SIGNAL=0$ diff --git a/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/test.desc index 3fb0a47980c..9716d23800e 100644 --- a/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f3();$ ^SIGNAL=0$ diff --git a/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/test.desc index 3fb0a47980c..9716d23800e 100644 --- a/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f3();$ ^SIGNAL=0$ diff --git a/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/test.desc index 77c3b9a93d1..313435441b0 100644 --- a/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f3();$ diff --git a/regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc index c78b9efabd8..5d0951328b4 100644 --- a/regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f2(); diff --git a/regression/goto-analyzer/precise-const-fp-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-const-fp/test.desc index 653466e87fb..9852b6f4f36 100644 --- a/regression/goto-analyzer/precise-const-fp-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f2();$ ^SIGNAL=0$ diff --git a/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/test.desc b/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/test.desc index 77c3b9a93d1..313435441b0 100644 --- a/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f3();$ diff --git a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/test.desc b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/test.desc index 77c3b9a93d1..313435441b0 100644 --- a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f3();$ diff --git a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/test.desc index c78b9efabd8..5d0951328b4 100644 --- a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f2(); diff --git a/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/test.desc index 77c3b9a93d1..313435441b0 100644 --- a/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f3();$ diff --git a/regression/goto-analyzer/precise-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp/test.desc index eb4d61d9d9c..8de39dddaab 100644 --- a/regression/goto-analyzer/precise-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f2(); diff --git a/regression/goto-analyzer/precise-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/precise-const-struct-non-const-fp/test.desc index c78b9efabd8..5d0951328b4 100644 --- a/regression/goto-analyzer/precise-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-struct-non-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f2(); diff --git a/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/test.desc b/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/test.desc index 77c3b9a93d1..313435441b0 100644 --- a/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f3();$ diff --git a/regression/goto-analyzer/precise-derefence/test.desc b/regression/goto-analyzer/precise-derefence/test.desc index eb4d61d9d9c..8de39dddaab 100644 --- a/regression/goto-analyzer/precise-derefence/test.desc +++ b/regression/goto-analyzer/precise-derefence/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f2(); diff --git a/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/test.desc b/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/test.desc index 77c3b9a93d1..313435441b0 100644 --- a/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f3();$ diff --git a/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-fp/test.desc b/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-fp/test.desc index 77c3b9a93d1..313435441b0 100644 --- a/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f3();$ diff --git a/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-struct-const-fp/test.desc b/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-struct-const-fp/test.desc index 77c3b9a93d1..313435441b0 100644 --- a/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-struct-const-fp/test.desc +++ b/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-struct-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f3();$ diff --git a/regression/goto-analyzer/precise-dereference-const-struct-pointer-const-fp/test.desc b/regression/goto-analyzer/precise-dereference-const-struct-pointer-const-fp/test.desc index 77c3b9a93d1..313435441b0 100644 --- a/regression/goto-analyzer/precise-dereference-const-struct-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/precise-dereference-const-struct-pointer-const-fp/test.desc @@ -1,6 +1,6 @@ CORE main.c ---show-goto-functions --verbosity 10 +--show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ ^\s*f3();$ diff --git a/src/goto-analyzer/goto_analyzer_parse_options.cpp b/src/goto-analyzer/goto_analyzer_parse_options.cpp index 10fb9d8d6d9..9a74e27f167 100644 --- a/src/goto-analyzer/goto_analyzer_parse_options.cpp +++ b/src/goto-analyzer/goto_analyzer_parse_options.cpp @@ -541,6 +541,9 @@ void goto_analyzer_parse_optionst::help() // NOLINTNEXTLINE(whitespace/line_length) " --show-properties show the properties, but don't run analysis\n" "\n" + "Program instrumentation options:\n" + HELP_GOTO_CHECK + "\n" "Other options:\n" " --version show version and exit\n" "\n"; diff --git a/src/goto-analyzer/goto_analyzer_parse_options.h b/src/goto-analyzer/goto_analyzer_parse_options.h index 7b319c8b99b..caf95254288 100644 --- a/src/goto-analyzer/goto_analyzer_parse_options.h +++ b/src/goto-analyzer/goto_analyzer_parse_options.h @@ -17,6 +17,8 @@ Author: Daniel Kroening, kroening@kroening.com #include #include +#include + class bmct; class goto_functionst; class optionst; @@ -28,6 +30,7 @@ class optionst; "(16)(32)(64)(LP64)(ILP64)(LLP64)(ILP32)(LP32)" \ "(little-endian)(big-endian)" \ OPT_SHOW_GOTO_FUNCTIONS \ + OPT_GOTO_CHECK \ "(show-loops)" \ "(show-symbol-table)(show-parse-tree)" \ "(show-properties)(show-reachable-properties)(property):" \ From 0de6b17606a6c7092cdde65a2d3ccd5589374693 Mon Sep 17 00:00:00 2001 From: thk123 Date: Mon, 13 Feb 2017 11:59:47 +0000 Subject: [PATCH 35/46] Adding checks for NULL function pointers --- .../main.c | 31 +++++++++++++ .../test.desc | 8 ++++ .../no-match-const-fp-const-fp-null/main.c | 31 +++++++++++++ .../no-match-const-fp-const-fp-null/test.desc | 8 ++++ .../main.c | 44 +++++++++++++++++++ .../test.desc | 9 ++++ .../main.c | 36 +++++++++++++++ .../test.desc | 9 ++++ .../no-match-const-fp-null/main.c | 30 +++++++++++++ .../no-match-const-fp-null/test.desc | 8 ++++ .../main.c | 40 +++++++++++++++++ .../test.desc | 9 ++++ 12 files changed, 263 insertions(+) create mode 100644 regression/goto-analyzer/no-match-array-literal-const-fp-null/main.c create mode 100644 regression/goto-analyzer/no-match-array-literal-const-fp-null/test.desc create mode 100644 regression/goto-analyzer/no-match-const-fp-const-fp-null/main.c create mode 100644 regression/goto-analyzer/no-match-const-fp-const-fp-null/test.desc create mode 100644 regression/goto-analyzer/no-match-const-fp-const-pointer-const-struct-const-fp-null/main.c create mode 100644 regression/goto-analyzer/no-match-const-fp-const-pointer-const-struct-const-fp-null/test.desc create mode 100644 regression/goto-analyzer/no-match-const-fp-dereference-const-pointer-null/main.c create mode 100644 regression/goto-analyzer/no-match-const-fp-dereference-const-pointer-null/test.desc create mode 100644 regression/goto-analyzer/no-match-const-fp-null/main.c create mode 100644 regression/goto-analyzer/no-match-const-fp-null/test.desc create mode 100644 regression/goto-analyzer/no-match-const-struct-non-const-fp-null/main.c create mode 100644 regression/goto-analyzer/no-match-const-struct-non-const-fp-null/test.desc diff --git a/regression/goto-analyzer/no-match-array-literal-const-fp-null/main.c b/regression/goto-analyzer/no-match-array-literal-const-fp-null/main.c new file mode 100644 index 00000000000..fba4069b7a2 --- /dev/null +++ b/regression/goto-analyzer/no-match-array-literal-const-fp-null/main.c @@ -0,0 +1,31 @@ +#include + +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, NULL ,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() +{ + fp_tbl[1](); +} + +int main() +{ + func(); + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-array-literal-const-fp-null/test.desc b/regression/goto-analyzer/no-match-array-literal-const-fp-null/test.desc new file mode 100644 index 00000000000..4786993cade --- /dev/null +++ b/regression/goto-analyzer/no-match-array-literal-const-fp-null/test.desc @@ -0,0 +1,8 @@ +CORE +main.c +--show-goto-functions --verbosity 10 --pointer-check +^Removing function pointers and virtual functions$ +^\s*ASSERT FALSE // invalid function pointer$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-const-fp-null/main.c b/regression/goto-analyzer/no-match-const-fp-const-fp-null/main.c new file mode 100644 index 00000000000..4b8ba72dd51 --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-const-fp-null/main.c @@ -0,0 +1,31 @@ +#include + +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 func() +{ + const void_fp fp = NULL; + const void_fp fp2 = fp; + fp2(); +} + +int main() +{ + func(); + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-fp-const-fp-null/test.desc b/regression/goto-analyzer/no-match-const-fp-const-fp-null/test.desc new file mode 100644 index 00000000000..4786993cade --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-const-fp-null/test.desc @@ -0,0 +1,8 @@ +CORE +main.c +--show-goto-functions --verbosity 10 --pointer-check +^Removing function pointers and virtual functions$ +^\s*ASSERT FALSE // invalid function pointer$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-const-pointer-const-struct-const-fp-null/main.c b/regression/goto-analyzer/no-match-const-fp-const-pointer-const-struct-const-fp-null/main.c new file mode 100644 index 00000000000..76671ef3829 --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-const-pointer-const-struct-const-fp-null/main.c @@ -0,0 +1,44 @@ +#include + +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}; + + +typedef struct fp_container +{ + int x; + const void_fp pointer; +} fp_container; + + + +void func() +{ + const fp_container container = {.x = 10, .pointer = f3}; + const fp_container container2 = {.x = 10, .pointer = f4}; + const fp_container * const container_ptr = NULL; + + // Illegal: + //container_ptr = &container2; + //container_ptr->pointer = f4; + + container_ptr->pointer(); +} + +int main() +{ + func(); +} diff --git a/regression/goto-analyzer/no-match-const-fp-const-pointer-const-struct-const-fp-null/test.desc b/regression/goto-analyzer/no-match-const-fp-const-pointer-const-struct-const-fp-null/test.desc new file mode 100644 index 00000000000..25b505c0a0f --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-const-pointer-const-struct-const-fp-null/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--show-goto-functions --verbosity 10 --pointer-check + +^Removing function pointers and virtual functions$ +^\s*ASSERT FALSE // invalid function pointer$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-dereference-const-pointer-null/main.c b/regression/goto-analyzer/no-match-const-fp-dereference-const-pointer-null/main.c new file mode 100644 index 00000000000..b384b87bb4e --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-dereference-const-pointer-null/main.c @@ -0,0 +1,36 @@ +#include + +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 func() +{ + const void_fp fp = f3; + const void_fp fp2 = f4; + const void_fp* const p2fp = NULL; + // Illegal: + //p2fp = &fp2; + //fp = f5; + const void_fp final_fp=*p2fp; + final_fp(); +} + +int main() +{ + func(); + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-fp-dereference-const-pointer-null/test.desc b/regression/goto-analyzer/no-match-const-fp-dereference-const-pointer-null/test.desc new file mode 100644 index 00000000000..25b505c0a0f --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-dereference-const-pointer-null/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--show-goto-functions --verbosity 10 --pointer-check + +^Removing function pointers and virtual functions$ +^\s*ASSERT FALSE // invalid function pointer$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-null/main.c b/regression/goto-analyzer/no-match-const-fp-null/main.c new file mode 100644 index 00000000000..98a0349ce37 --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-null/main.c @@ -0,0 +1,30 @@ +#include + +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 func() +{ + const void_fp fp = NULL; + fp(); +} + +int main() +{ + func(); + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-fp-null/test.desc b/regression/goto-analyzer/no-match-const-fp-null/test.desc new file mode 100644 index 00000000000..267ec2284f7 --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-null/test.desc @@ -0,0 +1,8 @@ +CORE +main.c +--show-goto-functions --verbosity 10 --pointer-check + +^Removing function pointers and virtual functions$ +^\s*ASSERT FALSE // invalid function pointer$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-struct-non-const-fp-null/main.c b/regression/goto-analyzer/no-match-const-struct-non-const-fp-null/main.c new file mode 100644 index 00000000000..569870b6609 --- /dev/null +++ b/regression/goto-analyzer/no-match-const-struct-non-const-fp-null/main.c @@ -0,0 +1,40 @@ +#include + +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 +{ + int x; + const void_fp fun; +}; + +const struct action rec = { .x = 4, .fun = NULL }; + +// 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) +{ + rec.fun(); +} + +int main() +{ + for(int i=0;i<3;i++) + { + func(i); + } + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-struct-non-const-fp-null/test.desc b/regression/goto-analyzer/no-match-const-struct-non-const-fp-null/test.desc new file mode 100644 index 00000000000..25b505c0a0f --- /dev/null +++ b/regression/goto-analyzer/no-match-const-struct-non-const-fp-null/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--show-goto-functions --verbosity 10 --pointer-check + +^Removing function pointers and virtual functions$ +^\s*ASSERT FALSE // invalid function pointer$ +^SIGNAL=0$ +-- +^warning: ignoring From 10a08efe8c76631d8ec5a23676bf3f84fdc81197 Mon Sep 17 00:00:00 2001 From: thk123 Date: Mon, 13 Feb 2017 12:25:43 +0000 Subject: [PATCH 36/46] Renaming functions to more consistent name --- src/goto-programs/remove_const_function_pointers.cpp | 12 ++++++------ src/goto-programs/remove_const_function_pointers.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index f61aa2c86e5..d43ac85d62a 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -96,7 +96,7 @@ exprt remove_const_function_pointerst::replace_const_symbols( { if(expression.id()==ID_symbol) { - if(is_expression_const(expression)) + if(is_const_expression(expression)) { const symbolt &symbol= symbol_table.lookup(expression.get(ID_identifier)); @@ -540,7 +540,7 @@ bool remove_const_function_pointerst::try_resolve_expression( else { resolved_expressions.push_back(simplified_expr); - is_resolved_expression_const=is_expression_const(simplified_expr); + is_resolved_expression_const=is_const_expression(simplified_expr); resolved=true; } @@ -653,7 +653,7 @@ bool remove_const_function_pointerst::try_resolve_index_of( { all_possible_const= all_possible_const && - is_type_const(potential_array_expr.type().subtype()); + is_const_type(potential_array_expr.type().subtype()); if(potential_array_expr.id()==ID_array) { @@ -953,10 +953,10 @@ Function: remove_const_function_pointerst::is_expression_const \*******************************************************************/ -bool remove_const_function_pointerst::is_expression_const( +bool remove_const_function_pointerst::is_const_expression( const exprt &expression) const { - return is_type_const(expression.type()); + return is_const_type(expression.type()); } /*******************************************************************\ @@ -973,7 +973,7 @@ Function: remove_const_function_pointerst::is_type_const \*******************************************************************/ -bool remove_const_function_pointerst::is_type_const(const typet &type) const +bool remove_const_function_pointerst::is_const_type(const typet &type) const { c_qualifierst qualifers(type); if(type.id()==ID_array) diff --git a/src/goto-programs/remove_const_function_pointers.h b/src/goto-programs/remove_const_function_pointers.h index 74b34a28e9d..8b0b0c23a56 100644 --- a/src/goto-programs/remove_const_function_pointers.h +++ b/src/goto-programs/remove_const_function_pointers.h @@ -79,8 +79,8 @@ class remove_const_function_pointerst:public messaget expressionst &out_expressions, bool &out_is_const); - bool is_expression_const(const exprt &expression) const; - bool is_type_const(const typet &type) const; + bool is_const_expression(const exprt &expression) const; + bool is_const_type(const typet &type) const; bool try_resolve_index_value( const exprt &index_value_expr, mp_integer &out_array_index); From cf6a49a6b55a2c6ce9fa4e3afcfebdef8d10295a Mon Sep 17 00:00:00 2001 From: thk123 Date: Mon, 13 Feb 2017 13:38:31 +0000 Subject: [PATCH 37/46] Swap to using an unorded set Modified the tests to not assume the order of the functions. For precise tests no further changes are required since if the removal failed, there will be a label before the call to be jumped to. For the no-match tests, no further changes are required since the goto statements are being verified to be all the there. For the approx tests, we need to verify that the other case statements aren't present in the GOTO program to be sure that the FP removal has been successful. As such, the other case statements are added to the exclude section. --- .../approx-array-variable-const-fp/test.desc | 12 +++++++++--- .../test.desc | 12 +++++++++--- .../test.desc | 12 +++++++++--- .../test.desc | 12 +++++++++--- .../test.desc | 12 +++++++++--- .../test.desc | 12 +++++++++--- .../test.desc | 12 +++++++++--- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../no-match-non-const-fp/test.desc | 18 +++++++++--------- .../no-match-parameter-const-fp/test.desc | 18 +++++++++--------- .../no-match-parameter-fp/test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../remove_const_function_pointers.h | 4 +++- 28 files changed, 246 insertions(+), 202 deletions(-) diff --git a/regression/goto-analyzer/approx-array-variable-const-fp/test.desc b/regression/goto-analyzer/approx-array-variable-const-fp/test.desc index e8d2128a0d0..28b95c5ac33 100644 --- a/regression/goto-analyzer/approx-array-variable-const-fp/test.desc +++ b/regression/goto-analyzer/approx-array-variable-const-fp/test.desc @@ -3,9 +3,15 @@ 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 1$ -^\s*IF fp_tbl\[(signed long int)i\] == f3 THEN GOTO 2$ -^\s*IF fp_tbl\[(signed long int)i\] == f4 THEN GOTO 3$ +^\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 diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc index 20eb8d6a109..973fbe34127 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc @@ -3,9 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == f2 THEN GOTO 1$ -^\s*IF fp == f3 THEN GOTO 2$ -^\s*IF fp == f4 THEN GOTO 3$ +^\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]$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc index 20eb8d6a109..973fbe34127 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc @@ -3,9 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == f2 THEN GOTO 1$ -^\s*IF fp == f3 THEN GOTO 2$ -^\s*IF fp == f4 THEN GOTO 3$ +^\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]$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc index 20eb8d6a109..973fbe34127 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc @@ -3,9 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == f2 THEN GOTO 1$ -^\s*IF fp == f3 THEN GOTO 2$ -^\s*IF fp == f4 THEN GOTO 3$ +^\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]$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc index 20eb8d6a109..973fbe34127 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc @@ -3,9 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == f2 THEN GOTO 1$ -^\s*IF fp == f3 THEN GOTO 2$ -^\s*IF fp == f4 THEN GOTO 3$ +^\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]$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc index 20eb8d6a109..973fbe34127 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc @@ -3,9 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == f2 THEN GOTO 1$ -^\s*IF fp == f3 THEN GOTO 2$ -^\s*IF fp == f4 THEN GOTO 3$ +^\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]$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc index 082acf9a6f2..5459b630bc9 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc @@ -3,9 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == (void (\*)(void))f2 THEN GOTO 1$ -^\s*IF fp == (void (\*)(void))f3 THEN GOTO 2$ -^\s*IF fp == (void (\*)(void))f4 THEN GOTO 3$ +^\s*IF fp == (void (\*)(void))f2 THEN GOTO [0-9]$ +^\s*IF fp == (void (\*)(void))f3 THEN GOTO [0-9]$ +^\s*IF fp == (void (\*)(void))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]$ diff --git a/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/test.desc b/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/test.desc index a90040a0f82..997ec886207 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == f1 THEN GOTO 1$ -^\s*IF fp == f2 THEN GOTO 2$ -^\s*IF fp == f3 THEN GOTO 3$ -^\s*IF fp == f4 THEN GOTO 4$ -^\s*IF fp == f5 THEN GOTO 5$ -^\s*IF fp == f6 THEN GOTO 6$ -^\s*IF fp == f7 THEN GOTO 7$ -^\s*IF fp == f8 THEN GOTO 8$ -^\s*IF fp == f9 THEN GOTO 9$ +^\s*IF fp == f1 THEN GOTO [0-9]$ +^\s*IF fp == f2 THEN GOTO [0-9]$ +^\s*IF fp == f3 THEN GOTO [0-9]$ +^\s*IF fp == f4 THEN GOTO [0-9]$ +^\s*IF fp == f5 THEN GOTO [0-9]$ +^\s*IF fp == f6 THEN GOTO [0-9]$ +^\s*IF fp == f7 THEN GOTO [0-9]$ +^\s*IF fp == f8 THEN GOTO [0-9]$ +^\s*IF fp == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/test.desc b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/test.desc index a90040a0f82..997ec886207 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == f1 THEN GOTO 1$ -^\s*IF fp == f2 THEN GOTO 2$ -^\s*IF fp == f3 THEN GOTO 3$ -^\s*IF fp == f4 THEN GOTO 4$ -^\s*IF fp == f5 THEN GOTO 5$ -^\s*IF fp == f6 THEN GOTO 6$ -^\s*IF fp == f7 THEN GOTO 7$ -^\s*IF fp == f8 THEN GOTO 8$ -^\s*IF fp == f9 THEN GOTO 9$ +^\s*IF fp == f1 THEN GOTO [0-9]$ +^\s*IF fp == f2 THEN GOTO [0-9]$ +^\s*IF fp == f3 THEN GOTO [0-9]$ +^\s*IF fp == f4 THEN GOTO [0-9]$ +^\s*IF fp == f5 THEN GOTO [0-9]$ +^\s*IF fp == f6 THEN GOTO [0-9]$ +^\s*IF fp == f7 THEN GOTO [0-9]$ +^\s*IF fp == f8 THEN GOTO [0-9]$ +^\s*IF fp == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/test.desc index 328eefd5fd0..9c0926c2e7a 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp2 == f1 THEN GOTO 1$ -^\s*IF fp2 == f2 THEN GOTO 2$ -^\s*IF fp2 == f3 THEN GOTO 3$ -^\s*IF fp2 == f4 THEN GOTO 4$ -^\s*IF fp2 == f5 THEN GOTO 5$ -^\s*IF fp2 == f6 THEN GOTO 6$ -^\s*IF fp2 == f7 THEN GOTO 7$ -^\s*IF fp2 == f8 THEN GOTO 8$ -^\s*IF fp2 == f9 THEN GOTO 9$ +^\s*IF fp2 == f1 THEN GOTO [0-9]$ +^\s*IF fp2 == f2 THEN GOTO [0-9]$ +^\s*IF fp2 == f3 THEN GOTO [0-9]$ +^\s*IF fp2 == f4 THEN GOTO [0-9]$ +^\s*IF fp2 == f5 THEN GOTO [0-9]$ +^\s*IF fp2 == f6 THEN GOTO [0-9]$ +^\s*IF fp2 == f7 THEN GOTO [0-9]$ +^\s*IF fp2 == f8 THEN GOTO [0-9]$ +^\s*IF fp2 == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/test.desc index 328eefd5fd0..9c0926c2e7a 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp2 == f1 THEN GOTO 1$ -^\s*IF fp2 == f2 THEN GOTO 2$ -^\s*IF fp2 == f3 THEN GOTO 3$ -^\s*IF fp2 == f4 THEN GOTO 4$ -^\s*IF fp2 == f5 THEN GOTO 5$ -^\s*IF fp2 == f6 THEN GOTO 6$ -^\s*IF fp2 == f7 THEN GOTO 7$ -^\s*IF fp2 == f8 THEN GOTO 8$ -^\s*IF fp2 == f9 THEN GOTO 9$ +^\s*IF fp2 == f1 THEN GOTO [0-9]$ +^\s*IF fp2 == f2 THEN GOTO [0-9]$ +^\s*IF fp2 == f3 THEN GOTO [0-9]$ +^\s*IF fp2 == f4 THEN GOTO [0-9]$ +^\s*IF fp2 == f5 THEN GOTO [0-9]$ +^\s*IF fp2 == f6 THEN GOTO [0-9]$ +^\s*IF fp2 == f7 THEN GOTO [0-9]$ +^\s*IF fp2 == f8 THEN GOTO [0-9]$ +^\s*IF fp2 == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/test.desc index a90040a0f82..997ec886207 100644 --- a/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == f1 THEN GOTO 1$ -^\s*IF fp == f2 THEN GOTO 2$ -^\s*IF fp == f3 THEN GOTO 3$ -^\s*IF fp == f4 THEN GOTO 4$ -^\s*IF fp == f5 THEN GOTO 5$ -^\s*IF fp == f6 THEN GOTO 6$ -^\s*IF fp == f7 THEN GOTO 7$ -^\s*IF fp == f8 THEN GOTO 8$ -^\s*IF fp == f9 THEN GOTO 9$ +^\s*IF fp == f1 THEN GOTO [0-9]$ +^\s*IF fp == f2 THEN GOTO [0-9]$ +^\s*IF fp == f3 THEN GOTO [0-9]$ +^\s*IF fp == f4 THEN GOTO [0-9]$ +^\s*IF fp == f5 THEN GOTO [0-9]$ +^\s*IF fp == f6 THEN GOTO [0-9]$ +^\s*IF fp == f7 THEN GOTO [0-9]$ +^\s*IF fp == f8 THEN GOTO [0-9]$ +^\s*IF fp == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/test.desc index a726957f5ee..61a7ec29e6b 100644 --- a/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF final_fp == f1 THEN GOTO 1$ -^\s*IF final_fp == f2 THEN GOTO 2$ -^\s*IF final_fp == f3 THEN GOTO 3$ -^\s*IF final_fp == f4 THEN GOTO 4$ -^\s*IF final_fp == f5 THEN GOTO 5$ -^\s*IF final_fp == f6 THEN GOTO 6$ -^\s*IF final_fp == f7 THEN GOTO 7$ -^\s*IF final_fp == f8 THEN GOTO 8$ -^\s*IF final_fp == f9 THEN GOTO 9$ +^\s*IF final_fp == f1 THEN GOTO [0-9]$ +^\s*IF final_fp == f2 THEN GOTO [0-9]$ +^\s*IF final_fp == f3 THEN GOTO [0-9]$ +^\s*IF final_fp == f4 THEN GOTO [0-9]$ +^\s*IF final_fp == f5 THEN GOTO [0-9]$ +^\s*IF final_fp == f6 THEN GOTO [0-9]$ +^\s*IF final_fp == f7 THEN GOTO [0-9]$ +^\s*IF final_fp == f8 THEN GOTO [0-9]$ +^\s*IF final_fp == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/test.desc index a90040a0f82..997ec886207 100644 --- a/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == f1 THEN GOTO 1$ -^\s*IF fp == f2 THEN GOTO 2$ -^\s*IF fp == f3 THEN GOTO 3$ -^\s*IF fp == f4 THEN GOTO 4$ -^\s*IF fp == f5 THEN GOTO 5$ -^\s*IF fp == f6 THEN GOTO 6$ -^\s*IF fp == f7 THEN GOTO 7$ -^\s*IF fp == f8 THEN GOTO 8$ -^\s*IF fp == f9 THEN GOTO 9$ +^\s*IF fp == f1 THEN GOTO [0-9]$ +^\s*IF fp == f2 THEN GOTO [0-9]$ +^\s*IF fp == f3 THEN GOTO [0-9]$ +^\s*IF fp == f4 THEN GOTO [0-9]$ +^\s*IF fp == f5 THEN GOTO [0-9]$ +^\s*IF fp == f6 THEN GOTO [0-9]$ +^\s*IF fp == f7 THEN GOTO [0-9]$ +^\s*IF fp == f8 THEN GOTO [0-9]$ +^\s*IF fp == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/test.desc b/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/test.desc index 06f3395c5fa..13d0c5353ce 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/test.desc @@ -2,15 +2,15 @@ CORE main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp2 == f1 THEN GOTO 1$ -^\s*IF fp2 == f2 THEN GOTO 2$ -^\s*IF fp2 == f3 THEN GOTO 3$ -^\s*IF fp2 == f4 THEN GOTO 4$ -^\s*IF fp2 == f5 THEN GOTO 5$ -^\s*IF fp2 == f6 THEN GOTO 6$ -^\s*IF fp2 == f7 THEN GOTO 7$ -^\s*IF fp2 == f8 THEN GOTO 8$ -^\s*IF fp2 == f9 THEN GOTO 9$ +^\s*IF fp2 == f1 THEN GOTO [0-9]$ +^\s*IF fp2 == f2 THEN GOTO [0-9]$ +^\s*IF fp2 == f3 THEN GOTO [0-9]$ +^\s*IF fp2 == f4 THEN GOTO [0-9]$ +^\s*IF fp2 == f5 THEN GOTO [0-9]$ +^\s*IF fp2 == f6 THEN GOTO [0-9]$ +^\s*IF fp2 == f7 THEN GOTO [0-9]$ +^\s*IF fp2 == f8 THEN GOTO [0-9]$ +^\s*IF fp2 == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/test.desc index a90040a0f82..997ec886207 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == f1 THEN GOTO 1$ -^\s*IF fp == f2 THEN GOTO 2$ -^\s*IF fp == f3 THEN GOTO 3$ -^\s*IF fp == f4 THEN GOTO 4$ -^\s*IF fp == f5 THEN GOTO 5$ -^\s*IF fp == f6 THEN GOTO 6$ -^\s*IF fp == f7 THEN GOTO 7$ -^\s*IF fp == f8 THEN GOTO 8$ -^\s*IF fp == f9 THEN GOTO 9$ +^\s*IF fp == f1 THEN GOTO [0-9]$ +^\s*IF fp == f2 THEN GOTO [0-9]$ +^\s*IF fp == f3 THEN GOTO [0-9]$ +^\s*IF fp == f4 THEN GOTO [0-9]$ +^\s*IF fp == f5 THEN GOTO [0-9]$ +^\s*IF fp == f6 THEN GOTO [0-9]$ +^\s*IF fp == f7 THEN GOTO [0-9]$ +^\s*IF fp == f8 THEN GOTO [0-9]$ +^\s*IF fp == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/test.desc index a90040a0f82..997ec886207 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == f1 THEN GOTO 1$ -^\s*IF fp == f2 THEN GOTO 2$ -^\s*IF fp == f3 THEN GOTO 3$ -^\s*IF fp == f4 THEN GOTO 4$ -^\s*IF fp == f5 THEN GOTO 5$ -^\s*IF fp == f6 THEN GOTO 6$ -^\s*IF fp == f7 THEN GOTO 7$ -^\s*IF fp == f8 THEN GOTO 8$ -^\s*IF fp == f9 THEN GOTO 9$ +^\s*IF fp == f1 THEN GOTO [0-9]$ +^\s*IF fp == f2 THEN GOTO [0-9]$ +^\s*IF fp == f3 THEN GOTO [0-9]$ +^\s*IF fp == f4 THEN GOTO [0-9]$ +^\s*IF fp == f5 THEN GOTO [0-9]$ +^\s*IF fp == f6 THEN GOTO [0-9]$ +^\s*IF fp == f7 THEN GOTO [0-9]$ +^\s*IF fp == f8 THEN GOTO [0-9]$ +^\s*IF fp == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/test.desc index a90040a0f82..997ec886207 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == f1 THEN GOTO 1$ -^\s*IF fp == f2 THEN GOTO 2$ -^\s*IF fp == f3 THEN GOTO 3$ -^\s*IF fp == f4 THEN GOTO 4$ -^\s*IF fp == f5 THEN GOTO 5$ -^\s*IF fp == f6 THEN GOTO 6$ -^\s*IF fp == f7 THEN GOTO 7$ -^\s*IF fp == f8 THEN GOTO 8$ -^\s*IF fp == f9 THEN GOTO 9$ +^\s*IF fp == f1 THEN GOTO [0-9]$ +^\s*IF fp == f2 THEN GOTO [0-9]$ +^\s*IF fp == f3 THEN GOTO [0-9]$ +^\s*IF fp == f4 THEN GOTO [0-9]$ +^\s*IF fp == f5 THEN GOTO [0-9]$ +^\s*IF fp == f6 THEN GOTO [0-9]$ +^\s*IF fp == f7 THEN GOTO [0-9]$ +^\s*IF fp == f8 THEN GOTO [0-9]$ +^\s*IF fp == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/test.desc b/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/test.desc index b038fb608e3..80169b619fa 100644 --- a/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF pts->go == f1 THEN GOTO 1$ -^\s*IF pts->go == f2 THEN GOTO 2$ -^\s*IF pts->go == f3 THEN GOTO 3$ -^\s*IF pts->go == f4 THEN GOTO 4$ -^\s*IF pts->go == f5 THEN GOTO 5$ -^\s*IF pts->go == f6 THEN GOTO 6$ -^\s*IF pts->go == f7 THEN GOTO 7$ -^\s*IF pts->go == f8 THEN GOTO 8$ -^\s*IF pts->go == f9 THEN GOTO 9$ +^\s*IF pts->go == f1 THEN GOTO [0-9]$ +^\s*IF pts->go == f2 THEN GOTO [0-9]$ +^\s*IF pts->go == f3 THEN GOTO [0-9]$ +^\s*IF pts->go == f4 THEN GOTO [0-9]$ +^\s*IF pts->go == f5 THEN GOTO [0-9]$ +^\s*IF pts->go == f6 THEN GOTO [0-9]$ +^\s*IF pts->go == f7 THEN GOTO [0-9]$ +^\s*IF pts->go == f8 THEN GOTO [0-9]$ +^\s*IF pts->go == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/test.desc b/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/test.desc index 2fa1d08dd26..9abe6fde56a 100644 --- a/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f1 THEN GOTO 1$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f2 THEN GOTO 2$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f3 THEN GOTO 3$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f4 THEN GOTO 4$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f5 THEN GOTO 5$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f6 THEN GOTO 6$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f7 THEN GOTO 7$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f8 THEN GOTO 8$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f9 THEN GOTO 9$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f1 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f2 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f3 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f4 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f5 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f6 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f7 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f8 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-dereference-non-const-struct-const-pointer-const-fp/test.desc b/regression/goto-analyzer/no-match-dereference-non-const-struct-const-pointer-const-fp/test.desc index 1eb1dc36059..f55defde97b 100644 --- a/regression/goto-analyzer/no-match-dereference-non-const-struct-const-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-dereference-non-const-struct-const-pointer-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF \*container_container\.container == f1 THEN GOTO 1$ -^\s*IF \*container_container\.container == f2 THEN GOTO 2$ -^\s*IF \*container_container\.container == f3 THEN GOTO 3$ -^\s*IF \*container_container\.container == f4 THEN GOTO 4$ -^\s*IF \*container_container\.container == f5 THEN GOTO 5$ -^\s*IF \*container_container\.container == f6 THEN GOTO 6$ -^\s*IF \*container_container\.container == f7 THEN GOTO 7$ -^\s*IF \*container_container\.container == f8 THEN GOTO 8$ -^\s*IF \*container_container\.container == f9 THEN GOTO 9$ +^\s*IF \*container_container\.container == f1 THEN GOTO [0-9]$ +^\s*IF \*container_container\.container == f2 THEN GOTO [0-9]$ +^\s*IF \*container_container\.container == f3 THEN GOTO [0-9]$ +^\s*IF \*container_container\.container == f4 THEN GOTO [0-9]$ +^\s*IF \*container_container\.container == f5 THEN GOTO [0-9]$ +^\s*IF \*container_container\.container == f6 THEN GOTO [0-9]$ +^\s*IF \*container_container\.container == f7 THEN GOTO [0-9]$ +^\s*IF \*container_container\.container == f8 THEN GOTO [0-9]$ +^\s*IF \*container_container\.container == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-dereference-non-const-struct-non-const-pointer-const-fp/test.desc b/regression/goto-analyzer/no-match-dereference-non-const-struct-non-const-pointer-const-fp/test.desc index 1eb1dc36059..f55defde97b 100644 --- a/regression/goto-analyzer/no-match-dereference-non-const-struct-non-const-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-dereference-non-const-struct-non-const-pointer-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF \*container_container\.container == f1 THEN GOTO 1$ -^\s*IF \*container_container\.container == f2 THEN GOTO 2$ -^\s*IF \*container_container\.container == f3 THEN GOTO 3$ -^\s*IF \*container_container\.container == f4 THEN GOTO 4$ -^\s*IF \*container_container\.container == f5 THEN GOTO 5$ -^\s*IF \*container_container\.container == f6 THEN GOTO 6$ -^\s*IF \*container_container\.container == f7 THEN GOTO 7$ -^\s*IF \*container_container\.container == f8 THEN GOTO 8$ -^\s*IF \*container_container\.container == f9 THEN GOTO 9$ +^\s*IF \*container_container\.container == f1 THEN GOTO [0-9]$ +^\s*IF \*container_container\.container == f2 THEN GOTO [0-9]$ +^\s*IF \*container_container\.container == f3 THEN GOTO [0-9]$ +^\s*IF \*container_container\.container == f4 THEN GOTO [0-9]$ +^\s*IF \*container_container\.container == f5 THEN GOTO [0-9]$ +^\s*IF \*container_container\.container == f6 THEN GOTO [0-9]$ +^\s*IF \*container_container\.container == f7 THEN GOTO [0-9]$ +^\s*IF \*container_container\.container == f8 THEN GOTO [0-9]$ +^\s*IF \*container_container\.container == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/test.desc b/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/test.desc index 06f3395c5fa..13d0c5353ce 100644 --- a/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/test.desc +++ b/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/test.desc @@ -2,15 +2,15 @@ CORE main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp2 == f1 THEN GOTO 1$ -^\s*IF fp2 == f2 THEN GOTO 2$ -^\s*IF fp2 == f3 THEN GOTO 3$ -^\s*IF fp2 == f4 THEN GOTO 4$ -^\s*IF fp2 == f5 THEN GOTO 5$ -^\s*IF fp2 == f6 THEN GOTO 6$ -^\s*IF fp2 == f7 THEN GOTO 7$ -^\s*IF fp2 == f8 THEN GOTO 8$ -^\s*IF fp2 == f9 THEN GOTO 9$ +^\s*IF fp2 == f1 THEN GOTO [0-9]$ +^\s*IF fp2 == f2 THEN GOTO [0-9]$ +^\s*IF fp2 == f3 THEN GOTO [0-9]$ +^\s*IF fp2 == f4 THEN GOTO [0-9]$ +^\s*IF fp2 == f5 THEN GOTO [0-9]$ +^\s*IF fp2 == f6 THEN GOTO [0-9]$ +^\s*IF fp2 == f7 THEN GOTO [0-9]$ +^\s*IF fp2 == f8 THEN GOTO [0-9]$ +^\s*IF fp2 == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-non-const-fp/test.desc b/regression/goto-analyzer/no-match-non-const-fp/test.desc index a90040a0f82..997ec886207 100644 --- a/regression/goto-analyzer/no-match-non-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-non-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == f1 THEN GOTO 1$ -^\s*IF fp == f2 THEN GOTO 2$ -^\s*IF fp == f3 THEN GOTO 3$ -^\s*IF fp == f4 THEN GOTO 4$ -^\s*IF fp == f5 THEN GOTO 5$ -^\s*IF fp == f6 THEN GOTO 6$ -^\s*IF fp == f7 THEN GOTO 7$ -^\s*IF fp == f8 THEN GOTO 8$ -^\s*IF fp == f9 THEN GOTO 9$ +^\s*IF fp == f1 THEN GOTO [0-9]$ +^\s*IF fp == f2 THEN GOTO [0-9]$ +^\s*IF fp == f3 THEN GOTO [0-9]$ +^\s*IF fp == f4 THEN GOTO [0-9]$ +^\s*IF fp == f5 THEN GOTO [0-9]$ +^\s*IF fp == f6 THEN GOTO [0-9]$ +^\s*IF fp == f7 THEN GOTO [0-9]$ +^\s*IF fp == f8 THEN GOTO [0-9]$ +^\s*IF fp == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-parameter-const-fp/test.desc b/regression/goto-analyzer/no-match-parameter-const-fp/test.desc index a90040a0f82..997ec886207 100644 --- a/regression/goto-analyzer/no-match-parameter-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-parameter-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == f1 THEN GOTO 1$ -^\s*IF fp == f2 THEN GOTO 2$ -^\s*IF fp == f3 THEN GOTO 3$ -^\s*IF fp == f4 THEN GOTO 4$ -^\s*IF fp == f5 THEN GOTO 5$ -^\s*IF fp == f6 THEN GOTO 6$ -^\s*IF fp == f7 THEN GOTO 7$ -^\s*IF fp == f8 THEN GOTO 8$ -^\s*IF fp == f9 THEN GOTO 9$ +^\s*IF fp == f1 THEN GOTO [0-9]$ +^\s*IF fp == f2 THEN GOTO [0-9]$ +^\s*IF fp == f3 THEN GOTO [0-9]$ +^\s*IF fp == f4 THEN GOTO [0-9]$ +^\s*IF fp == f5 THEN GOTO [0-9]$ +^\s*IF fp == f6 THEN GOTO [0-9]$ +^\s*IF fp == f7 THEN GOTO [0-9]$ +^\s*IF fp == f8 THEN GOTO [0-9]$ +^\s*IF fp == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-parameter-fp/test.desc b/regression/goto-analyzer/no-match-parameter-fp/test.desc index a90040a0f82..997ec886207 100644 --- a/regression/goto-analyzer/no-match-parameter-fp/test.desc +++ b/regression/goto-analyzer/no-match-parameter-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == f1 THEN GOTO 1$ -^\s*IF fp == f2 THEN GOTO 2$ -^\s*IF fp == f3 THEN GOTO 3$ -^\s*IF fp == f4 THEN GOTO 4$ -^\s*IF fp == f5 THEN GOTO 5$ -^\s*IF fp == f6 THEN GOTO 6$ -^\s*IF fp == f7 THEN GOTO 7$ -^\s*IF fp == f8 THEN GOTO 8$ -^\s*IF fp == f9 THEN GOTO 9$ +^\s*IF fp == f1 THEN GOTO [0-9]$ +^\s*IF fp == f2 THEN GOTO [0-9]$ +^\s*IF fp == f3 THEN GOTO [0-9]$ +^\s*IF fp == f4 THEN GOTO [0-9]$ +^\s*IF fp == f5 THEN GOTO [0-9]$ +^\s*IF fp == f6 THEN GOTO [0-9]$ +^\s*IF fp == f7 THEN GOTO [0-9]$ +^\s*IF fp == f8 THEN GOTO [0-9]$ +^\s*IF fp == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/test.desc b/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/test.desc index 9ae7c264af7..3f90b23b7d4 100644 --- a/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f1 THEN GOTO 1$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f2 THEN GOTO 2$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f3 THEN GOTO 3$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f4 THEN GOTO 4$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f5 THEN GOTO 5$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f6 THEN GOTO 6$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f7 THEN GOTO 7$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f8 THEN GOTO 8$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f9 THEN GOTO 9$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f1 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f2 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f3 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f4 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f5 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f6 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f7 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f8 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/src/goto-programs/remove_const_function_pointers.h b/src/goto-programs/remove_const_function_pointers.h index 8b0b0c23a56..1847ef56849 100644 --- a/src/goto-programs/remove_const_function_pointers.h +++ b/src/goto-programs/remove_const_function_pointers.h @@ -9,6 +9,8 @@ Author: Thomas Kiley, thomas.kiley@diffblue.com #ifndef CPROVER_GOTO_PROGRAMS_REMOVE_CONST_FUNCTION_POINTERS_H #define CPROVER_GOTO_PROGRAMS_REMOVE_CONST_FUNCTION_POINTERS_H +#include + #include "goto_model.h" #include #include @@ -18,7 +20,7 @@ Author: Thomas Kiley, thomas.kiley@diffblue.com class remove_const_function_pointerst:public messaget { public: - typedef std::set functionst; + typedef std::unordered_set functionst; typedef std::list expressionst; remove_const_function_pointerst( message_handlert &message_handler, From db11c31fc16df7e1eed7c3dd278489203d00d1be Mon Sep 17 00:00:00 2001 From: thk123 Date: Mon, 13 Feb 2017 16:20:18 +0000 Subject: [PATCH 38/46] Added flag for goto-instrument to just remove const function pointers Added a flag --remove-const-function-pointers for goto-instrument that can be used instead of --remove-function-pointers to only remove function pointers where we can resolve to something more precise that all functions with a matching signature. --- .../main.c | 34 +++++++++++ .../test.desc | 16 ++++++ .../main.c | 34 +++++++++++ .../test.desc | 16 ++++++ .../main.c | 31 ++++++++++ .../test.desc | 8 +++ .../main.c | 31 ++++++++++ .../test.desc | 16 ++++++ .../precise-const-fp-only-remove-const/main.c | 30 ++++++++++ .../test.desc | 7 +++ .../precise-const-fp-remove-all-fp/main.c | 30 ++++++++++ .../precise-const-fp-remove-all-fp/test.desc | 7 +++ .../goto_instrument_parse_options.cpp | 40 +++++++++++++ .../goto_instrument_parse_options.h | 3 + .../remove_const_function_pointers.h | 7 +++ .../remove_function_pointers.cpp | 57 +++++++++++++++---- src/goto-programs/remove_function_pointers.h | 9 ++- 17 files changed, 361 insertions(+), 15 deletions(-) create mode 100644 regression/goto-instrument/approx-array-variable-const-fp-only-remove-const/main.c create mode 100644 regression/goto-instrument/approx-array-variable-const-fp-only-remove-const/test.desc create mode 100644 regression/goto-instrument/approx-array-variable-const-fp-remove-all-fp/main.c create mode 100644 regression/goto-instrument/approx-array-variable-const-fp-remove-all-fp/test.desc create mode 100644 regression/goto-instrument/no-match-non-const-fp-only-remove-const/main.c create mode 100644 regression/goto-instrument/no-match-non-const-fp-only-remove-const/test.desc create mode 100644 regression/goto-instrument/no-match-non-const-fp-remove-all-fp/main.c create mode 100644 regression/goto-instrument/no-match-non-const-fp-remove-all-fp/test.desc create mode 100644 regression/goto-instrument/precise-const-fp-only-remove-const/main.c create mode 100644 regression/goto-instrument/precise-const-fp-only-remove-const/test.desc create mode 100644 regression/goto-instrument/precise-const-fp-remove-all-fp/main.c create mode 100644 regression/goto-instrument/precise-const-fp-remove-all-fp/test.desc diff --git a/regression/goto-instrument/approx-array-variable-const-fp-only-remove-const/main.c b/regression/goto-instrument/approx-array-variable-const-fp-only-remove-const/main.c new file mode 100644 index 00000000000..3fb230c83fd --- /dev/null +++ b/regression/goto-instrument/approx-array-variable-const-fp-only-remove-const/main.c @@ -0,0 +1,34 @@ +#include + +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; +} \ No newline at end of file diff --git a/regression/goto-instrument/approx-array-variable-const-fp-only-remove-const/test.desc b/regression/goto-instrument/approx-array-variable-const-fp-only-remove-const/test.desc new file mode 100644 index 00000000000..3c712e97b99 --- /dev/null +++ b/regression/goto-instrument/approx-array-variable-const-fp-only-remove-const/test.desc @@ -0,0 +1,16 @@ +CORE +main.c +--verbosity 10 --pointer-check --remove-const-function-pointers + +^\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 diff --git a/regression/goto-instrument/approx-array-variable-const-fp-remove-all-fp/main.c b/regression/goto-instrument/approx-array-variable-const-fp-remove-all-fp/main.c new file mode 100644 index 00000000000..7896e3402c0 --- /dev/null +++ b/regression/goto-instrument/approx-array-variable-const-fp-remove-all-fp/main.c @@ -0,0 +1,34 @@ +#include + +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; +} diff --git a/regression/goto-instrument/approx-array-variable-const-fp-remove-all-fp/test.desc b/regression/goto-instrument/approx-array-variable-const-fp-remove-all-fp/test.desc new file mode 100644 index 00000000000..7cd546580d7 --- /dev/null +++ b/regression/goto-instrument/approx-array-variable-const-fp-remove-all-fp/test.desc @@ -0,0 +1,16 @@ +CORE +main.c +--verbosity 10 --pointer-check --remove-function-pointers + +^\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 diff --git a/regression/goto-instrument/no-match-non-const-fp-only-remove-const/main.c b/regression/goto-instrument/no-match-non-const-fp-only-remove-const/main.c new file mode 100644 index 00000000000..80c8c863ff5 --- /dev/null +++ b/regression/goto-instrument/no-match-non-const-fp-only-remove-const/main.c @@ -0,0 +1,31 @@ +#include + +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 func() +{ + void_fp fp = f2; + fp = f3; + fp(); +} + +int main() +{ + func(); + + return 0; +} diff --git a/regression/goto-instrument/no-match-non-const-fp-only-remove-const/test.desc b/regression/goto-instrument/no-match-non-const-fp-only-remove-const/test.desc new file mode 100644 index 00000000000..ff5e6a916e1 --- /dev/null +++ b/regression/goto-instrument/no-match-non-const-fp-only-remove-const/test.desc @@ -0,0 +1,8 @@ +CORE +main.c +--verbosity 10 --pointer-check --remove-const-function-pointers + +^\s*fp();$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-instrument/no-match-non-const-fp-remove-all-fp/main.c b/regression/goto-instrument/no-match-non-const-fp-remove-all-fp/main.c new file mode 100644 index 00000000000..80c8c863ff5 --- /dev/null +++ b/regression/goto-instrument/no-match-non-const-fp-remove-all-fp/main.c @@ -0,0 +1,31 @@ +#include + +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 func() +{ + void_fp fp = f2; + fp = f3; + fp(); +} + +int main() +{ + func(); + + return 0; +} diff --git a/regression/goto-instrument/no-match-non-const-fp-remove-all-fp/test.desc b/regression/goto-instrument/no-match-non-const-fp-remove-all-fp/test.desc new file mode 100644 index 00000000000..3190d348aae --- /dev/null +++ b/regression/goto-instrument/no-match-non-const-fp-remove-all-fp/test.desc @@ -0,0 +1,16 @@ +CORE +main.c +--verbosity 10 --pointer-check --remove-function-pointers + +^\s*IF fp == f1 THEN GOTO [0-9]$ +^\s*IF fp == f2 THEN GOTO [0-9]$ +^\s*IF fp == f3 THEN GOTO [0-9]$ +^\s*IF fp == f4 THEN GOTO [0-9]$ +^\s*IF fp == f5 THEN GOTO [0-9]$ +^\s*IF fp == f6 THEN GOTO [0-9]$ +^\s*IF fp == f7 THEN GOTO [0-9]$ +^\s*IF fp == f8 THEN GOTO [0-9]$ +^\s*IF fp == f9 THEN GOTO [0-9]$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-instrument/precise-const-fp-only-remove-const/main.c b/regression/goto-instrument/precise-const-fp-only-remove-const/main.c new file mode 100644 index 00000000000..b4002c94e5e --- /dev/null +++ b/regression/goto-instrument/precise-const-fp-only-remove-const/main.c @@ -0,0 +1,30 @@ +#include + +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 func() +{ + const void_fp fp = f2; + fp(); +} + +int main() +{ + func(); + + return 0; +} diff --git a/regression/goto-instrument/precise-const-fp-only-remove-const/test.desc b/regression/goto-instrument/precise-const-fp-only-remove-const/test.desc new file mode 100644 index 00000000000..e125fff93f4 --- /dev/null +++ b/regression/goto-instrument/precise-const-fp-only-remove-const/test.desc @@ -0,0 +1,7 @@ +CORE +main.c +--verbosity 10 --pointer-check --remove-const-function-pointers + +^\s*f2(); +-- +^warning: ignoring diff --git a/regression/goto-instrument/precise-const-fp-remove-all-fp/main.c b/regression/goto-instrument/precise-const-fp-remove-all-fp/main.c new file mode 100644 index 00000000000..b4002c94e5e --- /dev/null +++ b/regression/goto-instrument/precise-const-fp-remove-all-fp/main.c @@ -0,0 +1,30 @@ +#include + +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 func() +{ + const void_fp fp = f2; + fp(); +} + +int main() +{ + func(); + + return 0; +} diff --git a/regression/goto-instrument/precise-const-fp-remove-all-fp/test.desc b/regression/goto-instrument/precise-const-fp-remove-all-fp/test.desc new file mode 100644 index 00000000000..58ccee3a018 --- /dev/null +++ b/regression/goto-instrument/precise-const-fp-remove-all-fp/test.desc @@ -0,0 +1,7 @@ +CORE +main.c +--verbosity 10 --pointer-check --remove-function-pointers + +^\s*f2(); +-- +^warning: ignoring diff --git a/src/goto-instrument/goto_instrument_parse_options.cpp b/src/goto-instrument/goto_instrument_parse_options.cpp index 3e923bd5103..7af3323d8e8 100644 --- a/src/goto-instrument/goto_instrument_parse_options.cpp +++ b/src/goto-instrument/goto_instrument_parse_options.cpp @@ -820,6 +820,39 @@ void goto_instrument_parse_optionst::do_indirect_call_and_rtti_removal( /*******************************************************************\ +Function: goto_instrument_parse_optionst::do_remove_const_function_pointers_only + + Inputs: + + Outputs: + + Purpose: Remove function pointers that can be resolved by analysing + const variables (i.e. can be resolved using + remove_const_function_pointers). Function pointers that cannot + be resolved will be left as function pointers. + +\*******************************************************************/ + +void goto_instrument_parse_optionst::do_remove_const_function_pointers_only() +{ + // Don't bother if we've already done a full function pointer + // removal. + if(function_pointer_removal_done) + { + return; + } + + status() << "Removing const function pointers only" << eom; + remove_function_pointers( + get_message_handler(), + symbol_table, + goto_functions, + cmdline.isset("pointer-check"), + true); // abort if we can't resolve via const pointers +} + +/*******************************************************************\ + Function: goto_instrument_parse_optionst::do_partial_inlining Inputs: @@ -1046,7 +1079,13 @@ void goto_instrument_parse_optionst::instrument_goto_program() // replace function pointers, if explicitly requested if(cmdline.isset("remove-function-pointers")) + { do_indirect_call_and_rtti_removal(); + } + else if(cmdline.isset("remove-const-function-pointers")) + { + do_remove_const_function_pointers_only(); + } if(cmdline.isset("function-inline")) { @@ -1556,6 +1595,7 @@ void goto_instrument_parse_optionst::help() " --no-caching disable caching of intermediate results during transitive function inlining\n" // NOLINT(*) " --log log in json format which code segments were inlined, use with --function-inline\n" // NOLINT(*) " --remove-function-pointers replace function pointers by case statement over function calls\n" // NOLINT(*) + HELP_REMOVE_CONST_FUNCTION_POINTERS " --add-library add models of C library functions\n" " --model-argc-argv model up to command line arguments\n" "\n" diff --git a/src/goto-instrument/goto_instrument_parse_options.h b/src/goto-instrument/goto_instrument_parse_options.h index d3efb975767..d4054b6e0a4 100644 --- a/src/goto-instrument/goto_instrument_parse_options.h +++ b/src/goto-instrument/goto_instrument_parse_options.h @@ -15,6 +15,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include #include +#include #include @@ -54,6 +55,7 @@ Author: Daniel Kroening, kroening@kroening.com "(show-uninitialized)(show-locations)" \ "(full-slice)(reachability-slice)(slice-global-inits)" \ "(inline)(partial-inline)(function-inline):(log):(no-caching)" \ + OPT_REMOVE_CONST_FUNCTION_POINTERS \ "(remove-function-pointers)" \ "(show-claims)(show-properties)(property):" \ "(show-symbol-table)(show-points-to)(show-rw-set)" \ @@ -98,6 +100,7 @@ class goto_instrument_parse_optionst: void eval_verbosity(); void do_indirect_call_and_rtti_removal(bool force=false); + void do_remove_const_function_pointers_only(); void do_partial_inlining(); void do_remove_returns(); diff --git a/src/goto-programs/remove_const_function_pointers.h b/src/goto-programs/remove_const_function_pointers.h index 1847ef56849..6516fb6ec64 100644 --- a/src/goto-programs/remove_const_function_pointers.h +++ b/src/goto-programs/remove_const_function_pointers.h @@ -95,4 +95,11 @@ class remove_const_function_pointerst:public messaget const symbol_tablet &symbol_table; }; +#define OPT_REMOVE_CONST_FUNCTION_POINTERS \ + "(remove-const-function-pointers)" + +#define HELP_REMOVE_CONST_FUNCTION_POINTERS \ + " --remove-const-function-pointers Remove function pointers that are constant or constant part of an array\n" // NOLINT(*) + + #endif // CPROVER_GOTO_PROGRAMS_REMOVE_CONST_FUNCTION_POINTERS_H diff --git a/src/goto-programs/remove_function_pointers.cpp b/src/goto-programs/remove_function_pointers.cpp index 4c505cdc191..a2500efd3ea 100644 --- a/src/goto-programs/remove_function_pointers.cpp +++ b/src/goto-programs/remove_function_pointers.cpp @@ -38,6 +38,7 @@ class remove_function_pointerst:public messaget message_handlert &_message_handler, symbol_tablet &_symbol_table, bool _add_safety_assertion, + bool only_resolve_const_fps, const goto_functionst &goto_functions); void operator()(goto_functionst &goto_functions); @@ -49,6 +50,14 @@ class remove_function_pointerst:public messaget symbol_tablet &symbol_table; bool add_safety_assertion; + // We can optionally halt the FP removal if we aren't able to use + // remove_const_function_pointerst to sucessfully narrow to a small + // subset of possible functions and just leave the function pointer + // as it is. + // This can be activated in goto-instrument using + // --remove-const-function-pointers instead of --remove-function-pointers + bool only_resolve_const_fps; + void remove_function_pointer( goto_programt &goto_program, goto_programt::targett target); @@ -97,12 +106,13 @@ Function: remove_function_pointerst::remove_function_pointerst remove_function_pointerst::remove_function_pointerst( message_handlert &_message_handler, symbol_tablet &_symbol_table, - bool _add_safety_assertion, + bool _add_safety_assertion, bool only_resolve_const_fps, const goto_functionst &goto_functions): messaget(_message_handler), ns(_symbol_table), symbol_table(_symbol_table), - add_safety_assertion(_add_safety_assertion) + add_safety_assertion(_add_safety_assertion), + only_resolve_const_fps(only_resolve_const_fps) { compute_address_taken_in_symbols(address_taken); compute_address_taken_functions(goto_functions, address_taken); @@ -366,6 +376,17 @@ void remove_function_pointerst::remove_function_pointer( if(!found_functions) { + if(only_resolve_const_fps) + { + // If this mode is enabled, we only remove function pointers + // that we can resolve either to an exact funciton, or an exact subset + // (e.g. a variable index in a constant array). + // Since we haven't found functions, we would now resort to + // replacing the function pointer with any function with a valid signature + // Since we don't want to do that, we abort. + return; + } + bool return_value_used=code.lhs().is_not_nil(); // get all type-compatible functions @@ -554,15 +575,20 @@ Function: remove_function_pointers \*******************************************************************/ -bool remove_function_pointers( - message_handlert &_message_handler, +bool remove_function_pointers(message_handlert &_message_handler, symbol_tablet &symbol_table, const goto_functionst &goto_functions, goto_programt &goto_program, - bool add_safety_assertion) + bool add_safety_assertion, + bool only_remove_const_fps) { remove_function_pointerst - rfp(_message_handler, symbol_table, add_safety_assertion, goto_functions); + rfp( + _message_handler, + symbol_table, + add_safety_assertion, + only_remove_const_fps, + goto_functions); return rfp.remove_function_pointers(goto_program); } @@ -583,10 +609,16 @@ void remove_function_pointers( message_handlert &_message_handler, symbol_tablet &symbol_table, goto_functionst &goto_functions, - bool add_safety_assertion) + bool add_safety_assertion, + bool only_remove_const_fps) { remove_function_pointerst - rfp(_message_handler, symbol_table, add_safety_assertion, goto_functions); + rfp( + _message_handler, + symbol_table, + add_safety_assertion, + only_remove_const_fps, + goto_functions); rfp(goto_functions); } @@ -603,14 +635,15 @@ Function: remove_function_pointers \*******************************************************************/ -void remove_function_pointers( - message_handlert &_message_handler, +void remove_function_pointers(message_handlert &_message_handler, goto_modelt &goto_model, - bool add_safety_assertion) + bool add_safety_assertion, + bool only_remove_const_fps) { remove_function_pointers( _message_handler, goto_model.symbol_table, goto_model.goto_functions, - add_safety_assertion); + add_safety_assertion, + only_remove_const_fps); } diff --git a/src/goto-programs/remove_function_pointers.h b/src/goto-programs/remove_function_pointers.h index 0320a77c9a2..e8eea37ea75 100644 --- a/src/goto-programs/remove_function_pointers.h +++ b/src/goto-programs/remove_function_pointers.h @@ -19,19 +19,22 @@ Date: June 2003 void remove_function_pointers( message_handlert &_message_handler, goto_modelt &goto_model, - bool add_safety_assertion); + bool add_safety_assertion, + bool only_remove_const_fps=false); void remove_function_pointers( message_handlert &_message_handler, symbol_tablet &symbol_table, goto_functionst &goto_functions, - bool add_safety_assertion); + bool add_safety_assertion, + bool only_remove_const_fps=false); bool remove_function_pointers( message_handlert &_message_handler, symbol_tablet &symbol_table, const goto_functionst &goto_functions, goto_programt &goto_program, - bool add_safety_assertion); + bool add_safety_assertion, + bool only_remove_const_fps=false); #endif // CPROVER_GOTO_PROGRAMS_REMOVE_FUNCTION_POINTERS_H From 052da5a6471dedd8b5f97ca8eaffaafb7f1730db Mon Sep 17 00:00:00 2001 From: thk123 Date: Tue, 14 Feb 2017 17:19:41 +0000 Subject: [PATCH 39/46] Check the GOTO program for loss of const Before removing const function pointers using remove_const_function_pointerst we check each instruction in the goto program for assigns where the RHS is more const than the LHS. This includes both implicit and explicit casting away of const. If this has happened to something relating to a function pointer, then our optimization is not sound, so if we find any we just abandon this optimization. This is acceptable since it is undefined behavior anyway to be modifying a const variable. --- .../no-match-const-fp-const-cast/main.c | 35 +++++ .../no-match-const-fp-const-cast/test.desc | 16 ++ .../no-match-const-fp-const-lost/main.c | 35 +++++ .../no-match-const-fp-const-lost/test.desc | 16 ++ .../main.c | 45 ++++++ .../test.desc | 17 ++ .../remove_function_pointers.cpp | 146 ++++++++++++++++-- 7 files changed, 298 insertions(+), 12 deletions(-) create mode 100644 regression/goto-analyzer/no-match-const-fp-const-cast/main.c create mode 100644 regression/goto-analyzer/no-match-const-fp-const-cast/test.desc create mode 100644 regression/goto-analyzer/no-match-const-fp-const-lost/main.c create mode 100644 regression/goto-analyzer/no-match-const-fp-const-lost/test.desc create mode 100644 regression/goto-analyzer/no-match-const-pointer-const-struct-const-fp-const-cast/main.c create mode 100644 regression/goto-analyzer/no-match-const-pointer-const-struct-const-fp-const-cast/test.desc diff --git a/regression/goto-analyzer/no-match-const-fp-const-cast/main.c b/regression/goto-analyzer/no-match-const-fp-const-cast/main.c new file mode 100644 index 00000000000..f7fa7f41b42 --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-const-cast/main.c @@ -0,0 +1,35 @@ +#include + +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 func() +{ + const void_fp fp = f2; + + // Warning: this loses const-ness of f2 + void_fp * p2fp = (void_fp*)&fp; + *p2fp = &f4; + + fp(); +} + +int main() +{ + func(); + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-fp-const-cast/test.desc b/regression/goto-analyzer/no-match-const-fp-const-cast/test.desc new file mode 100644 index 00000000000..e8357d911c6 --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-const-cast/test.desc @@ -0,0 +1,16 @@ +CORE +main.c +--show-goto-functions --verbosity 10 --pointer-check + +^Removing function pointers and virtual functions$ +^\s*IF fp == f1 THEN GOTO [0-9]$ +^\s*IF fp == f2 THEN GOTO [0-9]$ +^\s*IF fp == f3 THEN GOTO [0-9]$ +^\s*IF fp == f4 THEN GOTO [0-9]$ +^\s*IF fp == f5 THEN GOTO [0-9]$ +^\s*IF fp == f6 THEN GOTO [0-9]$ +^\s*IF fp == f7 THEN GOTO [0-9]$ +^\s*IF fp == f8 THEN GOTO [0-9]$ +^\s*IF fp == f9 THEN GOTO [0-9]$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-const-lost/main.c b/regression/goto-analyzer/no-match-const-fp-const-lost/main.c new file mode 100644 index 00000000000..edeca0d3f79 --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-const-lost/main.c @@ -0,0 +1,35 @@ +#include + +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 func() +{ + const void_fp fp = f2; + + // Warning: this loses const-ness of f2 + void_fp * p2fp = &fp; + *p2fp = &f4; + + fp(); +} + +int main() +{ + func(); + + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/no-match-const-fp-const-lost/test.desc b/regression/goto-analyzer/no-match-const-fp-const-lost/test.desc new file mode 100644 index 00000000000..e8357d911c6 --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-const-lost/test.desc @@ -0,0 +1,16 @@ +CORE +main.c +--show-goto-functions --verbosity 10 --pointer-check + +^Removing function pointers and virtual functions$ +^\s*IF fp == f1 THEN GOTO [0-9]$ +^\s*IF fp == f2 THEN GOTO [0-9]$ +^\s*IF fp == f3 THEN GOTO [0-9]$ +^\s*IF fp == f4 THEN GOTO [0-9]$ +^\s*IF fp == f5 THEN GOTO [0-9]$ +^\s*IF fp == f6 THEN GOTO [0-9]$ +^\s*IF fp == f7 THEN GOTO [0-9]$ +^\s*IF fp == f8 THEN GOTO [0-9]$ +^\s*IF fp == f9 THEN GOTO [0-9]$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-pointer-const-struct-const-fp-const-cast/main.c b/regression/goto-analyzer/no-match-const-pointer-const-struct-const-fp-const-cast/main.c new file mode 100644 index 00000000000..b7b9e4d2b30 --- /dev/null +++ b/regression/goto-analyzer/no-match-const-pointer-const-struct-const-fp-const-cast/main.c @@ -0,0 +1,45 @@ +#include + +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}; + +typedef struct fp_cc +{ + int x; + void_fp fp; +} fp_cc; + + + +void func() +{ + const fp_cc container_container = { .fp = f2, .x = 4 }; + + const fp_cc * const container_pointer = &container_container; + + fp_cc* container_pointer_modifier = (fp_cc*) container_pointer; + container_pointer_modifier->fp = f4; + + // Illegal: + // container_container.container = &f4; + + container_pointer->fp(); +} + +int main() +{ + func(); +} diff --git a/regression/goto-analyzer/no-match-const-pointer-const-struct-const-fp-const-cast/test.desc b/regression/goto-analyzer/no-match-const-pointer-const-struct-const-fp-const-cast/test.desc new file mode 100644 index 00000000000..2f4b2832b4d --- /dev/null +++ b/regression/goto-analyzer/no-match-const-pointer-const-struct-const-fp-const-cast/test.desc @@ -0,0 +1,17 @@ +CORE +main.c +--show-goto-functions --verbosity 10 --pointer-check + +^Removing function pointers and virtual functions$ +^\s*IF container_pointer->fp == f1 THEN GOTO [0-9]$ +^\s*IF container_pointer->fp == f2 THEN GOTO [0-9]$ +^\s*IF container_pointer->fp == f3 THEN GOTO [0-9]$ +^\s*IF container_pointer->fp == f4 THEN GOTO [0-9]$ +^\s*IF container_pointer->fp == f5 THEN GOTO [0-9]$ +^\s*IF container_pointer->fp == f6 THEN GOTO [0-9]$ +^\s*IF container_pointer->fp == f7 THEN GOTO [0-9]$ +^\s*IF container_pointer->fp == f8 THEN GOTO [0-9]$ +^\s*IF container_pointer->fp == f9 THEN GOTO [0-9]$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/src/goto-programs/remove_function_pointers.cpp b/src/goto-programs/remove_function_pointers.cpp index a2500efd3ea..dd20bedeb6d 100644 --- a/src/goto-programs/remove_function_pointers.cpp +++ b/src/goto-programs/remove_function_pointers.cpp @@ -15,6 +15,8 @@ Author: Daniel Kroening, kroening@kroening.com #include #include #include +#include +#include #include @@ -62,6 +64,11 @@ class remove_function_pointerst:public messaget goto_programt &goto_program, goto_programt::targett target); + bool does_program_contain_const_removal_cast( + const goto_programt &goto_program); + + bool is_type_at_least_as_const_as(typet type_more_const, typet type_compare); + std::set address_taken; typedef std::map type_mapt; @@ -353,25 +360,36 @@ void remove_function_pointerst::remove_function_pointer( assert(function.id()==ID_dereference); assert(function.operands().size()==1); + bool found_functions; + const exprt &pointer=function.op0(); remove_const_function_pointerst::functionst functions; - remove_const_function_pointerst fpr( + if(does_program_contain_const_removal_cast(goto_program)) + { + warning() << "Cast from const to non-const pointer found, only worst case" + << " function pointer removal will be done." << eom; + found_functions=false; + } + else + { + remove_const_function_pointerst fpr( get_message_handler(), pointer, ns, symbol_table); - bool found_functions=fpr(functions); + found_functions=fpr(functions); - // Consistency checks - // Reported optimized function pointer call, but didn't find any functions - assert(!found_functions || !functions.empty()); + // Consistency checks + // Reported optimized function pointer call, but didn't find any functions + assert(!found_functions || !functions.empty()); - // Reported didn't optimize function pointer call, but did find some - // functions to replace with - assert(found_functions || functions.empty()); + // Reported didn't optimize function pointer call, but did find some + // functions to replace with + assert(found_functions || functions.empty()); - if(functions.size()==1) - { - to_code_function_call(target->code).function()=*functions.cbegin(); - return; + if(functions.size()==1) + { + to_code_function_call(target->code).function()=*functions.cbegin(); + return; + } } if(!found_functions) @@ -495,6 +513,110 @@ void remove_function_pointerst::remove_function_pointer( /*******************************************************************\ +Function: remove_function_pointerst::does_program_contain_const_removal_cast + + Inputs: + goto_program - the goto program to check + + Outputs: Returns true if any instruction in the code casts away either + explicitly or implicitly the const qualifier of a type. + + Purpose: A naive check to look for casts that remove const-ness from + pointers. If this is present, then our remove_const_function_pointerst + is not sound so we don't allow it. + +\*******************************************************************/ + +bool remove_function_pointerst::does_program_contain_const_removal_cast( + const goto_programt &goto_program) +{ + for(const goto_programt::instructiont &instruction : + goto_program.instructions) + { + if(instruction.is_assign()) + { + const code_assignt assign=to_code_assign(instruction.code); + typet rhs_type=assign.rhs().type(); + typet lhs_type=assign.lhs().type(); + + // Compare the types recursively for a point where the rhs is more + // const that the lhs + if(!is_type_at_least_as_const_as(lhs_type, rhs_type)) + { + return true; + } + + // see if the rhs loses const inside the expression tree + exprt rhs=assign.rhs(); + while(!rhs.operands().empty()) + { + typet &pre_op_type=rhs.type(); + typet &post_op_type=rhs.op0().type(); + + // Types equality does not check, for example, const-ness + // If this is true, then this expression only modified the + // type by some qualifier (or not at all) + if(base_type_eq(pre_op_type, post_op_type, ns)) + { + if(!is_type_at_least_as_const_as(pre_op_type, post_op_type)) + { + return true; + } + } + rhs=rhs.op0(); + } + } + } + + return false; +} + +/*******************************************************************\ + +Function: remove_function_pointerst::is_type_at_least_as_const_as + + Inputs: + type_more_const - the type we are expecting to be at least as const qualified + type_compare - the type we are comparing against which may be less const + qualified + + Outputs: Returns true if type_more_const is at least as const as type_compare + + Purpose: A recursive check to check the type_more_const is at least as const + as type compare. + + type_more_const | type_compare || result + ---------------------------------------- + const int * | const int * -> true + int * | const int * -> false + const int * | int * -> true + int * | int * const -> false + +\*******************************************************************/ + +bool remove_function_pointerst::is_type_at_least_as_const_as( + typet type_more_const, typet type_compare) +{ + while(!type_compare.id().empty() && !type_more_const.id().empty()) + { + const c_qualifierst rhs_qualifiers(type_compare); + const c_qualifierst lhs_qualifiers(type_more_const); + if(rhs_qualifiers.is_constant && !lhs_qualifiers.is_constant) + { + return false; + } + + type_compare=type_compare.subtype(); + type_more_const=type_more_const.subtype(); + } + + // Both the types should have the same number of subtypes + assert(type_compare.id()=="" && type_more_const.id()==""); + return true; +} + +/*******************************************************************\ + Function: remove_function_pointerst::remove_function_pointers Inputs: From 6ba046908cac6647c551db1a941c28d3778d8fd7 Mon Sep 17 00:00:00 2001 From: thk123 Date: Thu, 16 Feb 2017 12:09:38 +0000 Subject: [PATCH 40/46] Added a couple of missed test cases. Added test for run time const arrays. Adding test case for pointer to struct --- .../main.c | 32 ++++++++++++++ .../test.desc | 8 ++++ .../main.c | 43 +++++++++++++++++++ .../test.desc | 9 ++++ 4 files changed, 92 insertions(+) create mode 100644 regression/goto-analyzer/precise-const-fp-array-literal-const-fp-run-time/main.c create mode 100644 regression/goto-analyzer/precise-const-fp-array-literal-const-fp-run-time/test.desc create mode 100644 regression/goto-analyzer/precise-const-pointer-const-struct-fp/main.c create mode 100644 regression/goto-analyzer/precise-const-pointer-const-struct-fp/test.desc diff --git a/regression/goto-analyzer/precise-const-fp-array-literal-const-fp-run-time/main.c b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp-run-time/main.c new file mode 100644 index 00000000000..36e4da04ddf --- /dev/null +++ b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp-run-time/main.c @@ -0,0 +1,32 @@ +#include + +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 func() +{ + const void_fp fp_tbl[] = {f2, f3}; + // Illegal: + //fp_tbl[1] = f4; + const void_fp fp = fp_tbl[1]; + fp(); +} + +int main() +{ + func(); + return 0; +} \ No newline at end of file diff --git a/regression/goto-analyzer/precise-const-fp-array-literal-const-fp-run-time/test.desc b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp-run-time/test.desc new file mode 100644 index 00000000000..0e57c1a7db3 --- /dev/null +++ b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp-run-time/test.desc @@ -0,0 +1,8 @@ +CORE +main.c +--show-goto-functions --verbosity 10 --pointer-check + +^Removing function pointers and virtual functions$ +^\s*f3();$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/precise-const-pointer-const-struct-fp/main.c b/regression/goto-analyzer/precise-const-pointer-const-struct-fp/main.c new file mode 100644 index 00000000000..e1671666b2b --- /dev/null +++ b/regression/goto-analyzer/precise-const-pointer-const-struct-fp/main.c @@ -0,0 +1,43 @@ +#include + +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}; + +typedef struct fp_cc +{ + int x; + void_fp fp; +} fp_cc; + + + +void func() +{ + const fp_cc container_container = { .fp = f2, .x = 4 }; + + const fp_cc * const container_pointer = &container_container; + + // Illegal: + //meta_fp = &f4; + //container_container.container = &f4; + + container_pointer->fp(); +} + +int main() +{ + func(); +} diff --git a/regression/goto-analyzer/precise-const-pointer-const-struct-fp/test.desc b/regression/goto-analyzer/precise-const-pointer-const-struct-fp/test.desc new file mode 100644 index 00000000000..9d578669db7 --- /dev/null +++ b/regression/goto-analyzer/precise-const-pointer-const-struct-fp/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--show-goto-functions --verbosity 10 --pointer-check + +^Removing function pointers and virtual functions$ +^\s*f2();$ +^SIGNAL=0$ +-- +^warning: ignoring From 18b590778787ca3a9802a826dc6a570be4e0350a Mon Sep 17 00:00:00 2001 From: thk123 Date: Thu, 16 Feb 2017 14:04:02 +0000 Subject: [PATCH 41/46] Fixing tests to work with new test.pl The new test.pl script requrires breaks to be escaped. --- .../approx-array-variable-const-fp/test.desc | 18 +++++++++--------- .../test.desc | 12 ++++++------ .../test.desc | 12 ++++++------ .../test.desc | 12 ++++++------ .../test.desc | 12 ++++++------ .../test.desc | 12 ++++++------ .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 2 +- .../precise-array-literal-const-fp/test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../precise-const-fp-const-fp/test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../goto-analyzer/precise-const-fp/test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../goto-analyzer/precise-derefence/test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 2 +- .../test.desc | 18 +++++++++--------- .../test.desc | 18 +++++++++--------- .../test.desc | 2 +- .../test.desc | 2 +- .../precise-const-fp-remove-all-fp/test.desc | 2 +- 35 files changed, 108 insertions(+), 108 deletions(-) diff --git a/regression/goto-analyzer/approx-array-variable-const-fp/test.desc b/regression/goto-analyzer/approx-array-variable-const-fp/test.desc index 28b95c5ac33..83a930d1c36 100644 --- a/regression/goto-analyzer/approx-array-variable-const-fp/test.desc +++ b/regression/goto-analyzer/approx-array-variable-const-fp/test.desc @@ -3,15 +3,15 @@ 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]$ +^\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]$ +^\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 diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc index 973fbe34127..a937e306d31 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc @@ -9,9 +9,9 @@ main.c ^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]$ +^\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]$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc index 973fbe34127..a937e306d31 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc @@ -9,9 +9,9 @@ main.c ^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]$ +^\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]$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc index 973fbe34127..a937e306d31 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc @@ -9,9 +9,9 @@ main.c ^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]$ +^\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]$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc index 973fbe34127..a937e306d31 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc @@ -9,9 +9,9 @@ main.c ^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]$ +^\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]$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc index 973fbe34127..a937e306d31 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc @@ -9,9 +9,9 @@ main.c ^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]$ +^\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]$ diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc b/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc index 5459b630bc9..b6e93d5b677 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc +++ b/regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF fp == (void (\*)(void))f2 THEN GOTO [0-9]$ -^\s*IF fp == (void (\*)(void))f3 THEN GOTO [0-9]$ -^\s*IF fp == (void (\*)(void))f4 THEN GOTO [0-9]$ +^\s*IF fp == \(void \(\*\)\(void\)\)f2 THEN GOTO [0-9]$ +^\s*IF fp == \(void \(\*\)\(void\)\)f3 THEN GOTO [0-9]$ +^\s*IF fp == \(void \(\*\)\(void\)\)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]$ +^\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]$ diff --git a/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/test.desc b/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/test.desc index 9abe6fde56a..7e0aca75523 100644 --- a/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-dereference-const-pointer-const-array-literal-pointer-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f1 THEN GOTO [0-9]$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f2 THEN GOTO [0-9]$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f3 THEN GOTO [0-9]$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f4 THEN GOTO [0-9]$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f5 THEN GOTO [0-9]$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f6 THEN GOTO [0-9]$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f7 THEN GOTO [0-9]$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f8 THEN GOTO [0-9]$ -^\s*IF \*container_ptr->fp_tbl\[(signed long int)1\] == f9 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[\(signed long int\)1\] == f1 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[\(signed long int\)1\] == f2 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[\(signed long int\)1\] == f3 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[\(signed long int\)1\] == f4 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[\(signed long int\)1\] == f5 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[\(signed long int\)1\] == f6 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[\(signed long int\)1\] == f7 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[\(signed long int\)1\] == f8 THEN GOTO [0-9]$ +^\s*IF \*container_ptr->fp_tbl\[\(signed long int\)1\] == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/test.desc b/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/test.desc index 3f90b23b7d4..83a4d98d9f4 100644 --- a/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-pointer-const-struct-array-literal-non-const-fp/test.desc @@ -3,15 +3,15 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f1 THEN GOTO [0-9]$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f2 THEN GOTO [0-9]$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f3 THEN GOTO [0-9]$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f4 THEN GOTO [0-9]$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f5 THEN GOTO [0-9]$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f6 THEN GOTO [0-9]$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f7 THEN GOTO [0-9]$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f8 THEN GOTO [0-9]$ -^\s*IF container_ptr->fp_tbl\[(signed long int)1\] == f9 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[\(signed long int\)1\] == f1 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[\(signed long int\)1\] == f2 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[\(signed long int\)1\] == f3 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[\(signed long int\)1\] == f4 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[\(signed long int\)1\] == f5 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[\(signed long int\)1\] == f6 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[\(signed long int\)1\] == f7 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[\(signed long int\)1\] == f8 THEN GOTO [0-9]$ +^\s*IF container_ptr->fp_tbl\[\(signed long int\)1\] == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-array-calculation-const-fp/test.desc b/regression/goto-analyzer/precise-array-calculation-const-fp/test.desc index 9716d23800e..fad0e6c7a1d 100644 --- a/regression/goto-analyzer/precise-array-calculation-const-fp/test.desc +++ b/regression/goto-analyzer/precise-array-calculation-const-fp/test.desc @@ -2,7 +2,7 @@ CORE main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f3();$ +^\s*f3\(\);$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-array-literal-const-fp/test.desc b/regression/goto-analyzer/precise-array-literal-const-fp/test.desc index 9716d23800e..fad0e6c7a1d 100644 --- a/regression/goto-analyzer/precise-array-literal-const-fp/test.desc +++ b/regression/goto-analyzer/precise-array-literal-const-fp/test.desc @@ -2,7 +2,7 @@ CORE main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f3();$ +^\s*f3\(\);$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/test.desc index 9716d23800e..fad0e6c7a1d 100644 --- a/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/test.desc @@ -2,7 +2,7 @@ CORE main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f3();$ +^\s*f3\(\);$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-const-fp-array-literal-const-fp-run-time/test.desc b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp-run-time/test.desc index 0e57c1a7db3..6c7de56a1a0 100644 --- a/regression/goto-analyzer/precise-const-fp-array-literal-const-fp-run-time/test.desc +++ b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp-run-time/test.desc @@ -3,6 +3,6 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f3();$ +^\s*f3\(\);$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/test.desc index 9716d23800e..fad0e6c7a1d 100644 --- a/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/test.desc @@ -2,7 +2,7 @@ CORE main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f3();$ +^\s*f3\(\);$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/test.desc index 313435441b0..2eff811f4bc 100644 --- a/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-array-literal-const-struct-non-const-fp/test.desc @@ -3,7 +3,7 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f3();$ +^\s*f3\(\);$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc index 5d0951328b4..eb1e2781ef1 100644 --- a/regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc @@ -3,7 +3,7 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f2(); +^\s*f2\(\); ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-const-fp-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-const-fp/test.desc index 9852b6f4f36..40361f6ccc2 100644 --- a/regression/goto-analyzer/precise-const-fp-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-const-fp/test.desc @@ -2,7 +2,7 @@ CORE main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f2();$ +^\s*f2\(\);$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/test.desc b/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/test.desc index 313435441b0..2eff811f4bc 100644 --- a/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-const-struct-const-array-literal-fp/test.desc @@ -3,7 +3,7 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f3();$ +^\s*f3\(\);$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/test.desc b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/test.desc index 313435441b0..2eff811f4bc 100644 --- a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/test.desc @@ -3,7 +3,7 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f3();$ +^\s*f3\(\);$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/test.desc index 5d0951328b4..eb1e2781ef1 100644 --- a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/test.desc @@ -3,7 +3,7 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f2(); +^\s*f2\(\); ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/test.desc index 313435441b0..2eff811f4bc 100644 --- a/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/test.desc @@ -3,7 +3,7 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f3();$ +^\s*f3\(\);$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-const-fp/test.desc b/regression/goto-analyzer/precise-const-fp/test.desc index 8de39dddaab..ef4cf690b60 100644 --- a/regression/goto-analyzer/precise-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-fp/test.desc @@ -3,6 +3,6 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f2(); +^\s*f2\(\); -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-const-pointer-const-struct-fp/test.desc b/regression/goto-analyzer/precise-const-pointer-const-struct-fp/test.desc index 9d578669db7..0de6942ba42 100644 --- a/regression/goto-analyzer/precise-const-pointer-const-struct-fp/test.desc +++ b/regression/goto-analyzer/precise-const-pointer-const-struct-fp/test.desc @@ -3,7 +3,7 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f2();$ +^\s*f2\(\);$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-const-struct-non-const-fp/test.desc b/regression/goto-analyzer/precise-const-struct-non-const-fp/test.desc index 5d0951328b4..eb1e2781ef1 100644 --- a/regression/goto-analyzer/precise-const-struct-non-const-fp/test.desc +++ b/regression/goto-analyzer/precise-const-struct-non-const-fp/test.desc @@ -3,7 +3,7 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f2(); +^\s*f2\(\); ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/test.desc b/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/test.desc index 313435441b0..2eff811f4bc 100644 --- a/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/test.desc @@ -3,7 +3,7 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f3();$ +^\s*f3\(\);$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-derefence/test.desc b/regression/goto-analyzer/precise-derefence/test.desc index 8de39dddaab..ef4cf690b60 100644 --- a/regression/goto-analyzer/precise-derefence/test.desc +++ b/regression/goto-analyzer/precise-derefence/test.desc @@ -3,6 +3,6 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f2(); +^\s*f2\(\); -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/test.desc b/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/test.desc index 313435441b0..2eff811f4bc 100644 --- a/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/test.desc @@ -3,7 +3,7 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f3();$ +^\s*f3\(\);$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-fp/test.desc b/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-fp/test.desc index 313435441b0..2eff811f4bc 100644 --- a/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-fp/test.desc @@ -3,7 +3,7 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f3();$ +^\s*f3\(\);$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-struct-const-fp/test.desc b/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-struct-const-fp/test.desc index 313435441b0..2eff811f4bc 100644 --- a/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-struct-const-fp/test.desc +++ b/regression/goto-analyzer/precise-dereference-const-struct-const-pointer-const-struct-const-fp/test.desc @@ -3,7 +3,7 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f3();$ +^\s*f3\(\);$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-analyzer/precise-dereference-const-struct-pointer-const-fp/test.desc b/regression/goto-analyzer/precise-dereference-const-struct-pointer-const-fp/test.desc index 313435441b0..2eff811f4bc 100644 --- a/regression/goto-analyzer/precise-dereference-const-struct-pointer-const-fp/test.desc +++ b/regression/goto-analyzer/precise-dereference-const-struct-pointer-const-fp/test.desc @@ -3,7 +3,7 @@ main.c --show-goto-functions --verbosity 10 --pointer-check ^Removing function pointers and virtual functions$ -^\s*f3();$ +^\s*f3\(\);$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-instrument/approx-array-variable-const-fp-only-remove-const/test.desc b/regression/goto-instrument/approx-array-variable-const-fp-only-remove-const/test.desc index 3c712e97b99..f58b03a58b3 100644 --- a/regression/goto-instrument/approx-array-variable-const-fp-only-remove-const/test.desc +++ b/regression/goto-instrument/approx-array-variable-const-fp-only-remove-const/test.desc @@ -2,15 +2,15 @@ CORE main.c --verbosity 10 --pointer-check --remove-const-function-pointers -^\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]$ +^\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]$ +^\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 diff --git a/regression/goto-instrument/approx-array-variable-const-fp-remove-all-fp/test.desc b/regression/goto-instrument/approx-array-variable-const-fp-remove-all-fp/test.desc index 7cd546580d7..3d065f1a742 100644 --- a/regression/goto-instrument/approx-array-variable-const-fp-remove-all-fp/test.desc +++ b/regression/goto-instrument/approx-array-variable-const-fp-remove-all-fp/test.desc @@ -2,15 +2,15 @@ CORE main.c --verbosity 10 --pointer-check --remove-function-pointers -^\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]$ +^\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]$ +^\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 diff --git a/regression/goto-instrument/no-match-non-const-fp-only-remove-const/test.desc b/regression/goto-instrument/no-match-non-const-fp-only-remove-const/test.desc index ff5e6a916e1..3b016907a44 100644 --- a/regression/goto-instrument/no-match-non-const-fp-only-remove-const/test.desc +++ b/regression/goto-instrument/no-match-non-const-fp-only-remove-const/test.desc @@ -2,7 +2,7 @@ CORE main.c --verbosity 10 --pointer-check --remove-const-function-pointers -^\s*fp();$ +^\s*fp\(\);$ ^SIGNAL=0$ -- ^warning: ignoring diff --git a/regression/goto-instrument/precise-const-fp-only-remove-const/test.desc b/regression/goto-instrument/precise-const-fp-only-remove-const/test.desc index e125fff93f4..2304d56b239 100644 --- a/regression/goto-instrument/precise-const-fp-only-remove-const/test.desc +++ b/regression/goto-instrument/precise-const-fp-only-remove-const/test.desc @@ -2,6 +2,6 @@ CORE main.c --verbosity 10 --pointer-check --remove-const-function-pointers -^\s*f2(); +^\s*f2\(\); -- ^warning: ignoring diff --git a/regression/goto-instrument/precise-const-fp-remove-all-fp/test.desc b/regression/goto-instrument/precise-const-fp-remove-all-fp/test.desc index 58ccee3a018..dd072b1c232 100644 --- a/regression/goto-instrument/precise-const-fp-remove-all-fp/test.desc +++ b/regression/goto-instrument/precise-const-fp-remove-all-fp/test.desc @@ -2,6 +2,6 @@ CORE main.c --verbosity 10 --pointer-check --remove-function-pointers -^\s*f2(); +^\s*f2\(\); -- ^warning: ignoring From 2538f4f31fbbdce8842b8a46d3219234fb1a23ad Mon Sep 17 00:00:00 2001 From: thk123 Date: Mon, 20 Feb 2017 12:19:00 +0000 Subject: [PATCH 42/46] Fixing missing new lines --- regression/goto-analyzer/approx-array-variable-const-fp/main.c | 2 +- .../approx-const-fp-array-variable-cast-const-fp/main.c | 2 +- .../approx-const-fp-array-variable-const-fp-with-null/main.c | 2 +- .../approx-const-fp-array-variable-const-fp/main.c | 2 +- .../main.c | 2 +- .../goto-analyzer/no-match-array-literal-const-fp-null/main.c | 2 +- .../no-match-const-fp-array-literal-const-fp-run-time/main.c | 2 +- .../main.c | 2 +- .../no-match-const-fp-array-literal-non-const-fp/main.c | 2 +- .../goto-analyzer/no-match-const-fp-array-non-const-fp/main.c | 2 +- regression/goto-analyzer/no-match-const-fp-const-cast/main.c | 2 +- regression/goto-analyzer/no-match-const-fp-const-fp-null/main.c | 2 +- regression/goto-analyzer/no-match-const-fp-const-lost/main.c | 2 +- .../main.c | 2 +- .../no-match-const-fp-dereference-const-pointer-null/main.c | 2 +- .../main.c | 2 +- .../no-match-const-fp-dynamic-array-non-const-fp/main.c | 2 +- .../no-match-const-fp-non-const-fp-direct-assignment/main.c | 2 +- .../main.c | 2 +- .../no-match-const-fp-non-const-struct-const-fp/main.c | 2 +- .../no-match-const-fp-non-const-struct-non-const-fp/main.c | 2 +- regression/goto-analyzer/no-match-const-fp-null/main.c | 2 +- .../no-match-const-pointer-non-const-struct-const-fp/main.c | 2 +- .../no-match-const-pointer-non-const-struct-const-fp/test.desc | 2 +- .../no-match-const-struct-non-const-fp-null/main.c | 2 +- .../no-match-non-const-fp-const-fp-direct-assignment/main.c | 2 +- regression/goto-analyzer/no-match-non-const-fp/main.c | 2 +- regression/goto-analyzer/no-match-parameter-const-fp/main.c | 2 +- regression/goto-analyzer/no-match-parameter-fp/main.c | 2 +- .../goto-analyzer/precise-array-calculation-const-fp/main.c | 2 +- regression/goto-analyzer/precise-array-literal-const-fp/main.c | 2 +- .../precise-const-fp-array-const-variable-const-fp/main.c | 2 +- .../precise-const-fp-array-literal-const-fp-run-time/main.c | 2 +- .../precise-const-fp-array-literal-const-fp/main.c | 2 +- .../main.c | 2 +- regression/goto-analyzer/precise-const-fp-const-fp/main.c | 2 +- .../main.c | 2 +- .../precise-const-fp-const-struct-non-const-fp/main.c | 2 +- .../precise-const-fp-dereference-const-pointer-const-fp/main.c | 2 +- regression/goto-analyzer/precise-const-fp/main.c | 2 +- .../goto-analyzer/precise-const-struct-non-const-fp/main.c | 2 +- .../precise-derefence-const-pointer-const-fp/main.c | 2 +- regression/goto-analyzer/precise-derefence/main.c | 2 +- .../precise-dereference-address-pointer-const-fp/main.c | 2 +- 44 files changed, 44 insertions(+), 44 deletions(-) diff --git a/regression/goto-analyzer/approx-array-variable-const-fp/main.c b/regression/goto-analyzer/approx-array-variable-const-fp/main.c index 3fb230c83fd..7896e3402c0 100644 --- a/regression/goto-analyzer/approx-array-variable-const-fp/main.c +++ b/regression/goto-analyzer/approx-array-variable-const-fp/main.c @@ -31,4 +31,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/main.c index 3d968a5e243..8fda2e71af4 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/main.c +++ b/regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/main.c @@ -38,4 +38,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/main.c index a777bce3a48..72a600aa80c 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/main.c +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/main.c @@ -32,4 +32,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/main.c index d426bba269e..7eea22141bd 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/main.c +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-fp/main.c @@ -32,4 +32,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/main.c b/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/main.c index c27aee68bd8..67d256f0c7b 100644 --- a/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/main.c +++ b/regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/main.c @@ -47,4 +47,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-array-literal-const-fp-null/main.c b/regression/goto-analyzer/no-match-array-literal-const-fp-null/main.c index fba4069b7a2..93ed0af0d47 100644 --- a/regression/goto-analyzer/no-match-array-literal-const-fp-null/main.c +++ b/regression/goto-analyzer/no-match-array-literal-const-fp-null/main.c @@ -28,4 +28,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/main.c b/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/main.c index 16b0221e740..ee9ba95cb57 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/main.c +++ b/regression/goto-analyzer/no-match-const-fp-array-literal-const-fp-run-time/main.c @@ -33,4 +33,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/main.c b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/main.c index a67cf750d5e..fa1cf231a50 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/main.c +++ b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp-run-time/main.c @@ -31,4 +31,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/main.c b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/main.c index d649b1dd056..88b4edcf448 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-fp-array-literal-non-const-fp/main.c @@ -35,4 +35,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/main.c b/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/main.c index 189bd8c036d..38d09cfb14e 100644 --- a/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-fp-array-non-const-fp/main.c @@ -33,4 +33,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-fp-const-cast/main.c b/regression/goto-analyzer/no-match-const-fp-const-cast/main.c index f7fa7f41b42..b9bd141e6f0 100644 --- a/regression/goto-analyzer/no-match-const-fp-const-cast/main.c +++ b/regression/goto-analyzer/no-match-const-fp-const-cast/main.c @@ -32,4 +32,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-fp-const-fp-null/main.c b/regression/goto-analyzer/no-match-const-fp-const-fp-null/main.c index 4b8ba72dd51..67c501302a6 100644 --- a/regression/goto-analyzer/no-match-const-fp-const-fp-null/main.c +++ b/regression/goto-analyzer/no-match-const-fp-const-fp-null/main.c @@ -28,4 +28,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-fp-const-lost/main.c b/regression/goto-analyzer/no-match-const-fp-const-lost/main.c index edeca0d3f79..d2724684066 100644 --- a/regression/goto-analyzer/no-match-const-fp-const-lost/main.c +++ b/regression/goto-analyzer/no-match-const-fp-const-lost/main.c @@ -32,4 +32,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/main.c b/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/main.c index 1420490b0a6..3f55ff255dd 100644 --- a/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-fp-const-pointer-non-const-struct-const-fp/main.c @@ -44,4 +44,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-fp-dereference-const-pointer-null/main.c b/regression/goto-analyzer/no-match-const-fp-dereference-const-pointer-null/main.c index b384b87bb4e..e4048adb8cb 100644 --- a/regression/goto-analyzer/no-match-const-fp-dereference-const-pointer-null/main.c +++ b/regression/goto-analyzer/no-match-const-fp-dereference-const-pointer-null/main.c @@ -33,4 +33,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/main.c b/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/main.c index f9750966b58..30e4947c2d7 100644 --- a/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-fp-dereference-non-const-pointer-const-fp/main.c @@ -37,4 +37,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/main.c b/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/main.c index f468113ac16..d7d4820d29c 100644 --- a/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-fp-dynamic-array-non-const-fp/main.c @@ -36,4 +36,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/main.c b/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/main.c index 98c7f0619b6..6c9ba5514e7 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/main.c +++ b/regression/goto-analyzer/no-match-const-fp-non-const-fp-direct-assignment/main.c @@ -29,4 +29,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/main.c b/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/main.c index 1da907916bd..bb40b1a53c1 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-fp-non-const-pointer-non-const-struct-const-fp/main.c @@ -44,4 +44,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/main.c b/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/main.c index 3952169b535..ed86d4c39c6 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-fp-non-const-struct-const-fp/main.c @@ -40,4 +40,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/main.c b/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/main.c index 9c1af7d8d83..7d8b2584388 100644 --- a/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-fp-non-const-struct-non-const-fp/main.c @@ -40,4 +40,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-fp-null/main.c b/regression/goto-analyzer/no-match-const-fp-null/main.c index 98a0349ce37..16c65f9f845 100644 --- a/regression/goto-analyzer/no-match-const-fp-null/main.c +++ b/regression/goto-analyzer/no-match-const-fp-null/main.c @@ -27,4 +27,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/main.c b/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/main.c index f626942ef8b..bf4bb45d094 100644 --- a/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/main.c +++ b/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/main.c @@ -40,4 +40,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/test.desc b/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/test.desc index 80169b619fa..2760fadd576 100644 --- a/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/test.desc +++ b/regression/goto-analyzer/no-match-const-pointer-non-const-struct-const-fp/test.desc @@ -14,4 +14,4 @@ main.c ^\s*IF pts->go == f9 THEN GOTO [0-9]$ ^SIGNAL=0$ -- -^warning: ignoring \ No newline at end of file +^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-struct-non-const-fp-null/main.c b/regression/goto-analyzer/no-match-const-struct-non-const-fp-null/main.c index 569870b6609..6e24a0d8d4c 100644 --- a/regression/goto-analyzer/no-match-const-struct-non-const-fp-null/main.c +++ b/regression/goto-analyzer/no-match-const-struct-non-const-fp-null/main.c @@ -37,4 +37,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/main.c b/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/main.c index a9a31b98a70..4487db8b047 100644 --- a/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/main.c +++ b/regression/goto-analyzer/no-match-non-const-fp-const-fp-direct-assignment/main.c @@ -30,4 +30,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-non-const-fp/main.c b/regression/goto-analyzer/no-match-non-const-fp/main.c index a5d81d9959d..80c8c863ff5 100644 --- a/regression/goto-analyzer/no-match-non-const-fp/main.c +++ b/regression/goto-analyzer/no-match-non-const-fp/main.c @@ -28,4 +28,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-parameter-const-fp/main.c b/regression/goto-analyzer/no-match-parameter-const-fp/main.c index 340373af407..23e73aabdc0 100644 --- a/regression/goto-analyzer/no-match-parameter-const-fp/main.c +++ b/regression/goto-analyzer/no-match-parameter-const-fp/main.c @@ -29,4 +29,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/no-match-parameter-fp/main.c b/regression/goto-analyzer/no-match-parameter-fp/main.c index fe392e11f0e..332df257368 100644 --- a/regression/goto-analyzer/no-match-parameter-fp/main.c +++ b/regression/goto-analyzer/no-match-parameter-fp/main.c @@ -29,4 +29,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/precise-array-calculation-const-fp/main.c b/regression/goto-analyzer/precise-array-calculation-const-fp/main.c index be8d02bff78..a61d95186aa 100644 --- a/regression/goto-analyzer/precise-array-calculation-const-fp/main.c +++ b/regression/goto-analyzer/precise-array-calculation-const-fp/main.c @@ -29,4 +29,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/precise-array-literal-const-fp/main.c b/regression/goto-analyzer/precise-array-literal-const-fp/main.c index 31cc52a7403..55dab779802 100644 --- a/regression/goto-analyzer/precise-array-literal-const-fp/main.c +++ b/regression/goto-analyzer/precise-array-literal-const-fp/main.c @@ -28,4 +28,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/main.c b/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/main.c index a43a189f96f..c2465dcb695 100644 --- a/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp-array-const-variable-const-fp/main.c @@ -30,4 +30,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/precise-const-fp-array-literal-const-fp-run-time/main.c b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp-run-time/main.c index 36e4da04ddf..59d51313fde 100644 --- a/regression/goto-analyzer/precise-const-fp-array-literal-const-fp-run-time/main.c +++ b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp-run-time/main.c @@ -29,4 +29,4 @@ int main() { func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/main.c b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/main.c index d061734174f..2e9cb8cc4df 100644 --- a/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp-array-literal-const-fp/main.c @@ -29,4 +29,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/main.c b/regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/main.c index c1bcb0dc951..c61a7a32499 100644 --- a/regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp-array-variable-const-pointer-const-struct-non-const-fp/main.c @@ -46,4 +46,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/precise-const-fp-const-fp/main.c b/regression/goto-analyzer/precise-const-fp-const-fp/main.c index d3a61d828e1..a1efb8e0934 100644 --- a/regression/goto-analyzer/precise-const-fp-const-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp-const-fp/main.c @@ -28,4 +28,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/main.c b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/main.c index 5cf1602c854..bc4ffead00e 100644 --- a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-array-literal-fp/main.c @@ -42,4 +42,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/main.c b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/main.c index 02cbb17f851..7c3bed93919 100644 --- a/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp-const-struct-non-const-fp/main.c @@ -41,4 +41,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/main.c b/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/main.c index c18a7fe3256..efeb3b35d80 100644 --- a/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp-dereference-const-pointer-const-fp/main.c @@ -33,4 +33,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/precise-const-fp/main.c b/regression/goto-analyzer/precise-const-fp/main.c index f4d21dc2588..b4002c94e5e 100644 --- a/regression/goto-analyzer/precise-const-fp/main.c +++ b/regression/goto-analyzer/precise-const-fp/main.c @@ -27,4 +27,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/precise-const-struct-non-const-fp/main.c b/regression/goto-analyzer/precise-const-struct-non-const-fp/main.c index aa534a96e93..150ea314914 100644 --- a/regression/goto-analyzer/precise-const-struct-non-const-fp/main.c +++ b/regression/goto-analyzer/precise-const-struct-non-const-fp/main.c @@ -37,4 +37,4 @@ int main() } return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/main.c b/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/main.c index 1e2fd83fd6b..78901cc6405 100644 --- a/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/main.c +++ b/regression/goto-analyzer/precise-derefence-const-pointer-const-fp/main.c @@ -32,4 +32,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/precise-derefence/main.c b/regression/goto-analyzer/precise-derefence/main.c index 318676c712e..d3bc8a2bc35 100644 --- a/regression/goto-analyzer/precise-derefence/main.c +++ b/regression/goto-analyzer/precise-derefence/main.c @@ -28,4 +28,4 @@ int main() func(); return 0; -} \ No newline at end of file +} diff --git a/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/main.c b/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/main.c index 56a7a7d7c4e..e0246369f7b 100644 --- a/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/main.c +++ b/regression/goto-analyzer/precise-dereference-address-pointer-const-fp/main.c @@ -27,4 +27,4 @@ int main() func(); return 0; -} \ No newline at end of file +} From 29e7e0de382778dc341bf4858e2cd1f76964d0cd Mon Sep 17 00:00:00 2001 From: thk123 Date: Mon, 20 Mar 2017 12:57:23 +0000 Subject: [PATCH 43/46] Split out the const check into own analysis Created a standalone class to check whether a prgram contains a cast that loses the const-ness of something that would allow modifying a constant value (i.e. undefinied behaviour). --- src/analyses/Makefile | 4 +- src/analyses/does_remove_const.cpp | 138 ++++++++++++++++++ src/analyses/does_remove_const.h | 29 ++++ .../remove_function_pointers.cpp | 113 +------------- 4 files changed, 173 insertions(+), 111 deletions(-) create mode 100644 src/analyses/does_remove_const.cpp create mode 100644 src/analyses/does_remove_const.h diff --git a/src/analyses/Makefile b/src/analyses/Makefile index 89f14e4f768..e05d5be0c42 100644 --- a/src/analyses/Makefile +++ b/src/analyses/Makefile @@ -6,7 +6,9 @@ SRC = natural_loops.cpp is_threaded.cpp dirty.cpp interval_analysis.cpp \ local_bitvector_analysis.cpp dependence_graph.cpp \ constant_propagator.cpp replace_symbol_ext.cpp \ flow_insensitive_analysis.cpp \ - custom_bitvector_analysis.cpp escape_analysis.cpp global_may_alias.cpp + custom_bitvector_analysis.cpp escape_analysis.cpp global_may_alias.cpp \ + does_remove_const.cpp \ + # Empty last line INCLUDES= -I .. diff --git a/src/analyses/does_remove_const.cpp b/src/analyses/does_remove_const.cpp new file mode 100644 index 00000000000..75d520b6937 --- /dev/null +++ b/src/analyses/does_remove_const.cpp @@ -0,0 +1,138 @@ +/*******************************************************************\ + + Module: Analyses + + Author: DiffBlue Limited. All rights reserved. + +\*******************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include "does_remove_const.h" + +/*******************************************************************\ + +Function: does_remove_constt::does_remove_constt + + Inputs: + goto_program - the goto program to check + ns - the namespace of the goto program (used for checking type equality) + + Outputs: + + Purpose: A naive analysis to look for casts that remove const-ness from + pointers. + +\*******************************************************************/ + +does_remove_constt::does_remove_constt( + const goto_programt &goto_program, + const namespacet &ns): + goto_program(goto_program), + ns(ns) +{} + +/*******************************************************************\ + +Function: does_remove_constt::operator() + + Inputs: + + Outputs: Returns true if the pgroam contains a const-removing cast + + Purpose: A naive analysis to look for casts that remove const-ness from + pointers. + +\*******************************************************************/ + +bool does_remove_constt::operator()() const +{ + for(const goto_programt::instructiont &instruction : + goto_program.instructions) + { + if(instruction.is_assign()) + { + const code_assignt assign=to_code_assign(instruction.code); + const typet &rhs_type=assign.rhs().type(); + const typet &lhs_type=assign.lhs().type(); + + // Compare the types recursively for a point where the rhs is more + // const that the lhs + if(!is_type_at_least_as_const_as(lhs_type, rhs_type)) + { + return true; + } + + // see if the rhs loses const inside the expression tree + exprt rhs=assign.rhs(); + while(!rhs.operands().empty()) + { + typet &pre_op_type=rhs.type(); + typet &post_op_type=rhs.op0().type(); + + // Types equality does not check, for example, const-ness + // If this is true, then this expression only modified the + // type by some qualifier (or not at all) + if(base_type_eq(pre_op_type, post_op_type, ns)) + { + if(!is_type_at_least_as_const_as(pre_op_type, post_op_type)) + { + return true; + } + } + rhs=rhs.op0(); + } + } + } + + return false; +} + +/*******************************************************************\ + +Function: does_remove_constt::is_type_at_least_as_const_as + + Inputs: + type_more_const - the type we are expecting to be at least as const qualified + type_compare - the type we are comparing against which may be less const + qualified + + Outputs: Returns true if type_more_const is at least as const as type_compare + + Purpose: A recursive check to check the type_more_const is at least as const + as type compare. + + type_more_const | type_compare || result + ---------------------------------------- + const int * | const int * -> true + int * | const int * -> false + const int * | int * -> true + int * | int * const -> false + +\*******************************************************************/ + +bool does_remove_constt::is_type_at_least_as_const_as( + typet type_more_const, typet type_compare) const +{ + while(!type_compare.id().empty() && !type_more_const.id().empty()) + { + const c_qualifierst rhs_qualifiers(type_compare); + const c_qualifierst lhs_qualifiers(type_more_const); + if(rhs_qualifiers.is_constant && !lhs_qualifiers.is_constant) + { + return false; + } + + type_compare=type_compare.subtype(); + type_more_const=type_more_const.subtype(); + } + + // Both the types should have the same number of subtypes + assert(type_compare.id().empty() && type_more_const.id().empty()); + return true; +} diff --git a/src/analyses/does_remove_const.h b/src/analyses/does_remove_const.h new file mode 100644 index 00000000000..98a09a0eca6 --- /dev/null +++ b/src/analyses/does_remove_const.h @@ -0,0 +1,29 @@ +/*******************************************************************\ + + Module: Analyses + + Author: DiffBlue Limited. All rights reserved. + +\*******************************************************************/ +#ifndef CPROVER_ANALYSES_DOES_REMOVE_CONST_H +#define CPROVER_ANALYSES_DOES_REMOVE_CONST_H + +#include + +class goto_programt; + +class does_remove_constt +{ +public: + does_remove_constt(const goto_programt &goto_program, const namespacet &ns); + bool operator()() const; + +private: + bool is_type_at_least_as_const_as( + typet type_more_const, typet type_compare) const; + + const goto_programt &goto_program; + const namespacet &ns; +}; + +#endif // CPROVER_ANALYSES_DOES_REMOVE_CONST_H diff --git a/src/goto-programs/remove_function_pointers.cpp b/src/goto-programs/remove_function_pointers.cpp index dd20bedeb6d..021c63148be 100644 --- a/src/goto-programs/remove_function_pointers.cpp +++ b/src/goto-programs/remove_function_pointers.cpp @@ -17,6 +17,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include #include +#include #include @@ -64,11 +65,6 @@ class remove_function_pointerst:public messaget goto_programt &goto_program, goto_programt::targett target); - bool does_program_contain_const_removal_cast( - const goto_programt &goto_program); - - bool is_type_at_least_as_const_as(typet type_more_const, typet type_compare); - std::set address_taken; typedef std::map type_mapt; @@ -364,7 +360,8 @@ void remove_function_pointerst::remove_function_pointer( const exprt &pointer=function.op0(); remove_const_function_pointerst::functionst functions; - if(does_program_contain_const_removal_cast(goto_program)) + does_remove_constt const_removal_check(goto_program, ns); + if(const_removal_check()) { warning() << "Cast from const to non-const pointer found, only worst case" << " function pointer removal will be done." << eom; @@ -513,110 +510,6 @@ void remove_function_pointerst::remove_function_pointer( /*******************************************************************\ -Function: remove_function_pointerst::does_program_contain_const_removal_cast - - Inputs: - goto_program - the goto program to check - - Outputs: Returns true if any instruction in the code casts away either - explicitly or implicitly the const qualifier of a type. - - Purpose: A naive check to look for casts that remove const-ness from - pointers. If this is present, then our remove_const_function_pointerst - is not sound so we don't allow it. - -\*******************************************************************/ - -bool remove_function_pointerst::does_program_contain_const_removal_cast( - const goto_programt &goto_program) -{ - for(const goto_programt::instructiont &instruction : - goto_program.instructions) - { - if(instruction.is_assign()) - { - const code_assignt assign=to_code_assign(instruction.code); - typet rhs_type=assign.rhs().type(); - typet lhs_type=assign.lhs().type(); - - // Compare the types recursively for a point where the rhs is more - // const that the lhs - if(!is_type_at_least_as_const_as(lhs_type, rhs_type)) - { - return true; - } - - // see if the rhs loses const inside the expression tree - exprt rhs=assign.rhs(); - while(!rhs.operands().empty()) - { - typet &pre_op_type=rhs.type(); - typet &post_op_type=rhs.op0().type(); - - // Types equality does not check, for example, const-ness - // If this is true, then this expression only modified the - // type by some qualifier (or not at all) - if(base_type_eq(pre_op_type, post_op_type, ns)) - { - if(!is_type_at_least_as_const_as(pre_op_type, post_op_type)) - { - return true; - } - } - rhs=rhs.op0(); - } - } - } - - return false; -} - -/*******************************************************************\ - -Function: remove_function_pointerst::is_type_at_least_as_const_as - - Inputs: - type_more_const - the type we are expecting to be at least as const qualified - type_compare - the type we are comparing against which may be less const - qualified - - Outputs: Returns true if type_more_const is at least as const as type_compare - - Purpose: A recursive check to check the type_more_const is at least as const - as type compare. - - type_more_const | type_compare || result - ---------------------------------------- - const int * | const int * -> true - int * | const int * -> false - const int * | int * -> true - int * | int * const -> false - -\*******************************************************************/ - -bool remove_function_pointerst::is_type_at_least_as_const_as( - typet type_more_const, typet type_compare) -{ - while(!type_compare.id().empty() && !type_more_const.id().empty()) - { - const c_qualifierst rhs_qualifiers(type_compare); - const c_qualifierst lhs_qualifiers(type_more_const); - if(rhs_qualifiers.is_constant && !lhs_qualifiers.is_constant) - { - return false; - } - - type_compare=type_compare.subtype(); - type_more_const=type_more_const.subtype(); - } - - // Both the types should have the same number of subtypes - assert(type_compare.id()=="" && type_more_const.id()==""); - return true; -} - -/*******************************************************************\ - Function: remove_function_pointerst::remove_function_pointers Inputs: From 649e0bf252e9ca1ddf8c587cc1e7c856c0b3c586 Mon Sep 17 00:00:00 2001 From: thk123 Date: Tue, 21 Mar 2017 14:25:31 +0000 Subject: [PATCH 44/46] Descend all children of the same base type When we are checking for loss of const qualifiers, we need to check all children that are the same basic type to see if their qualification is lost in their parent. --- .../main.c | 41 ++++++++++++ .../test.desc | 16 +++++ .../main.c | 35 ++++++++++ .../test.desc | 16 +++++ .../main.c | 40 ++++++++++++ .../test.desc | 16 +++++ .../no-match-const-fp-const-array-lost/main.c | 40 ++++++++++++ .../test.desc | 16 +++++ .../main.c | 36 +++++++++++ .../test.desc | 16 +++++ src/analyses/does_remove_const.cpp | 64 +++++++++++++------ src/analyses/does_remove_const.h | 2 + 12 files changed, 320 insertions(+), 18 deletions(-) create mode 100644 regression/goto-analyzer/no-match-const-array-const-pointer-const-fp-const-lost/main.c create mode 100644 regression/goto-analyzer/no-match-const-array-const-pointer-const-fp-const-lost/test.desc create mode 100644 regression/goto-analyzer/no-match-const-fp-binary-op-const-lost/main.c create mode 100644 regression/goto-analyzer/no-match-const-fp-binary-op-const-lost/test.desc create mode 100644 regression/goto-analyzer/no-match-const-fp-const-array-index-lost/main.c create mode 100644 regression/goto-analyzer/no-match-const-fp-const-array-index-lost/test.desc create mode 100644 regression/goto-analyzer/no-match-const-fp-const-array-lost/main.c create mode 100644 regression/goto-analyzer/no-match-const-fp-const-array-lost/test.desc create mode 100644 regression/goto-analyzer/no-match-const-fp-ternerary-op-const-lost/main.c create mode 100644 regression/goto-analyzer/no-match-const-fp-ternerary-op-const-lost/test.desc diff --git a/regression/goto-analyzer/no-match-const-array-const-pointer-const-fp-const-lost/main.c b/regression/goto-analyzer/no-match-const-array-const-pointer-const-fp-const-lost/main.c new file mode 100644 index 00000000000..a17acab6166 --- /dev/null +++ b/regression/goto-analyzer/no-match-const-array-const-pointer-const-fp-const-lost/main.c @@ -0,0 +1,41 @@ +#include + +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 func() +{ + const void_fp start_fp = f2; + const void_fp * const fp_tbl[] = { &start_fp, &start_fp, &start_fp }; + + // warning: loses const + void_fp * arr_ptr=fp_tbl[0]; + (*arr_ptr) = f5; + arr_ptr++; + (*arr_ptr) = f5; + + const void_fp * const fp = fp_tbl[1]; + + + (*fp)(); +} + +int main() +{ + func(); + + return 0; +} diff --git a/regression/goto-analyzer/no-match-const-array-const-pointer-const-fp-const-lost/test.desc b/regression/goto-analyzer/no-match-const-array-const-pointer-const-fp-const-lost/test.desc new file mode 100644 index 00000000000..9ac0520abde --- /dev/null +++ b/regression/goto-analyzer/no-match-const-array-const-pointer-const-fp-const-lost/test.desc @@ -0,0 +1,16 @@ +CORE +main.c +--show-goto-functions --verbosity 10 --pointer-check + +^Removing function pointers and virtual functions$ +^\s*IF \*fp == f1 THEN GOTO [0-9]$ +^\s*IF \*fp == f2 THEN GOTO [0-9]$ +^\s*IF \*fp == f3 THEN GOTO [0-9]$ +^\s*IF \*fp == f4 THEN GOTO [0-9]$ +^\s*IF \*fp == f5 THEN GOTO [0-9]$ +^\s*IF \*fp == f6 THEN GOTO [0-9]$ +^\s*IF \*fp == f7 THEN GOTO [0-9]$ +^\s*IF \*fp == f8 THEN GOTO [0-9]$ +^\s*IF \*fp == f9 THEN GOTO [0-9]$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-binary-op-const-lost/main.c b/regression/goto-analyzer/no-match-const-fp-binary-op-const-lost/main.c new file mode 100644 index 00000000000..7f5c0ea3755 --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-binary-op-const-lost/main.c @@ -0,0 +1,35 @@ +#include + +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 func() +{ + const void_fp fp = f2; + + // Warning: this loses const-ness of f2 + void_fp * p2fp = 0 + ((void_fp*)&fp); + *p2fp = &f4; + + fp(); +} + +int main() +{ + func(); + + return 0; +} diff --git a/regression/goto-analyzer/no-match-const-fp-binary-op-const-lost/test.desc b/regression/goto-analyzer/no-match-const-fp-binary-op-const-lost/test.desc new file mode 100644 index 00000000000..e8357d911c6 --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-binary-op-const-lost/test.desc @@ -0,0 +1,16 @@ +CORE +main.c +--show-goto-functions --verbosity 10 --pointer-check + +^Removing function pointers and virtual functions$ +^\s*IF fp == f1 THEN GOTO [0-9]$ +^\s*IF fp == f2 THEN GOTO [0-9]$ +^\s*IF fp == f3 THEN GOTO [0-9]$ +^\s*IF fp == f4 THEN GOTO [0-9]$ +^\s*IF fp == f5 THEN GOTO [0-9]$ +^\s*IF fp == f6 THEN GOTO [0-9]$ +^\s*IF fp == f7 THEN GOTO [0-9]$ +^\s*IF fp == f8 THEN GOTO [0-9]$ +^\s*IF fp == f9 THEN GOTO [0-9]$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-const-array-index-lost/main.c b/regression/goto-analyzer/no-match-const-fp-const-array-index-lost/main.c new file mode 100644 index 00000000000..b3dafeff777 --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-const-array-index-lost/main.c @@ -0,0 +1,40 @@ +#include + +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 func() +{ + const void_fp fp_tbl[] = {f2, f3 ,f4}; + + // warning: loses const + void_fp * arr_ptr=&fp_tbl[0]; + (*arr_ptr) = f5; + arr_ptr++; + (*arr_ptr) = f5; + + const void_fp * const fp = &fp_tbl[1]; + + + (*fp)(); +} + +int main() +{ + func(); + + return 0; +} diff --git a/regression/goto-analyzer/no-match-const-fp-const-array-index-lost/test.desc b/regression/goto-analyzer/no-match-const-fp-const-array-index-lost/test.desc new file mode 100644 index 00000000000..9ac0520abde --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-const-array-index-lost/test.desc @@ -0,0 +1,16 @@ +CORE +main.c +--show-goto-functions --verbosity 10 --pointer-check + +^Removing function pointers and virtual functions$ +^\s*IF \*fp == f1 THEN GOTO [0-9]$ +^\s*IF \*fp == f2 THEN GOTO [0-9]$ +^\s*IF \*fp == f3 THEN GOTO [0-9]$ +^\s*IF \*fp == f4 THEN GOTO [0-9]$ +^\s*IF \*fp == f5 THEN GOTO [0-9]$ +^\s*IF \*fp == f6 THEN GOTO [0-9]$ +^\s*IF \*fp == f7 THEN GOTO [0-9]$ +^\s*IF \*fp == f8 THEN GOTO [0-9]$ +^\s*IF \*fp == f9 THEN GOTO [0-9]$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-const-array-lost/main.c b/regression/goto-analyzer/no-match-const-fp-const-array-lost/main.c new file mode 100644 index 00000000000..d27da78d0b7 --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-const-array-lost/main.c @@ -0,0 +1,40 @@ +#include + +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 func() +{ + const void_fp fp_tbl[] = {f2, f3 ,f4}; + + // warning: loses const + void_fp * arr_ptr=fp_tbl; + (*arr_ptr) = f5; + arr_ptr++; + (*arr_ptr) = f5; + + const void_fp * const fp = &fp_tbl[1]; + + + (*fp)(); +} + +int main() +{ + func(); + + return 0; +} diff --git a/regression/goto-analyzer/no-match-const-fp-const-array-lost/test.desc b/regression/goto-analyzer/no-match-const-fp-const-array-lost/test.desc new file mode 100644 index 00000000000..9ac0520abde --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-const-array-lost/test.desc @@ -0,0 +1,16 @@ +CORE +main.c +--show-goto-functions --verbosity 10 --pointer-check + +^Removing function pointers and virtual functions$ +^\s*IF \*fp == f1 THEN GOTO [0-9]$ +^\s*IF \*fp == f2 THEN GOTO [0-9]$ +^\s*IF \*fp == f3 THEN GOTO [0-9]$ +^\s*IF \*fp == f4 THEN GOTO [0-9]$ +^\s*IF \*fp == f5 THEN GOTO [0-9]$ +^\s*IF \*fp == f6 THEN GOTO [0-9]$ +^\s*IF \*fp == f7 THEN GOTO [0-9]$ +^\s*IF \*fp == f8 THEN GOTO [0-9]$ +^\s*IF \*fp == f9 THEN GOTO [0-9]$ +-- +^warning: ignoring diff --git a/regression/goto-analyzer/no-match-const-fp-ternerary-op-const-lost/main.c b/regression/goto-analyzer/no-match-const-fp-ternerary-op-const-lost/main.c new file mode 100644 index 00000000000..ba5bcad694a --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-ternerary-op-const-lost/main.c @@ -0,0 +1,36 @@ +#include + +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 func(int x) +{ + const void_fp fp = f2; + void_fp non_const_fp = f7; + + // Warning: this loses const-ness of f2 + void_fp * p2fp = x > 0 ? ((void_fp*)&fp) : &non_const_fp; + *p2fp = &f4; + + fp(); +} + +int main() +{ + func(1); + + return 0; +} diff --git a/regression/goto-analyzer/no-match-const-fp-ternerary-op-const-lost/test.desc b/regression/goto-analyzer/no-match-const-fp-ternerary-op-const-lost/test.desc new file mode 100644 index 00000000000..e8357d911c6 --- /dev/null +++ b/regression/goto-analyzer/no-match-const-fp-ternerary-op-const-lost/test.desc @@ -0,0 +1,16 @@ +CORE +main.c +--show-goto-functions --verbosity 10 --pointer-check + +^Removing function pointers and virtual functions$ +^\s*IF fp == f1 THEN GOTO [0-9]$ +^\s*IF fp == f2 THEN GOTO [0-9]$ +^\s*IF fp == f3 THEN GOTO [0-9]$ +^\s*IF fp == f4 THEN GOTO [0-9]$ +^\s*IF fp == f5 THEN GOTO [0-9]$ +^\s*IF fp == f6 THEN GOTO [0-9]$ +^\s*IF fp == f7 THEN GOTO [0-9]$ +^\s*IF fp == f8 THEN GOTO [0-9]$ +^\s*IF fp == f9 THEN GOTO [0-9]$ +-- +^warning: ignoring diff --git a/src/analyses/does_remove_const.cpp b/src/analyses/does_remove_const.cpp index 75d520b6937..43c575838d3 100644 --- a/src/analyses/does_remove_const.cpp +++ b/src/analyses/does_remove_const.cpp @@ -43,7 +43,7 @@ Function: does_remove_constt::operator() Inputs: - Outputs: Returns true if the pgroam contains a const-removing cast + Outputs: Returns true if the program contains a const-removing cast Purpose: A naive analysis to look for casts that remove const-ness from pointers. @@ -68,24 +68,10 @@ bool does_remove_constt::operator()() const return true; } - // see if the rhs loses const inside the expression tree - exprt rhs=assign.rhs(); - while(!rhs.operands().empty()) + bool sub_expr_lose_const=does_expr_lose_const(assign.rhs()); + if(sub_expr_lose_const) { - typet &pre_op_type=rhs.type(); - typet &post_op_type=rhs.op0().type(); - - // Types equality does not check, for example, const-ness - // If this is true, then this expression only modified the - // type by some qualifier (or not at all) - if(base_type_eq(pre_op_type, post_op_type, ns)) - { - if(!is_type_at_least_as_const_as(pre_op_type, post_op_type)) - { - return true; - } - } - rhs=rhs.op0(); + return true; } } } @@ -95,6 +81,48 @@ bool does_remove_constt::operator()() const /*******************************************************************\ +Function: does_remove_constt::does_expr_lose_const() + + Inputs: + expr - The expression to check + + Outputs: Returns true if somewhere in the passed expression tree the const-ness + is lost. + + Purpose: Search the expression tree to look for any children that have the + same base type, but a less strict const qualification. + If one is found, we return true. + +\*******************************************************************/ + +bool does_remove_constt::does_expr_lose_const(const exprt &expr) const +{ + const typet &root_type=expr.type(); + + // Look in each child that has the same base type as the root + for(const exprt &op : expr.operands()) + { + const typet &op_type=op.type(); + if(base_type_eq(op_type, root_type, ns)) + { + // Is this child more const-qualified than the root + if(!is_type_at_least_as_const_as(root_type, op_type)) + { + return true; + } + } + + // Recursively check the children of this child + if(does_expr_lose_const(op)) + { + return true; + } + } + return false; +} + +/*******************************************************************\ + Function: does_remove_constt::is_type_at_least_as_const_as Inputs: diff --git a/src/analyses/does_remove_const.h b/src/analyses/does_remove_const.h index 98a09a0eca6..30add2aeee3 100644 --- a/src/analyses/does_remove_const.h +++ b/src/analyses/does_remove_const.h @@ -19,6 +19,8 @@ class does_remove_constt bool operator()() const; private: + bool does_expr_lose_const(const exprt &expr) const; + bool is_type_at_least_as_const_as( typet type_more_const, typet type_compare) const; From 4607e73e24dfd60423263c926f6c2ee6483fcbc8 Mon Sep 17 00:00:00 2001 From: thk123 Date: Wed, 22 Mar 2017 10:13:59 +0000 Subject: [PATCH 45/46] PR Feedback implementation Simplifying assert Simplify and reducing indentation by changing if branches with trivial else clauses into checking them first and bailing if condition not met. Corrected use of reference --- src/analyses/does_remove_const.cpp | 31 ++++++++++--------- .../remove_const_function_pointers.cpp | 26 ++++++---------- .../remove_function_pointers.cpp | 11 +++---- 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/analyses/does_remove_const.cpp b/src/analyses/does_remove_const.cpp index 43c575838d3..fc33d3dc973 100644 --- a/src/analyses/does_remove_const.cpp +++ b/src/analyses/does_remove_const.cpp @@ -55,24 +55,25 @@ bool does_remove_constt::operator()() const for(const goto_programt::instructiont &instruction : goto_program.instructions) { - if(instruction.is_assign()) + if(!instruction.is_assign()) { - const code_assignt assign=to_code_assign(instruction.code); - const typet &rhs_type=assign.rhs().type(); - const typet &lhs_type=assign.lhs().type(); + continue; + } - // Compare the types recursively for a point where the rhs is more - // const that the lhs - if(!is_type_at_least_as_const_as(lhs_type, rhs_type)) - { - return true; - } + const code_assignt &assign=to_code_assign(instruction.code); + const typet &rhs_type=assign.rhs().type(); + const typet &lhs_type=assign.lhs().type(); - bool sub_expr_lose_const=does_expr_lose_const(assign.rhs()); - if(sub_expr_lose_const) - { - return true; - } + // Compare the types recursively for a point where the rhs is more + // const that the lhs + if(!is_type_at_least_as_const_as(lhs_type, rhs_type)) + { + return true; + } + + if(does_expr_lose_const(assign.rhs())) + { + return true; } } diff --git a/src/goto-programs/remove_const_function_pointers.cpp b/src/goto-programs/remove_const_function_pointers.cpp index d43ac85d62a..c0a7d8d5380 100644 --- a/src/goto-programs/remove_const_function_pointers.cpp +++ b/src/goto-programs/remove_const_function_pointers.cpp @@ -501,7 +501,7 @@ Function: remove_const_function_pointerst::try_resolve_expression bool remove_const_function_pointerst::try_resolve_expression( const exprt &expr, expressionst &out_resolved_expression, bool &out_is_const) { - const exprt &simplified_expr=simplify_expr(expr, ns); + exprt simplified_expr=simplify_expr(expr, ns); bool resolved; expressionst resolved_expressions; bool is_resolved_expression_const; @@ -693,25 +693,19 @@ bool remove_const_function_pointerst::try_resolve_index_of( try_resolve_expression( array_entry, array_contents, is_entry_const); - if(resolved_value) - { - for(const exprt &resolved_array_entry : array_contents) - { - if(resolved_array_entry .is_zero()) - { - continue; - } - else - { - out_expressions.push_back(resolved_array_entry); - } - } - } - else + if(!resolved_value) { LOG("Failed to resolve array value", array_entry); return false; } + + for(const exprt &resolved_array_entry : array_contents) + { + if(!resolved_array_entry.is_zero()) + { + out_expressions.push_back(resolved_array_entry); + } + } } } } diff --git a/src/goto-programs/remove_function_pointers.cpp b/src/goto-programs/remove_function_pointers.cpp index 021c63148be..c67c834b2ce 100644 --- a/src/goto-programs/remove_function_pointers.cpp +++ b/src/goto-programs/remove_function_pointers.cpp @@ -374,13 +374,10 @@ void remove_function_pointerst::remove_function_pointer( found_functions=fpr(functions); - // Consistency checks - // Reported optimized function pointer call, but didn't find any functions - assert(!found_functions || !functions.empty()); - - // Reported didn't optimize function pointer call, but did find some - // functions to replace with - assert(found_functions || functions.empty()); + // Either found_functions is true therefore the functions should not + // be empty + // Or found_functions is false therefore the functions should be empty + assert(found_functions != functions.empty()); if(functions.size()==1) { From d7c15ae788f0429bbdc7f05f3750574316cd89b2 Mon Sep 17 00:00:00 2001 From: thk123 Date: Wed, 22 Mar 2017 10:27:10 +0000 Subject: [PATCH 46/46] Use pointers in is_type_at_least_as_const_as To avoid unnecessary temporary objects, use a pointer when checking for const preservation. Note we now need to compare the ID against NIL rather than the empty string since the non-const version of subtype returns a new irept with no id, but the const version returns the nil data structure. --- src/analyses/does_remove_const.cpp | 18 +++++++++--------- src/analyses/does_remove_const.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/analyses/does_remove_const.cpp b/src/analyses/does_remove_const.cpp index fc33d3dc973..fcccd8219c9 100644 --- a/src/analyses/does_remove_const.cpp +++ b/src/analyses/does_remove_const.cpp @@ -66,7 +66,7 @@ bool does_remove_constt::operator()() const // Compare the types recursively for a point where the rhs is more // const that the lhs - if(!is_type_at_least_as_const_as(lhs_type, rhs_type)) + if(!is_type_at_least_as_const_as(&lhs_type, &rhs_type)) { return true; } @@ -107,7 +107,7 @@ bool does_remove_constt::does_expr_lose_const(const exprt &expr) const if(base_type_eq(op_type, root_type, ns)) { // Is this child more const-qualified than the root - if(!is_type_at_least_as_const_as(root_type, op_type)) + if(!is_type_at_least_as_const_as(&root_type, &op_type)) { return true; } @@ -146,22 +146,22 @@ Function: does_remove_constt::is_type_at_least_as_const_as \*******************************************************************/ bool does_remove_constt::is_type_at_least_as_const_as( - typet type_more_const, typet type_compare) const + const typet *type_more_const, const typet *type_compare) const { - while(!type_compare.id().empty() && !type_more_const.id().empty()) + while(type_compare->id()!=ID_nil && type_more_const->id()!=ID_nil) { - const c_qualifierst rhs_qualifiers(type_compare); - const c_qualifierst lhs_qualifiers(type_more_const); + const c_qualifierst rhs_qualifiers(*type_compare); + const c_qualifierst lhs_qualifiers(*type_more_const); if(rhs_qualifiers.is_constant && !lhs_qualifiers.is_constant) { return false; } - type_compare=type_compare.subtype(); - type_more_const=type_more_const.subtype(); + type_compare=&type_compare->subtype(); + type_more_const=&type_more_const->subtype(); } // Both the types should have the same number of subtypes - assert(type_compare.id().empty() && type_more_const.id().empty()); + assert(type_compare->id()==ID_nil && type_more_const->id()==ID_nil); return true; } diff --git a/src/analyses/does_remove_const.h b/src/analyses/does_remove_const.h index 30add2aeee3..594682c7d50 100644 --- a/src/analyses/does_remove_const.h +++ b/src/analyses/does_remove_const.h @@ -22,7 +22,7 @@ class does_remove_constt bool does_expr_lose_const(const exprt &expr) const; bool is_type_at_least_as_const_as( - typet type_more_const, typet type_compare) const; + const typet *type_more_const, const typet *type_compare) const; const goto_programt &goto_program; const namespacet &ns;