PR middle-end/77357 - strlen of constant strings not folded
[official-gcc.git] / gcc / testsuite / gcc.dg / Wattributes-6.c
bloba260d018dcf10bb836c9bf43e86f403953e36f0e
1 /* { dg-do compile }
2 { dg-options "-Wall -Wattributes -ftrack-macro-expansion=0" } */
4 #define ATTR(attrlist) __attribute__ (attrlist)
6 /* Exercise the handling of the mutually exclusive attributes
7 aligned and packed on a type definition. */
9 /* Pointless but benign. */
10 struct ATTR ((aligned, aligned))
11 AlignedAligned { int i; };
13 /* Aligned followed by packed on a type and vice versa has a valid use:
14 to decrease the alignment of a type to the specified boundary. */
15 struct ATTR ((aligned, packed))
16 AlignedPacked { int i; };
18 struct ATTR ((packed, aligned))
19 PackedAligned { int i; };
21 struct ATTR ((aligned (2)))
22 AlignedMemberPacked
24 int ATTR ((packed)) i;
27 struct ATTR ((packed))
28 PackedMemberAligned
30 int ATTR ((aligned (2))) i;
33 /* Silly but benign. */
34 struct ATTR ((packed, packed))
35 PackedPacked { int i; };
38 /* Exercise the handling of the mutually exclusive attributes
39 aligned and packed on a function declaration. */
41 void ATTR ((aligned (8), packed))
42 faligned8_1 (void); /* { dg-warning ".packed. attribute ignored" } */
44 void ATTR ((aligned (8)))
45 faligned8_2 (void); /* { dg-message "previous declaration here" "" { xfail *-*-* } } */
47 void ATTR ((packed))
48 faligned8_2 (void); /* { dg-warning ".packed. attribute ignored" } */
50 /* Exercise the handling of the mutually exclusive attributes
51 always_inline and noinline (in that order). */
53 inline void ATTR ((always_inline))
54 falways_inline1 (void);
56 inline void ATTR ((__always_inline__))
57 falways_inline1 (void);
59 /* Verify that repeating attribute always_inline on the same declaration
60 doesn't trigger a warning. */
61 inline void ATTR ((always_inline, __always_inline__))
62 falways_inline1 (void);
64 /* Verify that repeating attribute always_inline on a distinct declaration
65 doesn't trigger a warning. */
66 inline void ATTR ((always_inline))
67 falways_inline1 (void); /* { dg-message "previous declaration here" } */
69 /* Verify a warning for noinline conflict. */
70 void ATTR ((noinline))
71 falways_inline1 (void) { } /* { dg-warning "ignoring attribute .noinline. because it conflicts with attribute .always_inline." } */
73 /* And again. */
74 void ATTR ((always_inline))
75 falways_inline1 (void);
78 /* Exercise the handling of the mutually exclusive attributes
79 noinline and always_inline (in that order). */
81 void ATTR ((noinline))
82 fnoinline1 (void);
84 void ATTR ((__noinline__))
85 fnoinline1 (void);
87 /* Verify that repeating attribute noinline on the same declaration
88 doesn't trigger a warning. */
89 void ATTR ((noinline, __noinline__))
90 fnoinline1 (void);
92 /* Verify that repeating attribute noinline on a distinct declaration
93 doesn't trigger a warning. */
94 void ATTR ((noinline))
95 fnoinline1 (void); /* { dg-message "previous declaration here" } */
97 /* Verify a warning for always_inline conflict. */
98 void ATTR ((always_inline))
99 fnoinline1 (void) { } /* { dg-warning "ignoring attribute .always_inline. because it conflicts with attribute .noinline." } */
101 /* Verify a warning for gnu_inline conflict. */
102 inline void ATTR ((gnu_inline))
103 fnoinline1 (void); /* { dg-warning "ignoring attribute .gnu_inline. because it conflicts with attribute .noinline." } */
104 /* { dg-warning "follows declaration with attribute .noinline." "inline noinline" { target *-*-* } .-1 } */
106 /* And again. */
107 void ATTR ((noinline))
108 fnoinline1 (void); /* { dg-warning "follows inline declaration" } */
111 /* Exercise the handling of the mutually exclusive attributes
112 noreturn and warn_unused_result. */
114 int ATTR ((__noreturn__))
115 fnoret1 (void);
117 int ATTR ((noreturn))
118 fnoret1 (void); /* { dg-message "previous declaration here" } */
120 int ATTR ((warn_unused_result))
121 fnoret1 (void); /* { dg-warning "ignoring attribute .warn_unused_result. because it conflicts with attribute .noreturn." } */
123 /* Verify that repeating attribute noreturn doesn't trigger a warning. */
124 int ATTR ((noreturn)) fnoret1 (void);
126 int call_noret1 (void)
128 /* Verify that attribute warn_unused_result was, in fact, ignored
129 on the second declaration of fnoret1. */
130 fnoret1 ();
133 int ATTR ((noreturn, warn_unused_result))
134 fnoret2 (void); /* { dg-warning "ignoring attribute .warn_unused_result. because it conflicts with attribute .noreturn." } */
136 /* Verify that repeating attribute noreturn doesn't trigger a warning. */
137 int ATTR ((noreturn)) fnoret2 (void);
139 int call_noret2 (void)
141 /* Verify that attribute warn_unused_result was, in fact, ignored
142 on the second declaration of fnoret2. */
143 fnoret2 ();
146 /* Verify that attribute noreturn isn't diagnosed on a declaration
147 that was previously declared warn_unused_result and that attribute
148 was dropped (because the function returs void). */
150 void ATTR ((warn_unused_result))
151 fnorety6 (void); /* { dg-warning ".warn_unused_result. attribute ignored" } */
153 void ATTR ((noreturn))
154 fnoret6 (void);
157 /* Exercise the handling of the mutually exclusive attributes
158 noreturn and alloc_align. */
160 void* ATTR ((noreturn))
161 fnoret_alloc_align1 (int); /* { dg-message "previous declaration here" } */
163 void* ATTR ((alloc_align (1)))
164 fnoret_alloc_align1 (int); /* { dg-warning "ignoring attribute .alloc_align. because it conflicts with attribute .noreturn." } */
166 void* ATTR ((noreturn, alloc_align (1)))
167 fnoret_alloc_align2 (int); /* { dg-warning "ignoring attribute .alloc_align. because it conflicts with attribute .noreturn." } */
170 void* ATTR ((noreturn)) ATTR ((alloc_align (1)))
171 fnoret_alloc_align3 (int); /* { dg-warning "ignoring attribute .alloc_align. because it conflicts with attribute .noreturn." } */
174 void* ATTR ((alloc_align (1)))
175 falloc_align_noret1 (int); /* { dg-message "previous declaration here" } */
177 void* ATTR ((noreturn))
178 falloc_align_noret1 (int); /* { dg-warning "ignoring attribute .noreturn. because it conflicts with attribute .alloc_align." } */
181 void* ATTR ((alloc_align (1), noreturn))
182 falloc_align_noret2 (int); /* { dg-warning "ignoring attribute .(noreturn|alloc_align). because it conflicts with attribute .(alloc_align|noreturn)." } */
184 void* ATTR ((alloc_align (1))) ATTR ((noreturn))
185 falloc_align_noret3 (int); /* { dg-warning "ignoring attribute .(noreturn|alloc_align). because it conflicts with attribute .(noreturn|alloc_align)." } */
188 /* Exercise the handling of the mutually exclusive attributes
189 noreturn and alloc_size. */
191 void* ATTR ((noreturn))
192 fnoret_alloc_size1 (int); /* { dg-message "previous declaration here" } */
194 void* ATTR ((alloc_size (1)))
195 fnoret_alloc_size1 (int); /* { dg-warning "ignoring attribute .alloc_size. because it conflicts with attribute .noreturn." } */
197 void* ATTR ((noreturn, alloc_size (1)))
198 fnoret_alloc_size2 (int); /* { dg-warning "ignoring attribute .alloc_size. because it conflicts with attribute .noreturn." } */
201 void* ATTR ((noreturn)) ATTR ((alloc_size (1)))
202 fnoret_alloc_size3 (int); /* { dg-warning "ignoring attribute .alloc_size. because it conflicts with attribute .noreturn." } */
205 void* ATTR ((alloc_size (1)))
206 falloc_size_noret1 (int); /* { dg-message "previous declaration here" } */
208 void* ATTR ((noreturn))
209 falloc_size_noret1 (int); /* { dg-warning "ignoring attribute .noreturn. because it conflicts with attribute .alloc_size." } */
212 void* ATTR ((alloc_size (1), noreturn))
213 falloc_size_noret2 (int); /* { dg-warning "ignoring attribute .noreturn. because it conflicts with attribute .alloc_size." } */
215 void* ATTR ((alloc_size (1))) ATTR ((noreturn))
216 falloc_size_noret3 (int); /* { dg-warning "ignoring attribute .noreturn. because it conflicts with attribute .alloc_size." } */
219 /* Exercise the handling of the mutually exclusive attributes
220 noreturn and const. */
222 int ATTR ((noreturn))
223 fnoret_const1 (int); /* { dg-message "previous declaration here" } */
225 int ATTR ((const))
226 fnoret_const1 (int); /* { dg-warning "ignoring attribute .const. because it conflicts with attribute .noreturn." } */
228 /* Unfortunately, attributes on a single declarations may not be processed
229 in the same order as specified... */
230 int ATTR ((noreturn, const))
231 fnoret_const2 (int); /* { dg-warning "ignoring attribute .const. because it conflicts with attribute .noreturn." } */
234 int ATTR ((noreturn)) ATTR ((const))
235 fnoret_const3 (int); /* { dg-warning "ignoring attribute .const. because it conflicts with attribute .noreturn." } */
238 int ATTR ((const))
239 fconst_noret1 (int); /* { dg-message "previous declaration here" } */
241 int ATTR ((noreturn))
242 fconst_noret1 (int); /* { dg-warning "ignoring attribute .noreturn. because it conflicts with attribute .const." } */
245 int ATTR ((const, noreturn))
246 fconst_noret2 (int); /* { dg-warning "ignoring attribute .noreturn. because it conflicts with attribute .const." } */
248 int ATTR ((const)) ATTR ((noreturn))
249 fconst_noret3 (int); /* { dg-warning "ignoring attribute .noreturn. because it conflicts with attribute .const." } */
252 /* Exercise the handling of the mutually exclusive attributes
253 noreturn and malloc. */
255 void* ATTR ((noreturn))
256 fnoret_malloc1 (int); /* { dg-message "previous declaration here" } */
258 void* ATTR ((malloc))
259 fnoret_malloc1 (int); /* { dg-warning "ignoring attribute .malloc. because it conflicts with attribute .noreturn." } */
261 /* Unfortunately, attributes on a single declarations may not be processed
262 in the same order as specified... */
263 void* ATTR ((noreturn, malloc))
264 fnoret_malloc2 (int); /* { dg-warning "ignoring attribute .malloc. because it conflicts with attribute .noreturn." } */
267 void* ATTR ((noreturn)) ATTR ((malloc))
268 fnoret_malloc3 (int); /* { dg-warning "ignoring attribute .malloc. because it conflicts with attribute .noreturn." } */
271 void* ATTR ((__malloc__))
272 fmalloc_noret1 (int);
274 void* ATTR ((malloc))
275 fmalloc_noret1 (int); /* { dg-message "previous declaration here" } */
277 void* ATTR ((noreturn))
278 fmalloc_noret1 (int); /* { dg-warning "ignoring attribute .noreturn. because it conflicts with attribute .malloc." } */
281 void* ATTR ((malloc, noreturn))
282 fmalloc_noret2 (int); /* { dg-warning "ignoring attribute .noreturn. because it conflicts with attribute .malloc." } */
284 void* ATTR ((malloc)) ATTR ((noreturn))
285 fmalloc_noret3 (int); /* { dg-warning "ignoring attribute .noreturn. because it conflicts with attribute .malloc." } */
288 /* Exercise the handling of the mutually exclusive attributes
289 noreturn and pure. */
291 int ATTR ((noreturn))
292 fnoret_pure1 (int); /* { dg-message "previous declaration here" } */
294 int ATTR ((pure))
295 fnoret_pure1 (int); /* { dg-warning "ignoring attribute .pure. because it conflicts with attribute .noreturn." } */
297 /* Unfortunately, attributes on a single declarations may not be processed
298 in the same order as specified... */
299 int ATTR ((noreturn, pure))
300 fnoret_pure2 (int); /* { dg-warning "ignoring attribute .pure. because it conflicts with attribute .noreturn." } */
303 int ATTR ((noreturn)) ATTR ((pure))
304 fnoret_pure3 (int); /* { dg-warning "ignoring attribute .pure. because it conflicts with attribute .noreturn." } */
307 int ATTR ((__pure__))
308 fpure_noret1 (int);
310 int ATTR ((pure))
311 fpure_noret1 (int); /* { dg-message "previous declaration here" } */
313 int ATTR ((noreturn))
314 fpure_noret1 (int); /* { dg-warning "ignoring attribute .noreturn. because it conflicts with attribute .pure." } */
317 int ATTR ((pure, noreturn))
318 fpure_noret2 (int); /* { dg-warning "ignoring attribute .noreturn. because it conflicts with attribute .pur." } */
320 int ATTR ((pure)) ATTR ((noreturn))
321 fpure_noret3 (int); /* { dg-warning "ignoring attribute .noreturn. because it conflicts with attribute .pure." } */
324 /* Exercise the handling of the mutually exclusive attributes
325 noreturn and returns_twice. */
327 int ATTR ((noreturn))
328 fnoret_returns_twice1 (int); /* { dg-message "previous declaration here" } */
330 int ATTR ((returns_twice))
331 fnoret_returns_twice1 (int); /* { dg-warning "ignoring attribute .returns_twice. because it conflicts with attribute .noreturn." } */
333 /* Unfortunately, attributes on a single declarations may not be processed
334 in the same order as specified... */
335 int ATTR ((noreturn, returns_twice))
336 fnoret_returns_twice2 (int); /* { dg-warning "ignoring attribute .returns_twice. because it conflicts with attribute .noreturn." } */
339 int ATTR ((noreturn)) ATTR ((returns_twice))
340 fnoret_returns_twice3 (int); /* { dg-warning "ignoring attribute .returns_twice. because it conflicts with attribute .noreturn." } */
343 int ATTR ((returns_twice))
344 freturns_twice_noret1 (int); /* { dg-message "previous declaration here" } */
346 int ATTR ((noreturn))
347 freturns_twice_noret1 (int); /* { dg-warning "ignoring attribute .noreturn. because it conflicts with attribute .returns_twice." } */
350 int ATTR ((returns_twice, noreturn))
351 freturns_twice_noret2 (int); /* { dg-warning "ignoring attribute .noreturn. because it conflicts with attribute .returns_twice." } */
353 int ATTR ((returns_twice)) ATTR ((noreturn))
354 freturns_twice_noret3 (int); /* { dg-warning "ignoring attribute .noreturn. because it conflicts with attribute .returns_twice." } */
357 /* Exercise the interaction of multiple combinations of mutually
358 exclusive attributes specified on distinct declarations. */
360 inline int ATTR ((always_inline))
361 finline_cold_noreturn (int);
363 inline int ATTR ((cold))
364 finline_cold_noreturn (int);
366 inline int ATTR ((noreturn))
367 finline_cold_noreturn (int);
369 inline int ATTR ((noinline))
370 finline_cold_noreturn (int); /* { dg-warning "ignoring attribute .noinline. because it conflicts with attribute .always_inline." } */
372 inline int ATTR ((hot))
373 finline_cold_noreturn (int); /* { dg-warning "ignoring attribute .hot. because it conflicts with attribute .cold." } */
375 inline int ATTR ((warn_unused_result))
376 finline_cold_noreturn (int); /* { dg-warning "ignoring attribute .warn_unused_result. because it conflicts with attribute .noreturn." } */
378 inline int ATTR ((always_inline))
379 finline_cold_noreturn (int);
381 /* Expect no warning for the missing return statement below because
382 the function is noreturn. */
383 inline int ATTR ((noreturn))
384 finline_cold_noreturn (int i) { (void)&i; __builtin_abort (); }
387 /* Exercise the interaction of multiple combinations of mutually
388 exclusive attributes with some specified on the same declaration
389 and some on distinct declarations. */
391 inline int ATTR ((always_inline, hot))
392 finline_hot_noret_align (int);
394 inline int ATTR ((noreturn, noinline))
395 finline_hot_noret_align (int); /* { dg-warning "ignoring attribute .noinline. because it conflicts with attribute .always_inline." } */
397 inline int ATTR ((cold, aligned (8)))
398 finline_hot_noret_align (int); /* { dg-warning "ignoring attribute .cold. because it conflicts with attribute .hot." } */
400 inline int ATTR ((warn_unused_result))
401 finline_hot_noret_align (int); /* { dg-warning "ignoring attribute .warn_unused_result. because it conflicts with attribute .noreturn." } */
403 inline int ATTR ((aligned (4)))
404 finline_hot_noret_align (int); /* { dg-warning "ignoring attribute .aligned \\(4\\). because it conflicts with attribute .aligned \\(8\\)." "" { target { ! s390*-*-* } } } */
405 /* { dg-error "alignment for 'finline_hot_noret_align' must be at least 8" "" { target s390*-*-* } .-1 } */
407 inline int ATTR ((aligned (8)))
408 finline_hot_noret_align (int);
410 inline int ATTR ((const))
411 finline_hot_noret_align (int); /* { dg-warning "ignoring attribute .const. because it conflicts with attribute .noreturn." } */
413 /* Expect no warning for the missing return statement below because
414 the function is noreturn. */
415 inline int ATTR ((noreturn))
416 finline_hot_noret_align (int i) { (void)&i; __builtin_abort (); }
419 /* Exercise variable attributes. */
421 extern int ATTR ((common))
422 decl_common1; /* { dg-message "previous declaration here" } */
424 extern int ATTR ((nocommon))
425 decl_common1; /* { dg-warning "ignoring attribute .nocommon. because it conflicts with attribute .common." } */
428 extern int ATTR ((nocommon))
429 decl_common2; /* { dg-message "previous declaration here" } */
431 extern int ATTR ((common))
432 decl_common2; /* { dg-warning "ignoring attribute .common. because it conflicts with attribute .nocommon." } */
435 extern int ATTR ((common, nocommon))
436 decl_common3; /* { dg-warning "ignoring attribute .nocommon. because it conflicts with attribute .common." } */
439 extern int ATTR ((common, nocommon))
440 decl_common4; /* { dg-warning "ignoring attribute .nocommon. because it conflicts with attribute .common." } */