Debian Codegraph @

gcc/testsuite/g++.dg/ext/attr-copy.C

raw
1 /* PR middle-end/88546 - Copy attribute unusable for weakrefs
2 { dg-do compile }
3 { dg-options "-O1 -Wall -fdump-tree-optimized" }
4 { dg-require-weak "" } */
5
6 #define ATTR(...) __attribute__ ((__VA_ARGS__))
7 #define ASRT(expr) _Static_assert (expr, #expr)
8
9 extern "C" {
10
11 ATTR (leaf, nothrow) int
12 fnothrow ()
13 {
14 return 0;
15 }
16
17 static __typeof__ (fnothrow)
18 ATTR (weakref ("fnothrow"), copy (fnothrow))
19 alias_fnothrow;
20
21
22 ATTR (leaf) int
23 fthrow_none () throw ()
24 {
25 return 0;
26 }
27
28 // Verify that no warning is issued for the alias having less
29 // restrictive attributes than the target: nothrow.
30 static __typeof (fthrow_none)
31 ATTR (weakref ("fthrow_none"), copy (fthrow_none))
32 alias_fthrow_none;
33
34 // Same as above but with no definition of the target.
35 ATTR (leaf) int
36 fthrow_none_nodef () throw ();
37
38 static __typeof (fthrow_none_nodef)
39 ATTR (weakref ("fthrow_none_nodef"), copy (fthrow_none_nodef))
40 alias_fthrow_none_nodef;
41
42 // And again but without using typeof to make sure the nothrow
43 // bit is copied by attribute copy alone.
44 static int
45 ATTR (weakref ("fthrow_none_nodef"), copy (fthrow_none_nodef))
46 alias_fthrow_none_nodef_func ();
47 }
48
49
50 struct UsrClass
51 {
52 ~UsrClass ();
53 };
54
55 // Verify that the nothrow attribute/bit was copied to the alias and
56 // that no exception handling code is emitted in any of these calls.
57
58 int call_alias_fnothrow ()
59 {
60 UsrClass usr;
61 return alias_fnothrow ();
62 }
63
64 int call_alias_fthrow_none ()
65 {
66 UsrClass usr;
67 return alias_fthrow_none ();
68 }
69
70 int call_alias_fthrow_none_nodef ()
71 {
72 UsrClass usr;
73 return alias_fthrow_none_nodef ();
74 }
75
76 int call_alias_fthrow_none_nodef_func ()
77 {
78 UsrClass usr;
79 return alias_fthrow_none_nodef_func ();
80 }
81
82 // { dg-final { scan-tree-dump-not "__builtin_unwind" "optimized" } }