annotate clang/test/Sema/dllexport.c @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents c4bab56944e8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -triple i686-win32 -fsyntax-only -fms-extensions -verify -std=c99 %s
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -triple x86_64-win32 -fsyntax-only -fms-extensions -verify -std=c11 %s
anatofuz
parents:
diff changeset
3 // RUN: %clang_cc1 -triple i686-mingw32 -fsyntax-only -fms-extensions -verify -std=c11 %s
anatofuz
parents:
diff changeset
4 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c99 %s
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 // Invalid usage.
anatofuz
parents:
diff changeset
7 __declspec(dllexport) typedef int typedef1;
anatofuz
parents:
diff changeset
8 // expected-warning@-1{{'dllexport' attribute only applies to functions, variables, classes, and Objective-C interfaces}}
anatofuz
parents:
diff changeset
9 typedef __declspec(dllexport) int typedef2;
anatofuz
parents:
diff changeset
10 // expected-warning@-1{{'dllexport' attribute only applies to}}
anatofuz
parents:
diff changeset
11 typedef int __declspec(dllexport) typedef3;
anatofuz
parents:
diff changeset
12 // expected-warning@-1{{'dllexport' attribute only applies to}}
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
13 typedef __declspec(dllexport) void (*FunTy)(void);
150
anatofuz
parents:
diff changeset
14 // expected-warning@-1{{'dllexport' attribute only applies to}}
anatofuz
parents:
diff changeset
15 enum __declspec(dllexport) Enum { EnumVal };
anatofuz
parents:
diff changeset
16 // expected-warning@-1{{'dllexport' attribute only applies to}}
anatofuz
parents:
diff changeset
17 struct __declspec(dllexport) Record {};
anatofuz
parents:
diff changeset
18 // expected-warning@-1{{'dllexport' attribute only applies to}}
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
23 // Globals
anatofuz
parents:
diff changeset
24 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 // Export declaration.
anatofuz
parents:
diff changeset
27 __declspec(dllexport) extern int ExternGlobalDecl;
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 // dllexport implies a definition.
anatofuz
parents:
diff changeset
30 __declspec(dllexport) int GlobalDef;
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 // Export definition.
anatofuz
parents:
diff changeset
33 __declspec(dllexport) int GlobalInit1 = 1;
anatofuz
parents:
diff changeset
34 int __declspec(dllexport) GlobalInit2 = 1;
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 // Declare, then export definition.
anatofuz
parents:
diff changeset
37 __declspec(dllexport) extern int GlobalDeclInit;
anatofuz
parents:
diff changeset
38 int GlobalDeclInit = 1;
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 // Redeclarations
anatofuz
parents:
diff changeset
41 __declspec(dllexport) extern int GlobalRedecl1;
anatofuz
parents:
diff changeset
42 __declspec(dllexport) int GlobalRedecl1;
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 __declspec(dllexport) extern int GlobalRedecl2;
anatofuz
parents:
diff changeset
45 int GlobalRedecl2;
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 extern int GlobalRedecl3; // expected-note{{previous declaration is here}}
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
48 int useGlobalRedecl3(void) { return GlobalRedecl3; }
150
anatofuz
parents:
diff changeset
49 __declspec(dllexport) extern int GlobalRedecl3; // expected-error{{redeclaration of 'GlobalRedecl3' cannot add 'dllexport' attribute}}
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 extern int GlobalRedecl4; // expected-note{{previous declaration is here}}
anatofuz
parents:
diff changeset
52 __declspec(dllexport) extern int GlobalRedecl4; // expected-warning{{redeclaration of 'GlobalRedecl4' should not add 'dllexport' attribute}}
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 // External linkage is required.
anatofuz
parents:
diff changeset
56 __declspec(dllexport) static int StaticGlobal; // expected-error{{'StaticGlobal' must have external linkage when declared 'dllexport'}}
anatofuz
parents:
diff changeset
57
anatofuz
parents:
diff changeset
58 // Thread local variables are invalid.
anatofuz
parents:
diff changeset
59 __declspec(dllexport) __thread int ThreadLocalGlobal; // expected-error{{'ThreadLocalGlobal' cannot be thread local when declared 'dllexport'}}
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61 // Export in local scope.
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
62 void functionScope(void) {
150
anatofuz
parents:
diff changeset
63 __declspec(dllexport) int LocalVarDecl; // expected-error{{'LocalVarDecl' must have external linkage when declared 'dllexport'}}
anatofuz
parents:
diff changeset
64 __declspec(dllexport) int LocalVarDef = 1; // expected-error{{'LocalVarDef' must have external linkage when declared 'dllexport'}}
anatofuz
parents:
diff changeset
65 __declspec(dllexport) extern int ExternLocalVarDecl;
anatofuz
parents:
diff changeset
66 __declspec(dllexport) static int StaticLocalVar; // expected-error{{'StaticLocalVar' must have external linkage when declared 'dllexport'}}
anatofuz
parents:
diff changeset
67 }
anatofuz
parents:
diff changeset
68
anatofuz
parents:
diff changeset
69
anatofuz
parents:
diff changeset
70
anatofuz
parents:
diff changeset
71 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
72 // Functions
anatofuz
parents:
diff changeset
73 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
74
anatofuz
parents:
diff changeset
75 // Export function declaration. Check different placements.
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
76 __attribute__((dllexport)) void decl1A(void); // Basic check with __attribute__
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
77 __declspec(dllexport) void decl1B(void);
150
anatofuz
parents:
diff changeset
78
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
79 void __attribute__((dllexport)) decl2A(void);
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
80 void __declspec(dllexport) decl2B(void);
150
anatofuz
parents:
diff changeset
81
anatofuz
parents:
diff changeset
82 // Export function definition.
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
83 __declspec(dllexport) void def(void) {}
150
anatofuz
parents:
diff changeset
84
anatofuz
parents:
diff changeset
85 // Export inline function.
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
86 __declspec(dllexport) inline void inlineFunc1(void) {}
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
87 extern void inlineFunc1(void);
150
anatofuz
parents:
diff changeset
88
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
89 inline void __attribute__((dllexport)) inlineFunc2(void) {}
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
90 extern void inlineFunc2(void);
150
anatofuz
parents:
diff changeset
91
anatofuz
parents:
diff changeset
92 // Redeclarations
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
93 __declspec(dllexport) void redecl1(void);
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
94 __declspec(dllexport) void redecl1(void);
150
anatofuz
parents:
diff changeset
95
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
96 __declspec(dllexport) void redecl2(void);
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
97 void redecl2(void);
150
anatofuz
parents:
diff changeset
98
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
99 __declspec(dllexport) void redecl3(void);
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
100 void redecl3(void) {}
150
anatofuz
parents:
diff changeset
101
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
102 void redecl4(void); // expected-note{{previous declaration is here}}
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
103 void useRedecl4(void) { redecl4(); }
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
104 __declspec(dllexport) void redecl4(void); // expected-error{{redeclaration of 'redecl4' cannot add 'dllexport' attribute}}
150
anatofuz
parents:
diff changeset
105
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
106 void redecl5(void); // expected-note{{previous declaration is here}}
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
107 void useRedecl5(void) { redecl5(); }
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
108 __declspec(dllexport) inline void redecl5(void) {} // expected-error{{redeclaration of 'redecl5' cannot add 'dllexport' attribute}}
150
anatofuz
parents:
diff changeset
109
anatofuz
parents:
diff changeset
110 // Allow with a warning if the decl hasn't been used yet.
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
111 void redecl6(void); // expected-note{{previous declaration is here}}
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
112 __declspec(dllexport) void redecl6(void); // expected-warning{{redeclaration of 'redecl6' should not add 'dllexport' attribute}}
150
anatofuz
parents:
diff changeset
113
anatofuz
parents:
diff changeset
114
anatofuz
parents:
diff changeset
115 // External linkage is required.
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
116 __declspec(dllexport) static int staticFunc(void); // expected-error{{'staticFunc' must have external linkage when declared 'dllexport'}}
150
anatofuz
parents:
diff changeset
117
anatofuz
parents:
diff changeset
118 // Static locals don't count as having external linkage.
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
119 void staticLocalFunc(void) {
150
anatofuz
parents:
diff changeset
120 __declspec(dllexport) static int staticLocal; // expected-error{{'staticLocal' must have external linkage when declared 'dllexport'}}
anatofuz
parents:
diff changeset
121 }
anatofuz
parents:
diff changeset
122
anatofuz
parents:
diff changeset
123
anatofuz
parents:
diff changeset
124
anatofuz
parents:
diff changeset
125 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
126 // Precedence
anatofuz
parents:
diff changeset
127 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
128
anatofuz
parents:
diff changeset
129 // dllexport takes precedence over dllimport if both are specified.
anatofuz
parents:
diff changeset
130 __attribute__((dllimport, dllexport)) extern int PrecedenceExternGlobal1A; // expected-warning{{'dllimport' attribute ignored}}
anatofuz
parents:
diff changeset
131 __declspec(dllimport) __declspec(dllexport) extern int PrecedenceExternGlobal1B; // expected-warning{{'dllimport' attribute ignored}}
anatofuz
parents:
diff changeset
132
anatofuz
parents:
diff changeset
133 __attribute__((dllexport, dllimport)) extern int PrecedenceExternGlobal2A; // expected-warning{{'dllimport' attribute ignored}}
anatofuz
parents:
diff changeset
134 __declspec(dllexport) __declspec(dllimport) extern int PrecedenceExternGlobal2B; // expected-warning{{'dllimport' attribute ignored}}
anatofuz
parents:
diff changeset
135
anatofuz
parents:
diff changeset
136 __attribute__((dllimport, dllexport)) int PrecedenceGlobal1A; // expected-warning{{'dllimport' attribute ignored}}
anatofuz
parents:
diff changeset
137 __declspec(dllimport) __declspec(dllexport) int PrecedenceGlobal1B; // expected-warning{{'dllimport' attribute ignored}}
anatofuz
parents:
diff changeset
138
anatofuz
parents:
diff changeset
139 __attribute__((dllexport, dllimport)) int PrecedenceGlobal2A; // expected-warning{{'dllimport' attribute ignored}}
anatofuz
parents:
diff changeset
140 __declspec(dllexport) __declspec(dllimport) int PrecedenceGlobal2B; // expected-warning{{'dllimport' attribute ignored}}
anatofuz
parents:
diff changeset
141
anatofuz
parents:
diff changeset
142 __declspec(dllexport) extern int PrecedenceExternGlobalRedecl1;
anatofuz
parents:
diff changeset
143 __declspec(dllimport) extern int PrecedenceExternGlobalRedecl1; // expected-warning{{'dllimport' attribute ignored}}
anatofuz
parents:
diff changeset
144
anatofuz
parents:
diff changeset
145 __declspec(dllimport) extern int PrecedenceExternGlobalRedecl2; // expected-warning{{'dllimport' attribute ignored}}
anatofuz
parents:
diff changeset
146 __declspec(dllexport) extern int PrecedenceExternGlobalRedecl2;
anatofuz
parents:
diff changeset
147
anatofuz
parents:
diff changeset
148 __declspec(dllexport) extern int PrecedenceGlobalRedecl1;
anatofuz
parents:
diff changeset
149 __declspec(dllimport) int PrecedenceGlobalRedecl1; // expected-warning{{'dllimport' attribute ignored}}
anatofuz
parents:
diff changeset
150
anatofuz
parents:
diff changeset
151 __declspec(dllimport) extern int PrecedenceGlobalRedecl2; // expected-warning{{'dllimport' attribute ignored}}
anatofuz
parents:
diff changeset
152 __declspec(dllexport) int PrecedenceGlobalRedecl2;
anatofuz
parents:
diff changeset
153
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
154 void __attribute__((dllimport, dllexport)) precedence1A(void) {} // expected-warning{{'dllimport' attribute ignored}}
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
155 void __declspec(dllimport) __declspec(dllexport) precedence1B(void) {} // expected-warning{{'dllimport' attribute ignored}}
150
anatofuz
parents:
diff changeset
156
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
157 void __attribute__((dllexport, dllimport)) precedence2A(void) {} // expected-warning{{'dllimport' attribute ignored}}
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
158 void __declspec(dllexport) __declspec(dllimport) precedence2B(void) {} // expected-warning{{'dllimport' attribute ignored}}
150
anatofuz
parents:
diff changeset
159
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
160 void __declspec(dllimport) precedenceRedecl1(void); // expected-warning{{'dllimport' attribute ignored}}
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
161 void __declspec(dllexport) precedenceRedecl1(void) {}
150
anatofuz
parents:
diff changeset
162
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
163 void __declspec(dllexport) precedenceRedecl2(void);
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
164 void __declspec(dllimport) precedenceRedecl2(void) {} // expected-warning{{'dllimport' attribute ignored}}