annotate clang/test/Sema/dllimport.c @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1 // RUN: %clang_cc1 -triple i686-win32 -fsyntax-only -fms-extensions -verify -std=c99 -DMS %s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
2 // RUN: %clang_cc1 -triple x86_64-win32 -fsyntax-only -fms-extensions -verify -std=c11 -DMS %s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
3 // RUN: %clang_cc1 -triple i686-mingw32 -fsyntax-only -fms-extensions -verify -std=c11 -DGNU %s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
4 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c99 -DGNU %s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
5 // RUN: %clang_cc1 -triple aarch64-win32 -fsyntax-only -fms-extensions -verify -std=c99 -DMS %s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
6 // RUN: %clang_cc1 -triple i686-windows-itanium -fsyntax-only -fms-extensions -verify -std=c99 -DWI %s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
7 // RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c11 -DWI %s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
8 // RUN: %clang_cc1 -triple x86_64-scei-ps4 -fsyntax-only -fms-extensions -verify -std=c11 -DWI %s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
9 // RUN: %clang_cc1 -triple x86_64-scei-ps4 -fsyntax-only -fms-extensions -verify -std=c99 -DWI %s
150
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 // Invalid usage.
anatofuz
parents:
diff changeset
12 __declspec(dllimport) typedef int typedef1;
anatofuz
parents:
diff changeset
13 // expected-warning@-1{{'dllimport' attribute only applies to functions, variables, classes, and Objective-C interfaces}}
anatofuz
parents:
diff changeset
14 typedef __declspec(dllimport) int typedef2;
anatofuz
parents:
diff changeset
15 // expected-warning@-1{{'dllimport' attribute only applies to}}
anatofuz
parents:
diff changeset
16 typedef int __declspec(dllimport) typedef3;
anatofuz
parents:
diff changeset
17 // expected-warning@-1{{'dllimport' attribute only applies to}}
anatofuz
parents:
diff changeset
18 typedef __declspec(dllimport) void (*FunTy)();
anatofuz
parents:
diff changeset
19 // expected-warning@-1{{'dllimport' attribute only applies to}}
anatofuz
parents:
diff changeset
20 enum __declspec(dllimport) Enum { EnumVal };
anatofuz
parents:
diff changeset
21 // expected-warning@-1{{'dllimport' attribute only applies to}}
anatofuz
parents:
diff changeset
22 struct __declspec(dllimport) Record {};
anatofuz
parents:
diff changeset
23 // expected-warning@-1{{'dllimport' attribute only applies to}}
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26
anatofuz
parents:
diff changeset
27 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
28 // Globals
anatofuz
parents:
diff changeset
29 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 // Import declaration.
anatofuz
parents:
diff changeset
32 __declspec(dllimport) extern int ExternGlobalDecl;
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 // dllimport implies a declaration.
anatofuz
parents:
diff changeset
35 __declspec(dllimport) int GlobalDecl;
anatofuz
parents:
diff changeset
36 int **__attribute__((dllimport))* GlobalDeclChunkAttr;
anatofuz
parents:
diff changeset
37 int GlobalDeclAttr __attribute__((dllimport));
anatofuz
parents:
diff changeset
38
anatofuz
parents:
diff changeset
39 // Address of variables can't be used for initialization in C language modes.
anatofuz
parents:
diff changeset
40 int *VarForInit = &GlobalDecl; // expected-error{{initializer element is not a compile-time constant}}
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 // Not allowed on definitions.
anatofuz
parents:
diff changeset
43 __declspec(dllimport) extern int ExternGlobalInit = 1; // expected-error{{definition of dllimport data}}
anatofuz
parents:
diff changeset
44 __declspec(dllimport) int GlobalInit1 = 1; // expected-error{{definition of dllimport data}}
anatofuz
parents:
diff changeset
45 int __declspec(dllimport) GlobalInit2 = 1; // expected-error{{definition of dllimport data}}
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 // Declare, then reject definition.
anatofuz
parents:
diff changeset
48 #ifdef GNU
anatofuz
parents:
diff changeset
49 // expected-note@+2{{previous attribute is here}}
anatofuz
parents:
diff changeset
50 #endif
anatofuz
parents:
diff changeset
51 __declspec(dllimport) extern int ExternGlobalDeclInit; // expected-note{{previous declaration is here}}
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
52 #if defined(MS) || defined(WI)
150
anatofuz
parents:
diff changeset
53 // expected-warning@+4{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
anatofuz
parents:
diff changeset
54 #else
anatofuz
parents:
diff changeset
55 // expected-warning@+2{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
anatofuz
parents:
diff changeset
56 #endif
anatofuz
parents:
diff changeset
57 int ExternGlobalDeclInit = 1;
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59 #ifdef GNU
anatofuz
parents:
diff changeset
60 // expected-note@+2{{previous attribute is here}}
anatofuz
parents:
diff changeset
61 #endif
anatofuz
parents:
diff changeset
62 __declspec(dllimport) int GlobalDeclInit; // expected-note{{previous declaration is here}}
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
63 #if defined(MS) || defined(WI)
150
anatofuz
parents:
diff changeset
64 // expected-warning@+4{{'GlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
anatofuz
parents:
diff changeset
65 #else
anatofuz
parents:
diff changeset
66 // expected-warning@+2{{'GlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
anatofuz
parents:
diff changeset
67 #endif
anatofuz
parents:
diff changeset
68 int GlobalDeclInit = 1;
anatofuz
parents:
diff changeset
69
anatofuz
parents:
diff changeset
70 #ifdef GNU
anatofuz
parents:
diff changeset
71 // expected-note@+2{{previous attribute is here}}
anatofuz
parents:
diff changeset
72 #endif
anatofuz
parents:
diff changeset
73 int *__attribute__((dllimport)) GlobalDeclChunkAttrInit; // expected-note{{previous declaration is here}}
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
74 #if defined(MS) || defined(WI)
150
anatofuz
parents:
diff changeset
75 // expected-warning@+4{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
anatofuz
parents:
diff changeset
76 #else
anatofuz
parents:
diff changeset
77 // expected-warning@+2{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
anatofuz
parents:
diff changeset
78 #endif
anatofuz
parents:
diff changeset
79 int *GlobalDeclChunkAttrInit = 0;
anatofuz
parents:
diff changeset
80
anatofuz
parents:
diff changeset
81 #ifdef GNU
anatofuz
parents:
diff changeset
82 // expected-note@+2{{previous attribute is here}}
anatofuz
parents:
diff changeset
83 #endif
anatofuz
parents:
diff changeset
84 int GlobalDeclAttrInit __attribute__((dllimport)); // expected-note{{previous declaration is here}}
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
85 #if defined(MS) || defined(WI)
150
anatofuz
parents:
diff changeset
86 // expected-warning@+4{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
anatofuz
parents:
diff changeset
87 #else
anatofuz
parents:
diff changeset
88 // expected-warning@+2{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
anatofuz
parents:
diff changeset
89 #endif
anatofuz
parents:
diff changeset
90 int GlobalDeclAttrInit = 1;
anatofuz
parents:
diff changeset
91
anatofuz
parents:
diff changeset
92 // Redeclarations
anatofuz
parents:
diff changeset
93 __declspec(dllimport) extern int GlobalRedecl1;
anatofuz
parents:
diff changeset
94 __declspec(dllimport) extern int GlobalRedecl1;
anatofuz
parents:
diff changeset
95
anatofuz
parents:
diff changeset
96 __declspec(dllimport) int GlobalRedecl2a;
anatofuz
parents:
diff changeset
97 __declspec(dllimport) int GlobalRedecl2a;
anatofuz
parents:
diff changeset
98
anatofuz
parents:
diff changeset
99 int *__attribute__((dllimport)) GlobalRedecl2b;
anatofuz
parents:
diff changeset
100 int *__attribute__((dllimport)) GlobalRedecl2b;
anatofuz
parents:
diff changeset
101
anatofuz
parents:
diff changeset
102 int GlobalRedecl2c __attribute__((dllimport));
anatofuz
parents:
diff changeset
103 int GlobalRedecl2c __attribute__((dllimport));
anatofuz
parents:
diff changeset
104
anatofuz
parents:
diff changeset
105 // We follow GCC and drop the dllimport with a warning.
anatofuz
parents:
diff changeset
106 __declspec(dllimport) extern int GlobalRedecl3; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
anatofuz
parents:
diff changeset
107 extern int GlobalRedecl3; // expected-warning{{'GlobalRedecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
anatofuz
parents:
diff changeset
108
anatofuz
parents:
diff changeset
109 // Adding an attribute on redeclaration.
anatofuz
parents:
diff changeset
110 extern int GlobalRedecl4; // expected-note{{previous declaration is here}}
anatofuz
parents:
diff changeset
111 int useGlobalRedecl4() { return GlobalRedecl4; }
anatofuz
parents:
diff changeset
112 __declspec(dllimport) extern int GlobalRedecl4; // expected-error{{redeclaration of 'GlobalRedecl4' cannot add 'dllimport' attribute}}
anatofuz
parents:
diff changeset
113
anatofuz
parents:
diff changeset
114 // Allow with a warning if the decl hasn't been used yet.
anatofuz
parents:
diff changeset
115 extern int GlobalRedecl5; // expected-note{{previous declaration is here}}
anatofuz
parents:
diff changeset
116 __declspec(dllimport) extern int GlobalRedecl5; // expected-warning{{redeclaration of 'GlobalRedecl5' should not add 'dllimport' attribute}}
anatofuz
parents:
diff changeset
117
anatofuz
parents:
diff changeset
118
anatofuz
parents:
diff changeset
119 // External linkage is required.
anatofuz
parents:
diff changeset
120 __declspec(dllimport) static int StaticGlobal; // expected-error{{'StaticGlobal' must have external linkage when declared 'dllimport'}}
anatofuz
parents:
diff changeset
121
anatofuz
parents:
diff changeset
122 // Thread local variables are invalid.
anatofuz
parents:
diff changeset
123 __declspec(dllimport) __thread int ThreadLocalGlobal; // expected-error{{'ThreadLocalGlobal' cannot be thread local when declared 'dllimport'}}
anatofuz
parents:
diff changeset
124
anatofuz
parents:
diff changeset
125 // Import in local scope.
anatofuz
parents:
diff changeset
126 __declspec(dllimport) float LocalRedecl1; // expected-note{{previous declaration is here}}
anatofuz
parents:
diff changeset
127 __declspec(dllimport) float LocalRedecl2; // expected-note{{previous declaration is here}}
anatofuz
parents:
diff changeset
128 __declspec(dllimport) float LocalRedecl3; // expected-note{{previous declaration is here}}
anatofuz
parents:
diff changeset
129 __declspec(dllimport) float LocalRedecl4;
anatofuz
parents:
diff changeset
130 void functionScope() {
anatofuz
parents:
diff changeset
131 __declspec(dllimport) int LocalRedecl1; // expected-error{{redeclaration of 'LocalRedecl1' with a different type: 'int' vs 'float'}}
anatofuz
parents:
diff changeset
132 int *__attribute__((dllimport)) LocalRedecl2; // expected-error{{redeclaration of 'LocalRedecl2' with a different type: 'int *' vs 'float'}}
anatofuz
parents:
diff changeset
133 int LocalRedecl3 __attribute__((dllimport)); // expected-error{{redeclaration of 'LocalRedecl3' with a different type: 'int' vs 'float'}}
anatofuz
parents:
diff changeset
134
anatofuz
parents:
diff changeset
135 __declspec(dllimport) int LocalVarDecl;
anatofuz
parents:
diff changeset
136 __declspec(dllimport) int LocalVarDef = 1; // expected-error{{definition of dllimport data}}
anatofuz
parents:
diff changeset
137 __declspec(dllimport) extern int ExternLocalVarDecl;
anatofuz
parents:
diff changeset
138 __declspec(dllimport) extern int ExternLocalVarDef = 1; // expected-error{{definition of dllimport data}}
anatofuz
parents:
diff changeset
139 __declspec(dllimport) static int StaticLocalVar; // expected-error{{'StaticLocalVar' must have external linkage when declared 'dllimport'}}
anatofuz
parents:
diff changeset
140
anatofuz
parents:
diff changeset
141 // Local extern redeclaration does not drop the attribute.
anatofuz
parents:
diff changeset
142 extern float LocalRedecl4;
anatofuz
parents:
diff changeset
143 }
anatofuz
parents:
diff changeset
144
anatofuz
parents:
diff changeset
145
anatofuz
parents:
diff changeset
146
anatofuz
parents:
diff changeset
147 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
148 // Functions
anatofuz
parents:
diff changeset
149 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
150
anatofuz
parents:
diff changeset
151 // Import function declaration. Check different placements.
anatofuz
parents:
diff changeset
152 __attribute__((dllimport)) void decl1A(); // Sanity check with __attribute__
anatofuz
parents:
diff changeset
153 __declspec(dllimport) void decl1B();
anatofuz
parents:
diff changeset
154
anatofuz
parents:
diff changeset
155 void __attribute__((dllimport)) decl2A();
anatofuz
parents:
diff changeset
156 void __declspec(dllimport) decl2B();
anatofuz
parents:
diff changeset
157
anatofuz
parents:
diff changeset
158 // Address of functions can be used for initialization in C language modes.
anatofuz
parents:
diff changeset
159 // However, the address of the thunk wrapping the function is used instead of
anatofuz
parents:
diff changeset
160 // the address in the import address table.
anatofuz
parents:
diff changeset
161 void (*FunForInit)() = &decl2A;
anatofuz
parents:
diff changeset
162
anatofuz
parents:
diff changeset
163 // Not allowed on function definitions.
anatofuz
parents:
diff changeset
164 __declspec(dllimport) void def() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
anatofuz
parents:
diff changeset
165
anatofuz
parents:
diff changeset
166 // Import inline function.
anatofuz
parents:
diff changeset
167 #ifdef GNU
anatofuz
parents:
diff changeset
168 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
anatofuz
parents:
diff changeset
169 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
anatofuz
parents:
diff changeset
170 #endif
anatofuz
parents:
diff changeset
171 __declspec(dllimport) inline void inlineFunc1() {}
anatofuz
parents:
diff changeset
172 inline void __attribute__((dllimport)) inlineFunc2() {}
anatofuz
parents:
diff changeset
173
anatofuz
parents:
diff changeset
174 // Redeclarations
anatofuz
parents:
diff changeset
175 __declspec(dllimport) void redecl1();
anatofuz
parents:
diff changeset
176 __declspec(dllimport) void redecl1();
anatofuz
parents:
diff changeset
177
anatofuz
parents:
diff changeset
178 __declspec(dllimport) void redecl2(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
anatofuz
parents:
diff changeset
179 void redecl2(); // expected-warning{{'redecl2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
anatofuz
parents:
diff changeset
180
anatofuz
parents:
diff changeset
181 #ifdef GNU
anatofuz
parents:
diff changeset
182 // expected-note@+2{{previous attribute is here}}
anatofuz
parents:
diff changeset
183 #endif
anatofuz
parents:
diff changeset
184 __declspec(dllimport) void redecl3(); // expected-note{{previous declaration is here}}
anatofuz
parents:
diff changeset
185 // NB: Both MSVC and Clang issue a warning and make redecl3 dllexport.
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
186 #if defined(MS) || defined(WI)
150
anatofuz
parents:
diff changeset
187 // expected-warning@+4{{'redecl3' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
anatofuz
parents:
diff changeset
188 #else
anatofuz
parents:
diff changeset
189 // expected-warning@+2{{'redecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
anatofuz
parents:
diff changeset
190 #endif
anatofuz
parents:
diff changeset
191 void redecl3() {}
anatofuz
parents:
diff changeset
192
anatofuz
parents:
diff changeset
193 void redecl4(); // expected-note{{previous declaration is here}}
anatofuz
parents:
diff changeset
194 void useRedecl4() { redecl4(); }
anatofuz
parents:
diff changeset
195 __declspec(dllimport) void redecl4(); // expected-warning{{redeclaration of 'redecl4' should not add 'dllimport' attribute}}
anatofuz
parents:
diff changeset
196
anatofuz
parents:
diff changeset
197 // Allow with a warning if the decl hasn't been used yet.
anatofuz
parents:
diff changeset
198 void redecl5(); // expected-note{{previous declaration is here}}
anatofuz
parents:
diff changeset
199 __declspec(dllimport) void redecl5(); // expected-warning{{redeclaration of 'redecl5' should not add 'dllimport' attribute}}
anatofuz
parents:
diff changeset
200
anatofuz
parents:
diff changeset
201
anatofuz
parents:
diff changeset
202 // Inline redeclarations.
anatofuz
parents:
diff changeset
203 #ifdef GNU
anatofuz
parents:
diff changeset
204 // expected-warning@+3{{'redecl6' redeclared inline; 'dllimport' attribute ignored}}
anatofuz
parents:
diff changeset
205 #endif
anatofuz
parents:
diff changeset
206 __declspec(dllimport) void redecl6();
anatofuz
parents:
diff changeset
207 inline void redecl6() {}
anatofuz
parents:
diff changeset
208
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
209 #if defined(MS) || defined (WI)
150
anatofuz
parents:
diff changeset
210 // expected-note@+5{{previous declaration is here}}
anatofuz
parents:
diff changeset
211 // expected-warning@+5{{redeclaration of 'redecl7' should not add 'dllimport' attribute}}
anatofuz
parents:
diff changeset
212 #else
anatofuz
parents:
diff changeset
213 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
anatofuz
parents:
diff changeset
214 #endif
anatofuz
parents:
diff changeset
215 void redecl7();
anatofuz
parents:
diff changeset
216 __declspec(dllimport) inline void redecl7() {}
anatofuz
parents:
diff changeset
217
anatofuz
parents:
diff changeset
218 // PR31069: Don't crash trying to merge attributes for redeclaration of invalid
anatofuz
parents:
diff changeset
219 // decl.
anatofuz
parents:
diff changeset
220 void __declspec(dllimport) redecl8(unknowntype X); // expected-error{{unknown type name 'unknowntype'}}
anatofuz
parents:
diff changeset
221 void redecl8(unknowntype X) { } // expected-error{{unknown type name 'unknowntype'}}
anatofuz
parents:
diff changeset
222 // PR32021: Similarly, don't crash trying to merge attributes from a valid
anatofuz
parents:
diff changeset
223 // decl to an invalid redeclaration.
anatofuz
parents:
diff changeset
224 void __declspec(dllimport) redecl9(void); // expected-note{{previous declaration is here}}
anatofuz
parents:
diff changeset
225 int redecl9(void) {} // expected-error{{conflicting types for 'redecl9'}}
anatofuz
parents:
diff changeset
226
anatofuz
parents:
diff changeset
227 // External linkage is required.
anatofuz
parents:
diff changeset
228 __declspec(dllimport) static int staticFunc(); // expected-error{{'staticFunc' must have external linkage when declared 'dllimport'}}
anatofuz
parents:
diff changeset
229
anatofuz
parents:
diff changeset
230 // Static locals don't count as having external linkage.
anatofuz
parents:
diff changeset
231 void staticLocalFunc() {
anatofuz
parents:
diff changeset
232 __declspec(dllimport) static int staticLocal; // expected-error{{'staticLocal' must have external linkage when declared 'dllimport'}}
anatofuz
parents:
diff changeset
233 }