1 /* PR middle-end/88546 - Copy attribute unusable for weakrefs
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)
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)
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);
36 call_fleaf_retnz_test_leaf_eliminated ();
38 extern void call_fleaf_retnz_test_nonnull_eliminated (void);
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
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)
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);
62 call_fweakref_test_leaf_emitted ();
64 /* Expect the following test to be folded to false and the call
66 extern void call_fweakref_fleaf_nonnull_eliminated (void);
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");
87 extern __typeof (fnoreturn
)
88 ATTR (alias ("fnoreturn_name"), copy (fnoreturn
))
91 int call_fnoreturn_alias (void)