Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/pr96651-2.c

raw
1 #include "analyzer-decls.h"
2
3 extern void unknown_fn (void *, void *);
4
5 static int a;
6 static int b = 42;
7 int c;
8 int d = 17;
9 struct { int x; int y; char rgb[3]; } s = {5, 10, {0x80, 0x40, 0x20}};
10 void *e = &d;
11
12 extern struct _IO_FILE *stderr;
13
14 /* If we're not on a direct path from "main", we know nothing about
15 the values of globals. */
16
17 void test (void)
18 {
19 __analyzer_eval (a == 0); /* { dg-warning "UNKNOWN" } */
20 __analyzer_eval (b == 42); /* { dg-warning "UNKNOWN" } */
21 __analyzer_eval (c == 0); /* { dg-warning "UNKNOWN" } */
22 __analyzer_eval (d == 17); /* { dg-warning "UNKNOWN" } */
23 __analyzer_eval (s.rgb[2] == 0x20); /* { dg-warning "UNKNOWN" } */
24 __analyzer_eval (e == &d); /* { dg-warning "UNKNOWN" } */
25 __analyzer_eval (stderr == 0); /* { dg-warning "UNKNOWN" } */
26 }
27
28 static void __attribute__((noinline))
29 __analyzer_called_from_main (void)
30 {
31 /* When accessed from main, the vars still have their initializer values. */
32 __analyzer_eval (a == 0); /* { dg-warning "TRUE" } */
33 __analyzer_eval (b == 42); /* { dg-warning "TRUE" } */
34 __analyzer_eval (c == 0); /* { dg-warning "TRUE" } */
35 __analyzer_eval (d == 17); /* { dg-warning "TRUE" } */
36 __analyzer_eval (s.rgb[2] == 0x20); /* { dg-warning "TRUE" } */
37 __analyzer_eval (e == &d); /* { dg-warning "TRUE" } */
38 /* ...apart from those defined in a different TU (or that were inited
39 before "main"). */
40 __analyzer_eval (stderr == 0); /* { dg-warning "UNKNOWN" } */
41 }
42
43 int main (void)
44 {
45 /* When accessed from main, the vars still have their initializer values. */
46 __analyzer_eval (a == 0); /* { dg-warning "TRUE" } */
47 __analyzer_eval (b == 42); /* { dg-warning "TRUE" } */
48 __analyzer_eval (c == 0); /* { dg-warning "TRUE" } */
49 __analyzer_eval (d == 17); /* { dg-warning "TRUE" } */
50 __analyzer_eval (s.rgb[2] == 0x20); /* { dg-warning "TRUE" } */
51 __analyzer_eval (e == &d); /* { dg-warning "TRUE" } */
52 /* ...apart from those defined in a different TU (or that were inited
53 before "main"). */
54 __analyzer_eval (stderr == 0); /* { dg-warning "UNKNOWN" } */
55
56 __analyzer_called_from_main ();
57
58 unknown_fn (&a, &c);
59
60 /* "a" escaped above and so could have been written to. */
61 __analyzer_eval (a == 0); /* { dg-warning "UNKNOWN" } */
62 /* "b" doesn't escape and is static, and so must still have its
63 initial value. */
64 __analyzer_eval (b == 42); /* { dg-warning "TRUE" } */
65 /* The other globals are non-static and so have implicitly escaped,
66 and so could have been written to. */
67 __analyzer_eval (c == 0); /* { dg-warning "UNKNOWN" } */
68 __analyzer_eval (d == 17); /* { dg-warning "UNKNOWN" } */
69 __analyzer_eval (s.rgb[2] == 0x20); /* { dg-warning "UNKNOWN" } */
70 __analyzer_eval (e == &d); /* { dg-warning "UNKNOWN" } */
71 __analyzer_eval (stderr == 0); /* { dg-warning "UNKNOWN" } */
72 }