builtin-has-attribute-4.c: Skip on 32-bit hppa*-*-hpux*.
[official-gcc.git] / gcc / testsuite / gcc.dg / attr-copy-6.c
blob010db0d508ad70ea288c12a448bf08bfca49ae64
1 /* PR middle-end/88546 - Copy attribute unusable for weakrefs
2 { dg-do compile }
3 { dg-skip-if "Attributes not supported" { { hppa*-*-hpux* } && { ! lp64 } } }
4 { dg-options "-O2 -Wall" }
5 { dg-require-weak "" } */
7 #define ATTR(...) __attribute__ ((__VA_ARGS__))
8 #define ASRT(expr) _Static_assert (expr, #expr)
10 /* Variable that is local to this translation unit but that can
11 be modified from other units by calling reset_unit_local(). */
12 static int unit_local;
14 void reset_unit_local (void)
16 unit_local = 0;
19 /* Attribute leaf implies that fleaf() doesn't modify unit_local(). */
20 ATTR (leaf, returns_nonnull)
21 void* fleaf_retnz (void);
23 /* Verify both attributes have been applied. */
24 ASRT (__builtin_has_attribute (fleaf_retnz, leaf));
25 ASRT (__builtin_has_attribute (fleaf_retnz, returns_nonnull));
27 /* Verify that attribute leaf has the expected effect. */
28 void call_fleaf_retnz (void)
30 int i = unit_local;
31 void *p = fleaf_retnz ();
33 /* Expect both tests to be folded to false and the calls eliminated. */
34 extern void call_fleaf_retnz_test_leaf_eliminated (void);
35 if (i != unit_local)
36 call_fleaf_retnz_test_leaf_eliminated ();
38 extern void call_fleaf_retnz_test_nonnull_eliminated (void);
39 if (p == 0)
40 call_fleaf_retnz_test_nonnull_eliminated ();
44 /* Verify that attribute copy copies the returns_nonnull attribute
45 but doesn't try to copy attribute leaf which only applies to extern
46 function. */
47 static ATTR (copy (fleaf_retnz), weakref ("fleaf_retnz"))
48 void* fweakref_fleaf_retnz_copy (void);
50 ASRT (!__builtin_has_attribute (fweakref_fleaf_retnz_copy, leaf));
51 ASRT (__builtin_has_attribute (fweakref_fleaf_retnz_copy, returns_nonnull));
53 void call_fweakref_fleaf_retnz_copy (void)
55 int i = unit_local;
56 void *p = fweakref_fleaf_retnz_copy ();
58 /* Since leaf is not copied, expect the following test not to be
59 folded and the call to be emitted. */
60 extern void call_fweakref_test_leaf_emitted (void);
61 if (i != unit_local)
62 call_fweakref_test_leaf_emitted ();
64 /* Expect the following test to be folded to false and the call
65 eliminated. */
66 extern void call_fweakref_fleaf_nonnull_eliminated (void);
67 if (p == 0)
68 call_fweakref_fleaf_nonnull_eliminated ();
71 /* This is reduced from libgfortran/runtime/error.c. Verify it
72 doesn't trigger warnings and that the noreturn bit is copied
73 to the alias by verifying that calling the alias in a non-void
74 function with no return statement isn't diagnosed. */
76 extern _Noreturn void fnoreturn (void);
78 extern __typeof (fnoreturn)
79 ATTR (visibility ("hidden"))
80 fnoreturn __asm__ ("fnoreturn_name");
82 void fnoreturn (void)
84 __builtin_abort ();
87 extern __typeof (fnoreturn)
88 ATTR (alias ("fnoreturn_name"), copy (fnoreturn))
89 fnoreturn_alias;
91 int call_fnoreturn_alias (void)
93 fnoreturn_alias ();