Debian Codegraph @

gcc/testsuite/gcc.dg/Wnonnull-3.c

raw
1 /* PR middle-end/80936 - bcmp, bcopy, and bzero not declared nonnull
2 Verify that with optimization, -Wnonnull is issued for calls with
3 non-constant arguments determined to be null.
4 { dg-do compile }
5 { dg-options "-O2 -Wall" } */
6
7 #define NOIPA __attribute__ ((noipa))
8
9 NOIPA void
10 zero0 (void *p, unsigned n)
11 {
12 if (p == 0)
13 __builtin_memset (p, 0, 0);
14 if (p == 0)
15 __builtin_memset (p, 0, n);
16 if (p == 0 && n != 0)
17 __builtin_memset (p, 0, n); // { dg-warning "\\\[-Wnonnull]" }
18 }
19
20 NOIPA void
21 zero1 (void *p, unsigned n)
22 {
23 if (p == 0)
24 __builtin_bzero (p, 0);
25 if (p == 0)
26 __builtin_bzero (p, n);
27 if (p == 0 && n != 0)
28 __builtin_bzero (p, n); // { dg-warning "\\\[-Wnonnull]" }
29 }
30
31 NOIPA void
32 copy0 (void *p, const void *q, unsigned n)
33 {
34 if (p == 0)
35 __builtin_memcpy (p, q, 0);
36 if (p == 0)
37 __builtin_memcpy (p, q, n);
38 if (p == 0 && n != 0)
39 __builtin_memcpy (p, q, n); // { dg-warning "\\\[-Wnonnull]" }
40 }
41
42 NOIPA void
43 copy1 (void *p, const void *q, unsigned n)
44 {
45 if (q == 0)
46 __builtin_memcpy (p, q, 0);
47 if (q == 0)
48 __builtin_memcpy (p, q, n);
49 if (q == 0 && n != 0)
50 __builtin_memcpy (p, q, n); // { dg-warning "\\\[-Wnonnull]" }
51 }
52
53 NOIPA void
54 copy2 (void *p, const void *q, unsigned n)
55 {
56 if (p == 0)
57 __builtin_bcopy (q, p, 0);
58 if (p == 0)
59 __builtin_bcopy (q, p, n);
60 if (p == 0 && n != 0)
61 __builtin_bcopy (q, p, n); // { dg-warning "\\\[-Wnonnull]" }
62 }
63
64 NOIPA void
65 copy3 (void *p, const void *q, unsigned n)
66 {
67 if (q == 0)
68 __builtin_bcopy (q, p, 0);
69 if (q == 0)
70 __builtin_bcopy (q, p, n);
71 if (q == 0 && n != 0)
72 __builtin_bcopy (q, p, n); // { dg-warning "\\\[-Wnonnull]" }
73 }
74
75 NOIPA int
76 cmp0 (const void *p, const void *q, unsigned n)
77 {
78 if (p == 0)
79 return __builtin_memcmp (p, q, 0);
80 return 0;
81 }
82
83 NOIPA int
84 cmp1 (const void *p, const void *q, unsigned n)
85 {
86 if (q == 0)
87 return __builtin_memcmp (p, q, 0);
88 return 0;
89 }
90
91 NOIPA int
92 cmp2 (const void *p, const void *q, unsigned n)
93 {
94 if (p == 0)
95 return __builtin_bcmp (p, q, 0);
96 return 0;
97 }
98
99 NOIPA int
100 cmp3 (const void *p, const void *q, unsigned n)
101 {
102 if (q == 0)
103 return __builtin_bcmp (p, q, 0);
104 return 0;
105 }
106
107 NOIPA int
108 cmp4 (const void *p, const void *q, unsigned n)
109 {
110 if (p == 0)
111 return __builtin_memcmp (p, q, n);
112 return 0;
113 }
114
115 NOIPA int
116 cmp5 (const void *p, const void *q, unsigned n)
117 {
118 if (q == 0)
119 return __builtin_memcmp (p, q, n);
120 return 0;
121 }
122
123 NOIPA int
124 cmp6 (const void *p, const void *q, unsigned n)
125 {
126 if (p == 0)
127 return __builtin_bcmp (p, q, n);
128 return 0;
129 }
130
131 NOIPA int
132 cmp7 (const void *p, const void *q, unsigned n)
133 {
134 if (q == 0)
135 return __builtin_bcmp (p, q, n);
136 return 0;
137 }
138
139 NOIPA int
140 cmp8 (const void *p, const void *q, unsigned n)
141 {
142 if (p == 0 && n != 0)
143 return __builtin_memcmp (p, q, n); // { dg-warning "\\\[-Wnonnull]" }
144 return 0;
145 }
146
147 NOIPA int
148 cmp9 (const void *p, const void *q, unsigned n)
149 {
150 if (q == 0 && n != 0)
151 return __builtin_memcmp (p, q, n); // { dg-warning "\\\[-Wnonnull]" }
152 return 0;
153 }
154
155 NOIPA int
156 cmp10 (const void *p, const void *q, unsigned n)
157 {
158 if (p == 0 && n != 0)
159 return __builtin_bcmp (p, q, n); // { dg-warning "\\\[-Wnonnull]" }
160 return 0;
161 }
162
163 NOIPA int
164 cmp11 (const void *p, const void *q, unsigned n)
165 {
166 if (q == 0 && n != 0)
167 return __builtin_bcmp (p, q, n); // { dg-warning "\\\[-Wnonnull]" }
168 return 0;
169 }