]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/attr-copy-6.c
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / attr-copy-6.c
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-visibility "hidden" }
6 { dg-require-alias "" }
7 { dg-require-weak "" } */
8
9 #define ATTR(...) __attribute__ ((__VA_ARGS__))
10 #define ASRT(expr) _Static_assert (expr, #expr)
11
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;
15
16 void reset_unit_local (void)
17 {
18 unit_local = 0;
19 }
20
21 /* Attribute leaf implies that fleaf() doesn't modify unit_local(). */
22 ATTR (leaf, returns_nonnull)
23 void* fleaf_retnz (void);
24
25 /* Verify both attributes have been applied. */
26 ASRT (__builtin_has_attribute (fleaf_retnz, leaf));
27 ASRT (__builtin_has_attribute (fleaf_retnz, returns_nonnull));
28
29 /* Verify that attribute leaf has the expected effect. */
30 void call_fleaf_retnz (void)
31 {
32 int i = unit_local;
33 void *p = fleaf_retnz ();
34
35 /* Expect both tests to be folded to false and the calls eliminated. */
36 extern void call_fleaf_retnz_test_leaf_eliminated (void);
37 if (i != unit_local)
38 call_fleaf_retnz_test_leaf_eliminated ();
39
40 extern void call_fleaf_retnz_test_nonnull_eliminated (void);
41 if (p == 0)
42 call_fleaf_retnz_test_nonnull_eliminated ();
43 }
44
45
46 /* Verify that attribute copy copies the returns_nonnull attribute
47 but doesn't try to copy attribute leaf which only applies to extern
48 function. */
49 static ATTR (copy (fleaf_retnz), weakref ("fleaf_retnz"))
50 void* fweakref_fleaf_retnz_copy (void);
51
52 ASRT (!__builtin_has_attribute (fweakref_fleaf_retnz_copy, leaf));
53 ASRT (__builtin_has_attribute (fweakref_fleaf_retnz_copy, returns_nonnull));
54
55 void call_fweakref_fleaf_retnz_copy (void)
56 {
57 int i = unit_local;
58 void *p = fweakref_fleaf_retnz_copy ();
59
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);
63 if (i != unit_local)
64 call_fweakref_test_leaf_emitted ();
65
66 /* Expect the following test to be folded to false and the call
67 eliminated. */
68 extern void call_fweakref_fleaf_nonnull_eliminated (void);
69 if (p == 0)
70 call_fweakref_fleaf_nonnull_eliminated ();
71 }
72
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. */
77
78 extern _Noreturn void fnoreturn (void);
79
80 extern __typeof (fnoreturn)
81 ATTR (visibility ("hidden"))
82 fnoreturn __asm__ ("fnoreturn_name");
83
84 void fnoreturn (void)
85 {
86 __builtin_abort ();
87 }
88
89 extern __typeof (fnoreturn)
90 ATTR (alias ("fnoreturn_name"), copy (fnoreturn))
91 fnoreturn_alias;
92
93 int call_fnoreturn_alias (void)
94 {
95 fnoreturn_alias ();
96 }