Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/aliasing-3.c

raw
1 #include "../../gcc.dg/analyzer/analyzer-decls.h"
2
3 struct s1
4 {
5 int f1;
6 };
7
8 static struct s1 *p1_glob = NULL;
9
10 void test_1 (struct s1 **pp1, struct s1 *p1_parm)
11 {
12 struct s1 *init_p1_glob = p1_glob;
13
14 __analyzer_eval (p1_glob == init_p1_glob); /* { dg-warning "TRUE" } */
15
16 if (!p1_glob)
17 return;
18
19 __analyzer_eval (p1_glob == init_p1_glob); /* { dg-warning "TRUE" } */
20 __analyzer_eval (p1_glob != NULL); /* { dg-warning "TRUE" } */
21
22 *pp1 = p1_parm;
23
24 /* The write through *pp1 can't have changed p1_glob, because
25 we never take a pointer to p1_glob (and it's static to this TU). */
26 __analyzer_eval (p1_glob == init_p1_glob); /* { dg-warning "TRUE" } */
27 __analyzer_eval (p1_glob != NULL); /* { dg-warning "TRUE" } */
28 }
29
30 struct s2
31 {
32 int f1;
33 };
34
35 static struct s2 *p2_glob = NULL;
36
37 void test_2 (struct s2 **pp2, struct s2 *p2_parm)
38 {
39 /* Ensure that p2_glob is modified. */
40 p2_glob = (struct s2 *) __builtin_malloc (sizeof (struct s2));
41 if (!p2_glob)
42 return;
43
44 __analyzer_eval (p2_glob != NULL); /* { dg-warning "TRUE" } */
45
46 *pp2 = p2_parm;
47
48 /* The write through *pp2 can't have changed p2_glob, because
49 we never take a pointer to p2_glob (and it's static to this TU). */
50 __analyzer_eval (p2_glob != NULL); /* { dg-warning "TRUE" } */
51 }
52
53 struct s3
54 {
55 int f1;
56 };
57
58 struct s3 *p3_glob = NULL;
59
60 void test_3 (struct s3 **pp3, struct s3 *p3_parm)
61 {
62 p3_glob = (struct s3 *) __builtin_malloc (sizeof (struct s3));
63 if (!p3_glob)
64 return;
65
66 __analyzer_eval (p3_glob != NULL); /* { dg-warning "TRUE" } */
67
68 *pp3 = p3_parm;
69
70 /* The write through *pp3 could have changed p3_glob, because
71 another TU could take a pointer to p3_glob. */
72 __analyzer_eval (p3_glob != NULL); /* { dg-warning "UNKNOWN" } */
73 }