1 /* Verify __builtin_has_attribute error handling.
3 { dg-options "-Wall -ftrack-macro-expansion=0" } */
5 #define ATTR(list) __attribute__ (list)
9 ATTR ((aligned
)) void faligned (void);
10 ATTR ((aligned (8))) void faligned_8 (void);
12 #define has_attr(x, attr) __builtin_has_attribute (x, attr)
14 #define A(expect, sym, attr) \
15 typedef int Assert [1 - 2 * !(has_attr (sym, attr) == expect)]
20 /* Exercise syntactically invalid arguments. */
22 void test_bad_arguments (void)
24 b
= __builtin_has_attribute (); /* { dg-error "expected \(primary-\)?expression|expected .,." } */
25 b
= __builtin_has_attribute (1); /* { dg-error "expected .,." } */
26 b
= __builtin_has_attribute (void); /* { dg-error "expected .,." } */
27 b
= __builtin_has_attribute (foo
); /* { dg-error ".foo. \(undeclared|was not declared\)" } */
28 /* { dg-error "expected .,." "missing comma" { target *-*-* } .-1 } */
30 /* Verify the implementationm doesn't ICE. */
31 b
= __builtin_has_attribute (foobar
, aligned
); /* { dg-error ".foobar. \(undeclared|was not declared\)" } */
33 b
= __builtin_has_attribute (1, 2, 3); /* { dg-error "expected identifier" } */
34 b
= __builtin_has_attribute (int, 1 + 2); /* { dg-error "expected identifier" } */
35 b
= __builtin_has_attribute (2, "aligned"); /* { dg-error "expected identifier" } */
38 /* Exercise syntactically valid arguments applied in invalid ways. */
40 void test_invalid_arguments (void)
42 b
= has_attr (fnone
, align
); /* { dg-error "unknown attribute .align." } */
43 b
= has_attr (b
, aligned__
); /* { dg-error "unknown attribute .aligned__." } */
44 b
= has_attr (fnone
, aligned (3)); /* { dg-error "alignment .3. is not a positive power of 2" } */
46 /* Verify the out-of-bounds arguments are diagnosed and the result
47 of the built-in is false. */
48 A (0, fnone
, alloc_size (1)); /* { dg-warning "\\\[-Wattributes]" } */
49 A (0, fnone
, alloc_size (2)); /* { dg-warning "\\\[-Wattributes]" } */
51 A (0, int, alloc_size (1)); /* { dg-warning ".alloc_size. attribute only applies to function types" } */
54 A (0, i
, alloc_size (1)); /* { dg-warning ".alloc_size. attribute only applies to function types" } */
56 A (0, faligned_8
, aligned (i
)); /* { dg-error "alignment is not an integer constant" } */
58 typedef ATTR ((aligned (2))) char CA2
;
59 b
= has_attr (CA2
[2], aligned
); /* { dg-error "alignment of array elements is greater than element size" } */