Fix ICE in substring-handling building 502.gcc_r (PR 87562)
[official-gcc.git] / gcc / testsuite / gcc.dg / attr-weakref-1.c
blob9e14b605be0c3464ad7906e8bdac7ca0e31e4f6e
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 // { dg-additional-sources "attr-weakref-1a.c" }
19 // Copyright 2005 Free Software Foundation, Inc.
20 // Contributed by Alexandre Oliva <aoliva@redhat.com>
22 // Torture test for weakrefs. The first letter of an identifier
23 // indicates whether/how it is defined; the second letter indicates
24 // whether it is part of a variable or function test; the number that
25 // follows is a test counter, and a letter that may follow enables
26 // multiple identifiers within the same test (e.g., multiple weakrefs
27 // or pointers to the same identifier).
29 // Identifiers starting with W are weakrefs; those with p are
30 // pointers; those with g are global definitions; those with l are
31 // local definitions; those with w are expected to be weak undefined
32 // in the symbol table; those with u are expected to be marked as
33 // non-weak undefined in the symbol table.
35 #include <stdlib.h>
37 #define USED __attribute__((used))
39 typedef int vtype;
41 extern vtype wv1;
42 static vtype Wv1a __attribute__((weakref ("wv1")));
43 static vtype *pv1a USED = &Wv1a;
45 vtype gv2;
46 static vtype Wv2a __attribute__((weakref ("gv2")));
47 static vtype *pv2a USED = &Wv2a;
49 static vtype lv3;
50 static vtype Wv3a __attribute__((weakref ("lv3")));
51 static vtype *pv3a USED = &Wv3a;
53 extern vtype uv4;
54 static vtype Wv4a __attribute__((weakref ("uv4")));
55 static vtype *pv4a USED = &Wv4a;
56 static vtype *pv4 USED = &uv4;
58 static vtype Wv5a __attribute__((weakref ("uv5")));
59 static vtype *pv5a USED = &Wv5a;
60 extern vtype uv5;
61 static vtype *pv5 USED = &uv5;
63 static vtype Wv6a __attribute__((weakref ("wv6")));
64 static vtype *pv6a USED = &Wv6a;
65 extern vtype wv6;
67 static vtype Wv7a __attribute__((weakref ("uv7")));
68 static vtype* USED fv7 (void) {
69 return &Wv7a;
71 extern vtype uv7;
72 static vtype* USED fv7a (void) {
73 return &uv7;
76 extern vtype uv8;
77 static vtype* USED fv8a (void) {
78 return &uv8;
80 static vtype Wv8a __attribute__((weakref ("uv8")));
81 static vtype* USED fv8 (void) {
82 return &Wv8a;
85 extern vtype wv9 __attribute__((weak));
86 static vtype Wv9a __attribute__((weakref ("wv9")));
87 static vtype *pv9a USED = &Wv9a;
89 static vtype Wv10a __attribute__((weakref ("Wv10b")));
90 static vtype Wv10b __attribute__((weakref ("Wv10c")));
91 static vtype Wv10c __attribute__((weakref ("Wv10d")));
92 static vtype Wv10d __attribute__((weakref ("wv10")));
93 extern vtype wv10;
95 extern vtype wv11;
96 static vtype Wv11d __attribute__((weakref ("wv11")));
97 static vtype Wv11c __attribute__((weakref ("Wv11d")));
98 static vtype Wv11b __attribute__((weakref ("Wv11c")));
99 static vtype Wv11a __attribute__((weakref ("Wv11b")));
101 static vtype Wv12 __attribute__((weakref ("wv12")));
102 extern vtype wv12 __attribute__((weak));
104 static vtype Wv13 __attribute__((weakref ("wv13")));
105 extern vtype wv13 __attribute__((weak));
107 static vtype Wv14a __attribute__((weakref ("wv14")));
108 static vtype Wv14b __attribute__((weakref ("wv14")));
109 extern vtype wv14 __attribute__((weak));
111 typedef void ftype(void);
113 extern ftype wf1;
114 static ftype Wf1a __attribute__((weakref ("wf1")));
115 static ftype *pf1a USED = &Wf1a;
116 static ftype Wf1c __attribute__((weakref));
117 extern ftype Wf1c __attribute__((alias ("wf1")));
118 static ftype *pf1c USED = &Wf1c;
120 void gf2(void) {}
121 static ftype Wf2a __attribute__((weakref ("gf2")));
122 static ftype *pf2a USED = &Wf2a;
124 static void lf3(void) {}
125 static ftype Wf3a __attribute__((weakref ("lf3")));
126 static ftype *pf3a USED = &Wf3a;
128 extern ftype uf4;
129 static ftype Wf4a __attribute__((weakref ("uf4")));
130 static ftype *pf4a USED = &Wf4a;
131 static ftype *pf4 USED = &uf4;
133 static ftype Wf5a __attribute__((weakref ("uf5")));
134 static ftype *pf5a USED = &Wf5a;
135 extern ftype uf5;
136 static ftype *pf5 USED = &uf5;
138 static ftype Wf6a __attribute__((weakref ("wf6")));
139 static ftype *pf6a USED = &Wf6a;
140 extern ftype wf6;
142 static ftype Wf7a __attribute__((weakref ("uf7")));
143 static ftype* USED ff7 (void) {
144 return &Wf7a;
146 extern ftype uf7;
147 static ftype* USED ff7a (void) {
148 return &uf7;
151 extern ftype uf8;
152 static ftype* USED ff8a (void) {
153 return &uf8;
155 static ftype Wf8a __attribute__((weakref ("uf8")));
156 static ftype* USED ff8 (void) {
157 return &Wf8a;
160 extern ftype wf9 __attribute__((weak));
161 static ftype Wf9a __attribute__((weakref ("wf9")));
162 static ftype *pf9a USED = &Wf9a;
164 static ftype Wf10a __attribute__((weakref ("Wf10b")));
165 static ftype Wf10b __attribute__((weakref ("Wf10c")));
166 static ftype Wf10c __attribute__((weakref ("Wf10d")));
167 static ftype Wf10d __attribute__((weakref ("wf10")));
168 extern ftype wf10;
170 extern ftype wf11;
171 static ftype Wf11d __attribute__((weakref ("wf11")));
172 static ftype Wf11c __attribute__((weakref ("Wf11d")));
173 static ftype Wf11b __attribute__((weakref ("Wf11c")));
174 static ftype Wf11a __attribute__((weakref ("Wf11b")));
176 static ftype Wf12 __attribute__((weakref ("wf12")));
177 extern ftype wf12 __attribute__((weak));
179 static ftype Wf13 __attribute__((weakref ("wf13")));
180 extern ftype wf13 __attribute__((weak));
182 static ftype Wf14a __attribute__((weakref ("wf14")));
183 static ftype Wf14b __attribute__((weakref ("wf14")));
184 extern ftype wf14 __attribute__((weak));
186 #ifndef __APPLE__
187 #define chk(p) do { if (!p) abort (); } while (0)
188 #else
189 #define chk(p) /* */
190 #endif
192 int main () {
193 chk (!pv1a);
194 chk (pv2a);
195 chk (pv3a);
196 chk (pv4a);
197 chk (pv4);
198 chk (pv5a);
199 chk (pv5);
200 chk (!pv6a);
201 chk (fv7 ());
202 chk (fv7a ());
203 chk (fv8 ());
204 chk (fv8a ());
205 chk (!pv9a);
206 chk (!&Wv10a);
207 chk (!&Wv11a);
208 chk (!&Wv12);
209 chk (!&wv12);
210 chk (!&wv13);
211 chk (!&Wv14a);
213 chk (!pf1a);
214 chk (!pf1c);
215 chk (pf2a);
216 chk (pf3a);
217 chk (pf4a);
218 chk (pf4);
219 chk (pf5a);
220 chk (pf5);
221 chk (!pf6a);
222 chk (ff7 ());
223 chk (ff7a ());
224 chk (ff8 ());
225 chk (ff8a ());
226 chk (!pf9a);
227 chk (!&Wf10a);
228 chk (!&Wf11a);
229 chk (!&Wf12);
230 chk (!&wf12);
231 chk (!&wf13);
232 chk (!&Wf14a);
234 exit (0);