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-visibility "hidden" }
6 { dg-require-alias "" }
7 { dg-require-weak "" } */
9 #define ATTR(...) __attribute__ ((__VA_ARGS__))
10 #define ASRT(expr) _Static_assert (expr, #expr)
12 /* Variable that is local to this translation unit but that can
13 be modified from other units by calling reset_unit_local(). */
14 static int unit_local
;
16 void reset_unit_local (void)
21 /* Attribute leaf implies that fleaf() doesn't modify unit_local(). */
22 ATTR (leaf
, returns_nonnull
)
23 void* fleaf_retnz (void);
25 /* Verify both attributes have been applied. */
26 ASRT (__builtin_has_attribute (fleaf_retnz
, leaf
));
27 ASRT (__builtin_has_attribute (fleaf_retnz
, returns_nonnull
));
29 /* Verify that attribute leaf has the expected effect. */
30 void call_fleaf_retnz (void)
33 void *p
= fleaf_retnz ();
35 /* Expect both tests to be folded to false and the calls eliminated. */
36 extern void call_fleaf_retnz_test_leaf_eliminated (void);
38 call_fleaf_retnz_test_leaf_eliminated ();
40 extern void call_fleaf_retnz_test_nonnull_eliminated (void);
42 call_fleaf_retnz_test_nonnull_eliminated ();
46 /* Verify that attribute copy copies the returns_nonnull attribute
47 but doesn't try to copy attribute leaf which only applies to extern
49 static ATTR (copy (fleaf_retnz
), weakref ("fleaf_retnz"))
50 void* fweakref_fleaf_retnz_copy (void);
52 ASRT (!__builtin_has_attribute (fweakref_fleaf_retnz_copy
, leaf
));
53 ASRT (__builtin_has_attribute (fweakref_fleaf_retnz_copy
, returns_nonnull
));
55 void call_fweakref_fleaf_retnz_copy (void)
58 void *p
= fweakref_fleaf_retnz_copy ();
60 /* Since leaf is not copied, expect the following test not to be
61 folded and the call to be emitted. */
62 extern void call_fweakref_test_leaf_emitted (void);
64 call_fweakref_test_leaf_emitted ();
66 /* Expect the following test to be folded to false and the call
68 extern void call_fweakref_fleaf_nonnull_eliminated (void);
70 call_fweakref_fleaf_nonnull_eliminated ();
73 /* This is reduced from libgfortran/runtime/error.c. Verify it
74 doesn't trigger warnings and that the noreturn bit is copied
75 to the alias by verifying that calling the alias in a non-void
76 function with no return statement isn't diagnosed. */
78 extern _Noreturn
void fnoreturn (void);
80 extern __typeof (fnoreturn
)
81 ATTR (visibility ("hidden"))
82 fnoreturn
__asm__ ("fnoreturn_name");
89 extern __typeof (fnoreturn
)
90 ATTR (alias ("fnoreturn_name"), copy (fnoreturn
))
93 int call_fnoreturn_alias (void)