libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / attr-weakref-1.c
blobf13aee446ce616573af06211ffbee6918b673411
1 // { dg-do run }
2 // { dg-require-weak "" }
3 // On darwin, we use attr-weakref-1-darwin.c.
5 // This test requires support for undefined weak symbols. This support
6 // is not available on the following targets. The test is skipped rather than
7 // xfailed to suppress the warning that would otherwise arise.
8 // { dg-skip-if "" { "hppa*-*-hpux*" "*-*-aix*" "nvptx-*-*" } }
10 // For kernel modules and static RTPs, the loader treats undefined weak
11 // symbols in the same way as undefined strong symbols. The test
12 // therefore fails to load, so skip it.
13 // { dg-skip-if "" { "*-*-vxworks*" && nonpic } "*" { "-non-static" } }
14 // { dg-options "-O2" }
15 // { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } }
16 // { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } }
17 // One subtest doesn't assemble with the Solaris/x86 as (PR ipa/70582)
18 // { dg-additional-options "-DSOLARIS_X86_AS" { target { *86*-*-solaris2* && { ! gas } } } }
19 // { dg-additional-sources "attr-weakref-1a.c" }
21 // Copyright 2005 Free Software Foundation, Inc.
22 // Contributed by Alexandre Oliva <aoliva@redhat.com>
24 // Torture test for weakrefs. The first letter of an identifier
25 // indicates whether/how it is defined; the second letter indicates
26 // whether it is part of a variable or function test; the number that
27 // follows is a test counter, and a letter that may follow enables
28 // multiple identifiers within the same test (e.g., multiple weakrefs
29 // or pointers to the same identifier).
31 // Identifiers starting with W are weakrefs; those with p are
32 // pointers; those with g are global definitions; those with l are
33 // local definitions; those with w are expected to be weak undefined
34 // in the symbol table; those with u are expected to be marked as
35 // non-weak undefined in the symbol table.
37 #include <stdlib.h>
39 #define USED __attribute__((used))
41 typedef int vtype;
43 extern vtype wv1;
44 static vtype Wv1a __attribute__((weakref ("wv1")));
45 static vtype *pv1a USED = &Wv1a;
47 vtype gv2;
48 static vtype Wv2a __attribute__((weakref ("gv2")));
49 static vtype *pv2a USED = &Wv2a;
51 #if !defined SOLARIS_X86_AS
52 static vtype lv3;
53 static vtype Wv3a __attribute__((weakref ("lv3")));
54 static vtype *pv3a USED = &Wv3a;
55 #endif
57 extern vtype uv4;
58 static vtype Wv4a __attribute__((weakref ("uv4")));
59 static vtype *pv4a USED = &Wv4a;
60 static vtype *pv4 USED = &uv4;
62 static vtype Wv5a __attribute__((weakref ("uv5")));
63 static vtype *pv5a USED = &Wv5a;
64 extern vtype uv5;
65 static vtype *pv5 USED = &uv5;
67 static vtype Wv6a __attribute__((weakref ("wv6")));
68 static vtype *pv6a USED = &Wv6a;
69 extern vtype wv6;
71 static vtype Wv7a __attribute__((weakref ("uv7")));
72 static vtype* USED fv7 (void) {
73 return &Wv7a;
75 extern vtype uv7;
76 static vtype* USED fv7a (void) {
77 return &uv7;
80 extern vtype uv8;
81 static vtype* USED fv8a (void) {
82 return &uv8;
84 static vtype Wv8a __attribute__((weakref ("uv8")));
85 static vtype* USED fv8 (void) {
86 return &Wv8a;
89 extern vtype wv9 __attribute__((weak));
90 static vtype Wv9a __attribute__((weakref ("wv9")));
91 static vtype *pv9a USED = &Wv9a;
93 static vtype Wv10a __attribute__((weakref ("Wv10b")));
94 static vtype Wv10b __attribute__((weakref ("Wv10c")));
95 static vtype Wv10c __attribute__((weakref ("Wv10d")));
96 static vtype Wv10d __attribute__((weakref ("wv10")));
97 extern vtype wv10;
99 extern vtype wv11;
100 static vtype Wv11d __attribute__((weakref ("wv11")));
101 static vtype Wv11c __attribute__((weakref ("Wv11d")));
102 static vtype Wv11b __attribute__((weakref ("Wv11c")));
103 static vtype Wv11a __attribute__((weakref ("Wv11b")));
105 static vtype Wv12 __attribute__((weakref ("wv12")));
106 extern vtype wv12 __attribute__((weak));
108 static vtype Wv13 __attribute__((weakref ("wv13")));
109 extern vtype wv13 __attribute__((weak));
111 static vtype Wv14a __attribute__((weakref ("wv14")));
112 static vtype Wv14b __attribute__((weakref ("wv14")));
113 extern vtype wv14 __attribute__((weak));
115 typedef void ftype(void);
117 extern ftype wf1;
118 static ftype Wf1a __attribute__((weakref ("wf1")));
119 static ftype *pf1a USED = &Wf1a;
120 static ftype Wf1c __attribute__((weakref));
121 extern ftype Wf1c __attribute__((alias ("wf1")));
122 static ftype *pf1c USED = &Wf1c;
124 void gf2(void) {}
125 static ftype Wf2a __attribute__((weakref ("gf2")));
126 static ftype *pf2a USED = &Wf2a;
128 static void lf3(void) {}
129 static ftype Wf3a __attribute__((weakref ("lf3")));
130 static ftype *pf3a USED = &Wf3a;
132 extern ftype uf4;
133 static ftype Wf4a __attribute__((weakref ("uf4")));
134 static ftype *pf4a USED = &Wf4a;
135 static ftype *pf4 USED = &uf4;
137 static ftype Wf5a __attribute__((weakref ("uf5")));
138 static ftype *pf5a USED = &Wf5a;
139 extern ftype uf5;
140 static ftype *pf5 USED = &uf5;
142 static ftype Wf6a __attribute__((weakref ("wf6")));
143 static ftype *pf6a USED = &Wf6a;
144 extern ftype wf6;
146 static ftype Wf7a __attribute__((weakref ("uf7")));
147 static ftype* USED ff7 (void) {
148 return &Wf7a;
150 extern ftype uf7;
151 static ftype* USED ff7a (void) {
152 return &uf7;
155 extern ftype uf8;
156 static ftype* USED ff8a (void) {
157 return &uf8;
159 static ftype Wf8a __attribute__((weakref ("uf8")));
160 static ftype* USED ff8 (void) {
161 return &Wf8a;
164 extern ftype wf9 __attribute__((weak));
165 static ftype Wf9a __attribute__((weakref ("wf9")));
166 static ftype *pf9a USED = &Wf9a;
168 static ftype Wf10a __attribute__((weakref ("Wf10b")));
169 static ftype Wf10b __attribute__((weakref ("Wf10c")));
170 static ftype Wf10c __attribute__((weakref ("Wf10d")));
171 static ftype Wf10d __attribute__((weakref ("wf10")));
172 extern ftype wf10;
174 extern ftype wf11;
175 static ftype Wf11d __attribute__((weakref ("wf11")));
176 static ftype Wf11c __attribute__((weakref ("Wf11d")));
177 static ftype Wf11b __attribute__((weakref ("Wf11c")));
178 static ftype Wf11a __attribute__((weakref ("Wf11b")));
180 static ftype Wf12 __attribute__((weakref ("wf12")));
181 extern ftype wf12 __attribute__((weak));
183 static ftype Wf13 __attribute__((weakref ("wf13")));
184 extern ftype wf13 __attribute__((weak));
186 static ftype Wf14a __attribute__((weakref ("wf14")));
187 static ftype Wf14b __attribute__((weakref ("wf14")));
188 extern ftype wf14 __attribute__((weak));
190 #ifndef __APPLE__
191 #define chk(p) do { if (!p) abort (); } while (0)
192 #else
193 #define chk(p) /* */
194 #endif
196 int main () {
197 chk (!pv1a);
198 chk (pv2a);
199 #if !defined(SOLARIS_X86_AS)
200 chk (pv3a);
201 #endif
202 chk (pv4a);
203 chk (pv4);
204 chk (pv5a);
205 chk (pv5);
206 chk (!pv6a);
207 chk (fv7 ());
208 chk (fv7a ());
209 chk (fv8 ());
210 chk (fv8a ());
211 chk (!pv9a);
212 chk (!&Wv10a);
213 chk (!&Wv11a);
214 chk (!&Wv12);
215 chk (!&wv12);
216 chk (!&wv13);
217 chk (!&Wv14a);
219 chk (!pf1a);
220 chk (!pf1c);
221 chk (pf2a);
222 chk (pf3a);
223 chk (pf4a);
224 chk (pf4);
225 chk (pf5a);
226 chk (pf5);
227 chk (!pf6a);
228 chk (ff7 ());
229 chk (ff7a ());
230 chk (ff8 ());
231 chk (ff8a ());
232 chk (!pf9a);
233 chk (!&Wf10a);
234 chk (!&Wf11a);
235 chk (!&Wf12);
236 chk (!&wf12);
237 chk (!&wf13);
238 chk (!&Wf14a);
240 exit (0);