libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / builtin-has-attribute.c
blob9668acec0e2f068f619da9bc480fb00a95525334
1 /* Verify that defining a type in __builtin_has_attribute triggers
2 the expected -Wc++-compat warning and evaluates as expected.
3 Also verify that the expression in __builtin_has_attribute is
4 not evaluated.
6 { dg-do compile }
7 { dg-options "-O2 -Wall -Wc++-compat -fdump-tree-optimized -ftrack-macro-expansion=0" } */
9 #define ATTR(list) __attribute__ (list)
11 #define A(expect, sym, attr) \
12 typedef int Assert [1 - 2 * !(__builtin_has_attribute (sym, attr) == expect)]
14 #define assert(expr) \
15 ((expr) \
16 ? (void)0 \
17 : (__builtin_printf ("Assertion failed on line %i: %s\n", \
18 __LINE__, #expr), \
19 ++nfails))
21 A (0, struct A { int i; }, aligned); /* { dg-warning "expression is invalid in C\\\+\\\+" } */
22 A (1, struct ATTR ((aligned)) B { int i; }, aligned); /* { dg-warning "expression is invalid in C\\\+\\\+" } */
25 static int f (void)
27 __builtin_abort ();
30 int main (void)
32 int n = 0, nfails = 0;
34 assert (0 == __builtin_has_attribute (int[n++], aligned));
35 assert (1 == __builtin_has_attribute (ATTR ((aligned)) int[n++], aligned));
36 assert (1 == __builtin_has_attribute (ATTR ((aligned)) int[f ()], aligned));
37 assert (1 == 1);
39 if (n)
40 __builtin_abort ();
42 if (nfails)
43 __builtin_abort ();
45 return 0;
48 /* { dg-final { scan-tree-dump-times "abort" 0 "optimized" } } */