blob: 46031173cd2dc13b8eca6c65a486a278d8d643f0 [file] [log] [blame]
Nico Rieck60478662014-02-22 19:47:30 +00001// RUN: %clang_cc1 -triple i686-win32 -fsyntax-only -verify -std=c99 %s
2// RUN: %clang_cc1 -triple x86_64-win32 -fsyntax-only -verify -std=c11 %s
3// RUN: %clang_cc1 -triple i686-mingw32 -fsyntax-only -verify -std=c11 %s
4// RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -verify -std=c99 %s
5
6// Invalid usage.
7__declspec(dllimport) typedef int typedef1; // expected-warning{{'dllimport' attribute only applies to variables and functions}}
8typedef __declspec(dllimport) int typedef2; // expected-warning{{'dllimport' attribute only applies to variables and functions}}
9typedef int __declspec(dllimport) typedef3; // expected-warning{{'dllimport' attribute only applies to variables and functions}}
10typedef __declspec(dllimport) void (*FunTy)(); // expected-warning{{'dllimport' attribute only applies to variables and functions}}
11enum __declspec(dllimport) Enum { EnumVal }; // expected-warning{{'dllimport' attribute only applies to variables and functions}}
12struct __declspec(dllimport) Record {}; // expected-warning{{'dllimport' attribute only applies to variables and functions}}
13
14
15
16//===----------------------------------------------------------------------===//
17// Globals
18//===----------------------------------------------------------------------===//
19
20// Import declaration.
21__declspec(dllimport) extern int ExternGlobalDecl;
22
Nico Rieck8e9791f2014-02-26 21:27:13 +000023// dllimport implies a declaration.
24__declspec(dllimport) int GlobalDecl;
Nico Riecke84f8db2014-03-23 21:24:01 +000025int **__attribute__((dllimport))* GlobalDeclChunkAttr;
26int GlobalDeclAttr __attribute__((dllimport));
Nico Rieck60478662014-02-22 19:47:30 +000027
28// Not allowed on definitions.
Nico Rieck8e9791f2014-02-26 21:27:13 +000029__declspec(dllimport) extern int ExternGlobalInit = 1; // expected-error{{definition of dllimport data}}
30__declspec(dllimport) int GlobalInit1 = 1; // expected-error{{definition of dllimport data}}
31int __declspec(dllimport) GlobalInit2 = 1; // expected-error{{definition of dllimport data}}
Nico Rieck60478662014-02-22 19:47:30 +000032
33// Declare, then reject definition.
Nico Rieck82f0b062014-03-31 14:56:15 +000034__declspec(dllimport) extern int ExternGlobalDeclInit; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
35int ExternGlobalDeclInit = 1; // expected-warning{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
Nico Rieck60478662014-02-22 19:47:30 +000036
Nico Rieck82f0b062014-03-31 14:56:15 +000037__declspec(dllimport) int GlobalDeclInit; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
38int GlobalDeclInit = 1; // expected-warning{{'GlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
Nico Riecke84f8db2014-03-23 21:24:01 +000039
Nico Rieck82f0b062014-03-31 14:56:15 +000040int *__attribute__((dllimport)) GlobalDeclChunkAttrInit; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
41int *GlobalDeclChunkAttrInit = 0; // expected-warning{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
Nico Riecke84f8db2014-03-23 21:24:01 +000042
Nico Rieck82f0b062014-03-31 14:56:15 +000043int GlobalDeclAttrInit __attribute__((dllimport)); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
44int GlobalDeclAttrInit = 1; // expected-warning{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
Nico Riecke84f8db2014-03-23 21:24:01 +000045
Nico Rieck60478662014-02-22 19:47:30 +000046// Redeclarations
47__declspec(dllimport) extern int GlobalRedecl1;
48__declspec(dllimport) extern int GlobalRedecl1;
49
Nico Riecke84f8db2014-03-23 21:24:01 +000050__declspec(dllimport) int GlobalRedecl2a;
51__declspec(dllimport) int GlobalRedecl2a;
52
53int *__attribute__((dllimport)) GlobalRedecl2b;
54int *__attribute__((dllimport)) GlobalRedecl2b;
55
56int GlobalRedecl2c __attribute__((dllimport));
57int GlobalRedecl2c __attribute__((dllimport));
58
Nico Rieck82f0b062014-03-31 14:56:15 +000059// NB: MSVC issues a warning and makes GlobalRedecl3 dllexport. We follow GCC
60// and drop the dllimport with a warning.
61__declspec(dllimport) extern int GlobalRedecl3; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
62 extern int GlobalRedecl3; // expected-warning{{'GlobalRedecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
63
64 extern int GlobalRedecl4; // expected-note{{previous declaration is here}}
65__declspec(dllimport) extern int GlobalRedecl4; // expected-error{{redeclaration of 'GlobalRedecl4' cannot add 'dllimport' attribute}}
66
Nico Rieck60478662014-02-22 19:47:30 +000067// Import in local scope.
Nico Riecke84f8db2014-03-23 21:24:01 +000068__declspec(dllimport) float LocalRedecl1; // expected-note{{previous definition is here}}
69__declspec(dllimport) float LocalRedecl2; // expected-note{{previous definition is here}}
70__declspec(dllimport) float LocalRedecl3; // expected-note{{previous definition is here}}
Nico Rieck60478662014-02-22 19:47:30 +000071void functionScope() {
Nico Riecke84f8db2014-03-23 21:24:01 +000072 __declspec(dllimport) int LocalRedecl1; // expected-error{{redefinition of 'LocalRedecl1' with a different type: 'int' vs 'float'}}
73 int *__attribute__((dllimport)) LocalRedecl2; // expected-error{{redefinition of 'LocalRedecl2' with a different type: 'int *' vs 'float'}}
74 int LocalRedecl3 __attribute__((dllimport)); // expected-error{{redefinition of 'LocalRedecl3' with a different type: 'int' vs 'float'}}
75
Nico Rieck8e9791f2014-02-26 21:27:13 +000076 __declspec(dllimport) int LocalVarDecl;
77 __declspec(dllimport) int LocalVarDef = 1; // expected-error{{definition of dllimport data}}
Nico Rieck60478662014-02-22 19:47:30 +000078 __declspec(dllimport) extern int ExternLocalVarDecl;
Nico Rieck8e9791f2014-02-26 21:27:13 +000079 __declspec(dllimport) extern int ExternLocalVarDef = 1; // expected-error{{definition of dllimport data}}
Nico Rieck60478662014-02-22 19:47:30 +000080}
81
82
83
84//===----------------------------------------------------------------------===//
85// Functions
86//===----------------------------------------------------------------------===//
87
88// Import function declaration. Check different placements.
89__attribute__((dllimport)) void decl1A(); // Sanity check with __attribute__
90__declspec(dllimport) void decl1B();
91
92void __attribute__((dllimport)) decl2A();
93void __declspec(dllimport) decl2B();
94
95// Not allowed on function definitions.
96__declspec(dllimport) void def() {} // expected-error{{'dllimport' attribute can be applied only to symbol declaration}}
97
98// Import inline function.
99__declspec(dllimport) inline void inlineFunc1() {} // expected-warning{{'dllimport' attribute ignored}}
100inline void __attribute__((dllimport)) inlineFunc2() {} // expected-warning{{'dllimport' attribute ignored}}
101
102// Redeclarations
103__declspec(dllimport) void redecl1();
104__declspec(dllimport) void redecl1();
105
Nico Rieck82f0b062014-03-31 14:56:15 +0000106// NB: MSVC issues a warning and makes redecl2/redecl3 dllexport. We follow GCC
107// and drop the dllimport with a warning.
108__declspec(dllimport) void redecl2(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
109 void redecl2(); // expected-warning{{'redecl2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
110
111__declspec(dllimport) void redecl3(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
Nico Rieck60478662014-02-22 19:47:30 +0000112 void redecl3() {} // expected-warning{{'redecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
Nico Rieck82f0b062014-03-31 14:56:15 +0000113
114 void redecl4(); // expected-note{{previous declaration is here}}
115__declspec(dllimport) void redecl4(); // expected-error{{redeclaration of 'redecl4' cannot add 'dllimport' attribute}}