Debian Codegraph @

gcc/testsuite/gcc.dg/nonnull-10.c

raw
1 /* { dg-do compile } */
2 /* { dg-options "-O2 -Wnonnull" } */
3
4 #define N(x, y) __attribute__ ((nonnull_if_nonzero (x, y)))
5
6 void N (1, 2) f1_1 (void *, int);
7
8 void N (1, 3) f2_1 (void *, void *, int);
9 void N (1, 3) N (2, 3) f2_1_2 (void *, void *, int);
10
11 void N (1, 4) N (3, 5) f3_1_3 (void *, void *, void *, int, int);
12
13 void N (1, 5) N (2, 5) N (4, 5) g4_1_2_4 (void *, void *, void *, void *, long);
14 void N (1, 5) N (3, 5) N (4, 5) g4_1_3_4 (void *, void *, void *, void *, long);
15 void N (2, 5) N (3, 5) N (4, 5) g4_2_3_4 (void *, void *, void *, void *, long);
16
17 void N (1, 17) N (3, 17) N (5, 17) N (7, 17) N (11, 17) N (13, 17)
18 g16_1_3_5_7_11_13 (void *, void *, void *, void *,
19 void *, void *, void *, void *,
20 void *, void *, void *, void *,
21 void *, void *, void *, void *, int);
22
23 static void *null (void) { return 0; }
24
25 void
26 test (int t, long u)
27 {
28 void *p0 = null ();
29 void *px = &px;
30
31 f1_1 (p0, 0);
32 f1_1 (p0, t);
33 f1_1 (p0, 42); /* { dg-warning "argument 1 null where non-null expected because argument 2 is nonzero" } */
34 if (t)
35 f1_1 (p0, t); /* { dg-warning "argument 1 null where non-null expected because argument 2 is nonzero" } */
36 f1_1 (px, 17);
37
38 f2_1 (p0, px, 0);
39 f2_1 (p0, px, t);
40 f2_1 (p0, px, 5); /* { dg-warning "argument 1 null where non-null expected because argument 3 is nonzero" } */
41 if (t > 4)
42 f2_1 (p0, px, t); /* { dg-warning "argument 1 null where non-null expected because argument 3 is nonzero" } */
43 f2_1 (px, p0, 17);
44 f2_1 (p0, p0, 0);
45 if (t < 0)
46 f2_1 (p0, p0, t); /* { dg-warning "argument 1 null where non-null expected because argument 3 is nonzero" } */
47
48 f2_1_2 (p0, p0, 0);
49 f2_1_2 (p0, p0, t);
50 f2_1_2 (p0, px, 1); /* { dg-warning "argument 1 null where non-null expected because argument 3 is nonzero" } */
51 if (t > 8)
52 f2_1_2 (p0, px, t); /* { dg-warning "argument 1 null where non-null expected because argument 3 is nonzero" } */
53 f2_1_2 (px, p0, -3); /* { dg-warning "argument 2 null where non-null expected because argument 3 is nonzero" } */
54 if (t < -2)
55 f2_1_2 (px, p0, t); /* { dg-warning "argument 2 null where non-null expected because argument 3 is nonzero" } */
56 f2_1_2 (p0, p0, 8); /* { dg-warning "argument 1 null where non-null expected because argument 3 is nonzero" } */
57 /* { dg-warning "argument 2 null where non-null expected because argument 3 is nonzero" "argument 2" { target *-*-* } .-1 } */
58 if (t > 7)
59 f2_1_2 (p0, p0, t); /* { dg-warning "argument 1 null where non-null expected because argument 3 is nonzero" } */
60 /* { dg-warning "argument 2 null where non-null expected because argument 3 is nonzero" "argument 2" { target *-*-* } .-1 } */
61
62 f3_1_3 (p0, p0, p0, 0, 0);
63 f3_1_3 (p0, p0, px, 0, 6);
64 f3_1_3 (px, p0, p0, 2, 0);
65 f3_1_3 (p0, p0, p0, t, t);
66 f3_1_3 (p0, p0, px, t, 6);
67 f3_1_3 (px, p0, p0, 2, t);
68 f3_1_3 (p0, px, px, 8, 2); /* { dg-warning "argument 1 null where non-null expected because argument 4 is nonzero" } */
69 if (t > 9)
70 f3_1_3 (p0, px, px, t, 3); /* { dg-warning "argument 1 null where non-null expected because argument 4 is nonzero" } */
71 f3_1_3 (px, p0, px, 9, 10);
72 if (t > 11)
73 f3_1_3 (px, p0, px, t, t);
74 f3_1_3 (px, px, p0, 10, 11); /* { dg-warning "argument 3 null where non-null expected because argument 5 is nonzero" } */
75 if (t < -5)
76 f3_1_3 (px, px, p0, 0, t); /* { dg-warning "argument 3 null where non-null expected because argument 5 is nonzero" } */
77 f3_1_3 (p0, p0, px, 11, 12); /* { dg-warning "argument 1 null where non-null expected because argument 4 is nonzero" } */
78 if (t > 26)
79 f3_1_3 (p0, p0, px, t, 0); /* { dg-warning "argument 1 null where non-null expected because argument 4 is nonzero" } */
80 f3_1_3 (px, p0, p0, 12, 13); /* { dg-warning "argument 3 null where non-null expected because argument 5 is nonzero" } */
81 if (t > 31)
82 f3_1_3 (px, p0, p0, 12, t); /* { dg-warning "argument 3 null where non-null expected because argument 5 is nonzero" } */
83 f3_1_3 (p0, p0, p0, 13, 14); /* { dg-warning "argument 1 null where non-null expected because argument 4 is nonzero" } */
84 /* { dg-warning "argument 3 null where non-null expected because argument 5 is nonzero" "argument 3" { target *-*-* } .-1 } */
85 if (t > 28)
86 f3_1_3 (p0, p0, p0, t, t + 1); /* { dg-warning "argument 1 null where non-null expected because argument 4 is nonzero" } */
87 /* { dg-warning "argument 3 null where non-null expected because argument 5 is nonzero" "argument 3" { target *-*-* } .-1 } */
88
89 g4_1_2_4 (p0, px, px, px, u);
90 g4_1_2_4 (px, p0, px, px, u);
91 g4_1_2_4 (px, px, p0, px, u);
92 g4_1_2_4 (px, px, px, p0, u);
93 g4_1_2_4 (p0, px, px, px, 0);
94 g4_1_2_4 (px, p0, px, px, 0);
95 g4_1_2_4 (px, px, p0, px, 0);
96 g4_1_2_4 (px, px, px, p0, 0);
97 g4_1_2_4 (p0, px, px, px, 15); /* { dg-warning "argument 1 null where non-null expected because argument 5 is nonzero" } */
98 if (u)
99 g4_1_2_4 (p0, px, px, px, u); /* { dg-warning "argument 1 null where non-null expected because argument 5 is nonzero" } */
100 g4_1_2_4 (px, p0, px, px, 16); /* { dg-warning "argument 2 null where non-null expected because argument 5 is nonzero" } */
101 if (u > 2)
102 g4_1_2_4 (px, p0, px, px, u); /* { dg-warning "argument 2 null where non-null expected because argument 5 is nonzero" } */
103 g4_1_2_4 (px, px, p0, px, 17);
104 if (u > 3)
105 g4_1_2_4 (px, px, p0, px, u);
106 g4_1_2_4 (px, px, px, p0, 18); /* { dg-warning "argument 4 null where non-null expected because argument 5 is nonzero" } */
107 if (u < -2 || u > 10)
108 g4_1_2_4 (px, px, px, p0, u); /* { dg-warning "argument 4 null where non-null expected because argument 5 is nonzero" } */
109
110 g4_1_3_4 (p0, px, px, px, u);
111 g4_1_3_4 (px, p0, px, px, u);
112 g4_1_3_4 (px, px, p0, px, u);
113 g4_1_3_4 (px, px, px, p0, u);
114 g4_1_3_4 (p0, px, px, px, 0);
115 g4_1_3_4 (px, p0, px, px, 0);
116 g4_1_3_4 (px, px, p0, px, 0);
117 g4_1_3_4 (px, px, px, p0, 0);
118 g4_1_3_4 (p0, px, px, px, 20); /* { dg-warning "argument 1 null where non-null expected because argument 5 is nonzero" } */
119 if (u > 4)
120 g4_1_3_4 (p0, px, px, px, u); /* { dg-warning "argument 1 null where non-null expected because argument 5 is nonzero" } */
121 g4_1_3_4 (px, p0, px, px, 21);
122 if (u > 6 || u < -24)
123 g4_1_3_4 (px, p0, px, px, u);
124 g4_1_3_4 (px, px, p0, px, 22); /* { dg-warning "argument 3 null where non-null expected because argument 5 is nonzero" } */
125 if (u > 9)
126 g4_1_3_4 (px, px, p0, px, u - 3); /* { dg-warning "argument 3 null where non-null expected because argument 5 is nonzero" } */
127 g4_1_3_4 (px, px, px, p0, 23); /* { dg-warning "argument 4 null where non-null expected because argument 5 is nonzero" } */
128 if (u > 10)
129 g4_1_3_4 (px, px, px, p0, u); /* { dg-warning "argument 4 null where non-null expected because argument 5 is nonzero" } */
130
131 g4_2_3_4 (p0, px, px, px, u);
132 g4_2_3_4 (px, p0, px, px, u);
133 g4_2_3_4 (px, px, p0, px, u);
134 g4_2_3_4 (px, px, px, p0, u);
135 g4_2_3_4 (p0, px, px, px, 0);
136 g4_2_3_4 (px, p0, px, px, 0);
137 g4_2_3_4 (px, px, p0, px, 0);
138 g4_2_3_4 (px, px, px, p0, 0);
139 g4_2_3_4 (p0, px, px, px, 1);
140 if (u > 12)
141 g4_2_3_4 (p0, px, px, px, u);
142 g4_2_3_4 (px, p0, px, px, 2); /* { dg-warning "argument 2 null where non-null expected because argument 5 is nonzero" } */
143 if (u > 17)
144 g4_2_3_4 (px, p0, px, px, u - 3); /* { dg-warning "argument 2 null where non-null expected because argument 5 is nonzero" } */
145 g4_2_3_4 (px, px, p0, px, 3); /* { dg-warning "argument 3 null where non-null expected because argument 5 is nonzero" } */
146 if (u > 24)
147 g4_2_3_4 (px, px, p0, px, u); /* { dg-warning "argument 3 null where non-null expected because argument 5 is nonzero" } */
148 g4_2_3_4 (px, px, px, p0, 4); /* { dg-warning "argument 4 null where non-null expected because argument 5 is nonzero" } */
149 if (u > 42)
150 g4_2_3_4 (px, px, px, p0, u); /* { dg-warning "argument 4 null where non-null expected because argument 5 is nonzero" } */
151
152 g16_1_3_5_7_11_13 (px, px, px, px, px, px, px, px,
153 px, px, px, px, px, px, px, px, 17);
154 g16_1_3_5_7_11_13 (p0, p0, p0, p0, p0, p0, p0, p0,
155 p0, p0, p0, p0, p0, p0, p0, p0, t);
156 g16_1_3_5_7_11_13 (p0, p0, p0, p0, p0, p0, p0, p0,
157 p0, p0, p0, p0, p0, p0, p0, p0, 0);
158
159 g16_1_3_5_7_11_13 (px, p0, px, p0, px, p0, px, p0, p0, p0, px, p0, p0, p0, p0, p0, 2); /* { dg-warning "argument 13 null where non-null expected because argument 17 is nonzero" } */
160 if (t > 122)
161 g16_1_3_5_7_11_13 (px, p0, px, p0, px, p0, px, p0, p0, p0, px, p0, p0, p0, p0, p0, t); /* { dg-warning "argument 13 null where non-null expected because argument 17 is nonzero" } */
162 }