Skip to content

Commit 14fc023

Browse files
author
thk123
committed
Added test demonstrating bug with irrelevant lost of const
Though this example program appears to lose const-ness, since it is a primitive it is a copy so it is irrelevant.
1 parent 9d8d81a commit 14fc023

File tree

2 files changed

+52
-0
lines changed
  • regression/goto-analyzer/precise-const-fp-supurious-const-loss

2 files changed

+52
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
const int const_number=4;
20+
21+
void func()
22+
{
23+
// Here we 'lose' const-ness except it is a copy so we shouldn't care
24+
int non_const_number=const_number;
25+
const void_fp fp = f2;
26+
fp();
27+
}
28+
29+
int main()
30+
{
31+
func();
32+
33+
return 0;
34+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
KNOWNBUG
2+
main.c
3+
--show-goto-functions --verbosity 10 --pointer-check
4+
^Removing function pointers and virtual functions$
5+
^\s*f2\(\);
6+
--
7+
^warning: ignoring
8+
^\s*\d+:\s*f1\(\);
9+
^\s*\d+:\s*f3\(\);
10+
^\s*\d+:\s*f4\(\);
11+
^\s*\d+:\s*f5\(\);
12+
^\s*\d+:\s*f6\(\);
13+
^\s*\d+:\s*f7\(\);
14+
^\s*\d+:\s*f8\(\);
15+
^\s*\d+:\s*f9\(\);
16+
--
17+
Though this example program appears to lose const-ness, since it is a primitive
18+
it is a copy so it is irrelevant.

0 commit comments

Comments
 (0)