Skip to content

Commit 649e0bf

Browse files
author
thk123
committed
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.
1 parent 29e7e0d commit 649e0bf

File tree

12 files changed

+320
-18
lines changed

12 files changed

+320
-18
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <stdio.h>
2+
3+
void f1 (void) { printf("%i\n", 1); }
4+
void f2 (void) { printf("%i\n", 2); }
5+
void f3 (void) { printf("%i\n", 3); }
6+
void f4 (void) { printf("%i\n", 4); }
7+
void f5 (void) { printf("%i\n", 5); }
8+
void f6 (void) { printf("%i\n", 6); }
9+
void f7 (void) { printf("%i\n", 7); }
10+
void f8 (void) { printf("%i\n", 8); }
11+
void f9 (void) { printf("%i\n", 9); }
12+
13+
typedef void(*void_fp)(void);
14+
15+
// There is a basic check that excludes all functions that aren't used anywhere
16+
// This ensures that check can't work in this example
17+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
18+
19+
void func()
20+
{
21+
const void_fp start_fp = f2;
22+
const void_fp * const fp_tbl[] = { &start_fp, &start_fp, &start_fp };
23+
24+
// warning: loses const
25+
void_fp * arr_ptr=fp_tbl[0];
26+
(*arr_ptr) = f5;
27+
arr_ptr++;
28+
(*arr_ptr) = f5;
29+
30+
const void_fp * const fp = fp_tbl[1];
31+
32+
33+
(*fp)();
34+
}
35+
36+
int main()
37+
{
38+
func();
39+
40+
return 0;
41+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
main.c
3+
--show-goto-functions --verbosity 10 --pointer-check
4+
5+
^Removing function pointers and virtual functions$
6+
^\s*IF \*fp == f1 THEN GOTO [0-9]$
7+
^\s*IF \*fp == f2 THEN GOTO [0-9]$
8+
^\s*IF \*fp == f3 THEN GOTO [0-9]$
9+
^\s*IF \*fp == f4 THEN GOTO [0-9]$
10+
^\s*IF \*fp == f5 THEN GOTO [0-9]$
11+
^\s*IF \*fp == f6 THEN GOTO [0-9]$
12+
^\s*IF \*fp == f7 THEN GOTO [0-9]$
13+
^\s*IF \*fp == f8 THEN GOTO [0-9]$
14+
^\s*IF \*fp == f9 THEN GOTO [0-9]$
15+
--
16+
^warning: ignoring
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <stdio.h>
2+
3+
void f1 (void) { printf("%i\n", 1); }
4+
void f2 (void) { printf("%i\n", 2); }
5+
void f3 (void) { printf("%i\n", 3); }
6+
void f4 (void) { printf("%i\n", 4); }
7+
void f5 (void) { printf("%i\n", 5); }
8+
void f6 (void) { printf("%i\n", 6); }
9+
void f7 (void) { printf("%i\n", 7); }
10+
void f8 (void) { printf("%i\n", 8); }
11+
void f9 (void) { printf("%i\n", 9); }
12+
13+
typedef void(*void_fp)(void);
14+
15+
// There is a basic check that excludes all functions that aren't used anywhere
16+
// This ensures that check can't work in this example
17+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
18+
19+
void func()
20+
{
21+
const void_fp fp = f2;
22+
23+
// Warning: this loses const-ness of f2
24+
void_fp * p2fp = 0 + ((void_fp*)&fp);
25+
*p2fp = &f4;
26+
27+
fp();
28+
}
29+
30+
int main()
31+
{
32+
func();
33+
34+
return 0;
35+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
main.c
3+
--show-goto-functions --verbosity 10 --pointer-check
4+
5+
^Removing function pointers and virtual functions$
6+
^\s*IF fp == f1 THEN GOTO [0-9]$
7+
^\s*IF fp == f2 THEN GOTO [0-9]$
8+
^\s*IF fp == f3 THEN GOTO [0-9]$
9+
^\s*IF fp == f4 THEN GOTO [0-9]$
10+
^\s*IF fp == f5 THEN GOTO [0-9]$
11+
^\s*IF fp == f6 THEN GOTO [0-9]$
12+
^\s*IF fp == f7 THEN GOTO [0-9]$
13+
^\s*IF fp == f8 THEN GOTO [0-9]$
14+
^\s*IF fp == f9 THEN GOTO [0-9]$
15+
--
16+
^warning: ignoring
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <stdio.h>
2+
3+
void f1 (void) { printf("%i\n", 1); }
4+
void f2 (void) { printf("%i\n", 2); }
5+
void f3 (void) { printf("%i\n", 3); }
6+
void f4 (void) { printf("%i\n", 4); }
7+
void f5 (void) { printf("%i\n", 5); }
8+
void f6 (void) { printf("%i\n", 6); }
9+
void f7 (void) { printf("%i\n", 7); }
10+
void f8 (void) { printf("%i\n", 8); }
11+
void f9 (void) { printf("%i\n", 9); }
12+
13+
typedef void(*void_fp)(void);
14+
15+
// There is a basic check that excludes all functions that aren't used anywhere
16+
// This ensures that check can't work in this example
17+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
18+
19+
void func()
20+
{
21+
const void_fp fp_tbl[] = {f2, f3 ,f4};
22+
23+
// warning: loses const
24+
void_fp * arr_ptr=&fp_tbl[0];
25+
(*arr_ptr) = f5;
26+
arr_ptr++;
27+
(*arr_ptr) = f5;
28+
29+
const void_fp * const fp = &fp_tbl[1];
30+
31+
32+
(*fp)();
33+
}
34+
35+
int main()
36+
{
37+
func();
38+
39+
return 0;
40+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
main.c
3+
--show-goto-functions --verbosity 10 --pointer-check
4+
5+
^Removing function pointers and virtual functions$
6+
^\s*IF \*fp == f1 THEN GOTO [0-9]$
7+
^\s*IF \*fp == f2 THEN GOTO [0-9]$
8+
^\s*IF \*fp == f3 THEN GOTO [0-9]$
9+
^\s*IF \*fp == f4 THEN GOTO [0-9]$
10+
^\s*IF \*fp == f5 THEN GOTO [0-9]$
11+
^\s*IF \*fp == f6 THEN GOTO [0-9]$
12+
^\s*IF \*fp == f7 THEN GOTO [0-9]$
13+
^\s*IF \*fp == f8 THEN GOTO [0-9]$
14+
^\s*IF \*fp == f9 THEN GOTO [0-9]$
15+
--
16+
^warning: ignoring
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <stdio.h>
2+
3+
void f1 (void) { printf("%i\n", 1); }
4+
void f2 (void) { printf("%i\n", 2); }
5+
void f3 (void) { printf("%i\n", 3); }
6+
void f4 (void) { printf("%i\n", 4); }
7+
void f5 (void) { printf("%i\n", 5); }
8+
void f6 (void) { printf("%i\n", 6); }
9+
void f7 (void) { printf("%i\n", 7); }
10+
void f8 (void) { printf("%i\n", 8); }
11+
void f9 (void) { printf("%i\n", 9); }
12+
13+
typedef void(*void_fp)(void);
14+
15+
// There is a basic check that excludes all functions that aren't used anywhere
16+
// This ensures that check can't work in this example
17+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
18+
19+
void func()
20+
{
21+
const void_fp fp_tbl[] = {f2, f3 ,f4};
22+
23+
// warning: loses const
24+
void_fp * arr_ptr=fp_tbl;
25+
(*arr_ptr) = f5;
26+
arr_ptr++;
27+
(*arr_ptr) = f5;
28+
29+
const void_fp * const fp = &fp_tbl[1];
30+
31+
32+
(*fp)();
33+
}
34+
35+
int main()
36+
{
37+
func();
38+
39+
return 0;
40+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
main.c
3+
--show-goto-functions --verbosity 10 --pointer-check
4+
5+
^Removing function pointers and virtual functions$
6+
^\s*IF \*fp == f1 THEN GOTO [0-9]$
7+
^\s*IF \*fp == f2 THEN GOTO [0-9]$
8+
^\s*IF \*fp == f3 THEN GOTO [0-9]$
9+
^\s*IF \*fp == f4 THEN GOTO [0-9]$
10+
^\s*IF \*fp == f5 THEN GOTO [0-9]$
11+
^\s*IF \*fp == f6 THEN GOTO [0-9]$
12+
^\s*IF \*fp == f7 THEN GOTO [0-9]$
13+
^\s*IF \*fp == f8 THEN GOTO [0-9]$
14+
^\s*IF \*fp == f9 THEN GOTO [0-9]$
15+
--
16+
^warning: ignoring
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <stdio.h>
2+
3+
void f1 (void) { printf("%i\n", 1); }
4+
void f2 (void) { printf("%i\n", 2); }
5+
void f3 (void) { printf("%i\n", 3); }
6+
void f4 (void) { printf("%i\n", 4); }
7+
void f5 (void) { printf("%i\n", 5); }
8+
void f6 (void) { printf("%i\n", 6); }
9+
void f7 (void) { printf("%i\n", 7); }
10+
void f8 (void) { printf("%i\n", 8); }
11+
void f9 (void) { printf("%i\n", 9); }
12+
13+
typedef void(*void_fp)(void);
14+
15+
// There is a basic check that excludes all functions that aren't used anywhere
16+
// This ensures that check can't work in this example
17+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
18+
19+
void func(int x)
20+
{
21+
const void_fp fp = f2;
22+
void_fp non_const_fp = f7;
23+
24+
// Warning: this loses const-ness of f2
25+
void_fp * p2fp = x > 0 ? ((void_fp*)&fp) : &non_const_fp;
26+
*p2fp = &f4;
27+
28+
fp();
29+
}
30+
31+
int main()
32+
{
33+
func(1);
34+
35+
return 0;
36+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
main.c
3+
--show-goto-functions --verbosity 10 --pointer-check
4+
5+
^Removing function pointers and virtual functions$
6+
^\s*IF fp == f1 THEN GOTO [0-9]$
7+
^\s*IF fp == f2 THEN GOTO [0-9]$
8+
^\s*IF fp == f3 THEN GOTO [0-9]$
9+
^\s*IF fp == f4 THEN GOTO [0-9]$
10+
^\s*IF fp == f5 THEN GOTO [0-9]$
11+
^\s*IF fp == f6 THEN GOTO [0-9]$
12+
^\s*IF fp == f7 THEN GOTO [0-9]$
13+
^\s*IF fp == f8 THEN GOTO [0-9]$
14+
^\s*IF fp == f9 THEN GOTO [0-9]$
15+
--
16+
^warning: ignoring

0 commit comments

Comments
 (0)