1
2 int *global_ptr;
3
4 static void __attribute__((noinline))
5 called_by_test_1 (void)
6 {
7 int i = 42;
8 global_ptr = &i;
9 }
10
11 int test_1 (void)
12 {
13 called_by_test_1 ();
14 return *global_ptr; /* { dg-warning "dereferencing pointer 'global_ptr' to within stale stack frame" } */
15 }
16
17 static void __attribute__((noinline))
18 called_by_test_2 (int **out)
19 {
20 int i = 42;
21 *out = &i;
22 }
23
24 int test_2 (void)
25 {
26 int *ptr;
27 called_by_test_2 (&ptr);
28 return *ptr; /* { dg-warning "dereferencing pointer 'ptr' to within stale stack frame" } */
29 }
30
31 static int __attribute__((noinline))
32 called_by_test_3 (int **out)
33 {
34 int i = 42;
35 *out = &i;
36 return i;
37 }
38
39 int test_3 (void)
40 {
41 int *lhs_ptr;
42 *lhs_ptr = called_by_test_3 (&lhs_ptr); /* { dg-warning "use of uninitialized value 'lhs_ptr'" } */
43 return *lhs_ptr;
44 }