2015-05-27 03:44:52 +08:00
|
|
|
// RUN: %clang_cc1 -triple i686-win32 -fsyntax-only -fms-extensions -verify -std=c99 -DMS %s
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-win32 -fsyntax-only -fms-extensions -verify -std=c11 -DMS %s
|
|
|
|
// RUN: %clang_cc1 -triple i686-mingw32 -fsyntax-only -fms-extensions -verify -std=c11 -DGNU %s
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c99 -DGNU %s
|
2014-02-23 03:47:30 +08:00
|
|
|
|
|
|
|
// Invalid usage.
|
2016-07-16 04:41:10 +08:00
|
|
|
__declspec(dllimport) typedef int typedef1;
|
|
|
|
// expected-warning@-1{{'dllimport' attribute only applies to variables and functions}}
|
|
|
|
typedef __declspec(dllimport) int typedef2;
|
|
|
|
// expected-warning@-1{{'dllimport' attribute only applies to variables and functions}}
|
|
|
|
typedef int __declspec(dllimport) typedef3;
|
|
|
|
// expected-warning@-1{{'dllimport' attribute only applies to variables and functions}}
|
|
|
|
typedef __declspec(dllimport) void (*FunTy)();
|
|
|
|
// expected-warning@-1{{'dllimport' attribute only applies to variables and functions}}
|
|
|
|
enum __declspec(dllimport) Enum { EnumVal };
|
|
|
|
// expected-warning@-1{{'dllimport' attribute only applies to variables and functions}}
|
|
|
|
struct __declspec(dllimport) Record {};
|
|
|
|
// expected-warning@-1{{'dllimport' attribute only applies to variables and functions}}
|
2014-02-23 03:47:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Globals
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Import declaration.
|
|
|
|
__declspec(dllimport) extern int ExternGlobalDecl;
|
|
|
|
|
2014-02-27 05:27:13 +08:00
|
|
|
// dllimport implies a declaration.
|
|
|
|
__declspec(dllimport) int GlobalDecl;
|
2014-03-24 05:24:01 +08:00
|
|
|
int **__attribute__((dllimport))* GlobalDeclChunkAttr;
|
|
|
|
int GlobalDeclAttr __attribute__((dllimport));
|
2014-02-23 03:47:30 +08:00
|
|
|
|
2014-06-25 16:15:07 +08:00
|
|
|
// Address of variables can't be used for initialization in C language modes.
|
|
|
|
int *VarForInit = &GlobalDecl; // expected-error{{initializer element is not a compile-time constant}}
|
|
|
|
|
2014-02-23 03:47:30 +08:00
|
|
|
// Not allowed on definitions.
|
2014-02-27 05:27:13 +08:00
|
|
|
__declspec(dllimport) extern int ExternGlobalInit = 1; // expected-error{{definition of dllimport data}}
|
|
|
|
__declspec(dllimport) int GlobalInit1 = 1; // expected-error{{definition of dllimport data}}
|
|
|
|
int __declspec(dllimport) GlobalInit2 = 1; // expected-error{{definition of dllimport data}}
|
2014-02-23 03:47:30 +08:00
|
|
|
|
|
|
|
// Declare, then reject definition.
|
2016-05-25 19:32:42 +08:00
|
|
|
#ifdef GNU
|
|
|
|
// expected-note@+2{{previous attribute is here}}
|
|
|
|
#endif
|
|
|
|
__declspec(dllimport) extern int ExternGlobalDeclInit; // expected-note{{previous declaration is here}}
|
|
|
|
#ifdef MS
|
|
|
|
// expected-warning@+4{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
|
|
|
|
#else
|
|
|
|
// expected-warning@+2{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
|
|
|
|
#endif
|
|
|
|
int ExternGlobalDeclInit = 1;
|
2014-02-23 03:47:30 +08:00
|
|
|
|
2016-05-25 19:32:42 +08:00
|
|
|
#ifdef GNU
|
|
|
|
// expected-note@+2{{previous attribute is here}}
|
|
|
|
#endif
|
|
|
|
__declspec(dllimport) int GlobalDeclInit; // expected-note{{previous declaration is here}}
|
|
|
|
#ifdef MS
|
|
|
|
// expected-warning@+4{{'GlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
|
|
|
|
#else
|
|
|
|
// expected-warning@+2{{'GlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
|
|
|
|
#endif
|
|
|
|
int GlobalDeclInit = 1;
|
2014-03-24 05:24:01 +08:00
|
|
|
|
2016-05-25 19:32:42 +08:00
|
|
|
#ifdef GNU
|
|
|
|
// expected-note@+2{{previous attribute is here}}
|
|
|
|
#endif
|
|
|
|
int *__attribute__((dllimport)) GlobalDeclChunkAttrInit; // expected-note{{previous declaration is here}}
|
|
|
|
#ifdef MS
|
|
|
|
// expected-warning@+4{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
|
|
|
|
#else
|
|
|
|
// expected-warning@+2{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
|
|
|
|
#endif
|
|
|
|
int *GlobalDeclChunkAttrInit = 0;
|
2014-03-24 05:24:01 +08:00
|
|
|
|
2016-05-25 19:32:42 +08:00
|
|
|
#ifdef GNU
|
|
|
|
// expected-note@+2{{previous attribute is here}}
|
|
|
|
#endif
|
|
|
|
int GlobalDeclAttrInit __attribute__((dllimport)); // expected-note{{previous declaration is here}}
|
|
|
|
#ifdef MS
|
|
|
|
// expected-warning@+4{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
|
|
|
|
#else
|
|
|
|
// expected-warning@+2{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
|
|
|
|
#endif
|
|
|
|
int GlobalDeclAttrInit = 1;
|
2014-03-24 05:24:01 +08:00
|
|
|
|
2014-02-23 03:47:30 +08:00
|
|
|
// Redeclarations
|
|
|
|
__declspec(dllimport) extern int GlobalRedecl1;
|
|
|
|
__declspec(dllimport) extern int GlobalRedecl1;
|
|
|
|
|
2014-03-24 05:24:01 +08:00
|
|
|
__declspec(dllimport) int GlobalRedecl2a;
|
|
|
|
__declspec(dllimport) int GlobalRedecl2a;
|
|
|
|
|
|
|
|
int *__attribute__((dllimport)) GlobalRedecl2b;
|
|
|
|
int *__attribute__((dllimport)) GlobalRedecl2b;
|
|
|
|
|
|
|
|
int GlobalRedecl2c __attribute__((dllimport));
|
|
|
|
int GlobalRedecl2c __attribute__((dllimport));
|
|
|
|
|
2016-05-25 19:32:42 +08:00
|
|
|
// We follow GCC and drop the dllimport with a warning.
|
2014-03-31 22:56:15 +08:00
|
|
|
__declspec(dllimport) extern int GlobalRedecl3; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
|
|
|
|
extern int GlobalRedecl3; // expected-warning{{'GlobalRedecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
|
|
|
|
|
2014-08-28 05:27:40 +08:00
|
|
|
// Adding an attribute on redeclaration.
|
2014-03-31 22:56:15 +08:00
|
|
|
extern int GlobalRedecl4; // expected-note{{previous declaration is here}}
|
2014-08-28 05:27:40 +08:00
|
|
|
int useGlobalRedecl4() { return GlobalRedecl4; }
|
2014-03-31 22:56:15 +08:00
|
|
|
__declspec(dllimport) extern int GlobalRedecl4; // expected-error{{redeclaration of 'GlobalRedecl4' cannot add 'dllimport' attribute}}
|
|
|
|
|
2014-08-28 05:27:40 +08:00
|
|
|
// Allow with a warning if the decl hasn't been used yet.
|
|
|
|
extern int GlobalRedecl5; // expected-note{{previous declaration is here}}
|
|
|
|
__declspec(dllimport) extern int GlobalRedecl5; // expected-warning{{redeclaration of 'GlobalRedecl5' should not add 'dllimport' attribute}}
|
|
|
|
|
|
|
|
|
2014-03-31 22:56:58 +08:00
|
|
|
// External linkage is required.
|
|
|
|
__declspec(dllimport) static int StaticGlobal; // expected-error{{'StaticGlobal' must have external linkage when declared 'dllimport'}}
|
2014-10-04 14:51:54 +08:00
|
|
|
|
|
|
|
// Thread local variables are invalid.
|
|
|
|
__declspec(dllimport) __thread int ThreadLocalGlobal; // expected-error{{'ThreadLocalGlobal' cannot be thread local when declared 'dllimport'}}
|
2014-03-31 22:56:58 +08:00
|
|
|
|
2014-02-23 03:47:30 +08:00
|
|
|
// Import in local scope.
|
2015-07-15 04:08:49 +08:00
|
|
|
__declspec(dllimport) float LocalRedecl1; // expected-note{{previous declaration is here}}
|
|
|
|
__declspec(dllimport) float LocalRedecl2; // expected-note{{previous declaration is here}}
|
|
|
|
__declspec(dllimport) float LocalRedecl3; // expected-note{{previous declaration is here}}
|
2014-08-01 03:29:39 +08:00
|
|
|
__declspec(dllimport) float LocalRedecl4;
|
2014-02-23 03:47:30 +08:00
|
|
|
void functionScope() {
|
2015-07-15 04:08:49 +08:00
|
|
|
__declspec(dllimport) int LocalRedecl1; // expected-error{{redeclaration of 'LocalRedecl1' with a different type: 'int' vs 'float'}}
|
|
|
|
int *__attribute__((dllimport)) LocalRedecl2; // expected-error{{redeclaration of 'LocalRedecl2' with a different type: 'int *' vs 'float'}}
|
|
|
|
int LocalRedecl3 __attribute__((dllimport)); // expected-error{{redeclaration of 'LocalRedecl3' with a different type: 'int' vs 'float'}}
|
2014-03-24 05:24:01 +08:00
|
|
|
|
2014-02-27 05:27:13 +08:00
|
|
|
__declspec(dllimport) int LocalVarDecl;
|
|
|
|
__declspec(dllimport) int LocalVarDef = 1; // expected-error{{definition of dllimport data}}
|
2014-02-23 03:47:30 +08:00
|
|
|
__declspec(dllimport) extern int ExternLocalVarDecl;
|
2014-02-27 05:27:13 +08:00
|
|
|
__declspec(dllimport) extern int ExternLocalVarDef = 1; // expected-error{{definition of dllimport data}}
|
2014-03-31 22:56:58 +08:00
|
|
|
__declspec(dllimport) static int StaticLocalVar; // expected-error{{'StaticLocalVar' must have external linkage when declared 'dllimport'}}
|
2014-08-01 03:29:39 +08:00
|
|
|
|
|
|
|
// Local extern redeclaration does not drop the attribute.
|
|
|
|
extern float LocalRedecl4;
|
2014-02-23 03:47:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Functions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Import function declaration. Check different placements.
|
|
|
|
__attribute__((dllimport)) void decl1A(); // Sanity check with __attribute__
|
|
|
|
__declspec(dllimport) void decl1B();
|
|
|
|
|
|
|
|
void __attribute__((dllimport)) decl2A();
|
|
|
|
void __declspec(dllimport) decl2B();
|
|
|
|
|
2014-06-25 16:15:07 +08:00
|
|
|
// Address of functions can be used for initialization in C language modes.
|
|
|
|
// However, the address of the thunk wrapping the function is used instead of
|
|
|
|
// the address in the import address table.
|
|
|
|
void (*FunForInit)() = &decl2A;
|
|
|
|
|
2014-02-23 03:47:30 +08:00
|
|
|
// Not allowed on function definitions.
|
2014-05-16 06:07:49 +08:00
|
|
|
__declspec(dllimport) void def() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
|
2014-02-23 03:47:30 +08:00
|
|
|
|
|
|
|
// Import inline function.
|
2014-11-03 22:24:45 +08:00
|
|
|
#ifdef GNU
|
|
|
|
// expected-warning@+3{{'dllimport' attribute ignored on inline function}}
|
|
|
|
// expected-warning@+3{{'dllimport' attribute ignored on inline function}}
|
|
|
|
#endif
|
2014-05-16 06:07:49 +08:00
|
|
|
__declspec(dllimport) inline void inlineFunc1() {}
|
|
|
|
inline void __attribute__((dllimport)) inlineFunc2() {}
|
2014-02-23 03:47:30 +08:00
|
|
|
|
|
|
|
// Redeclarations
|
|
|
|
__declspec(dllimport) void redecl1();
|
|
|
|
__declspec(dllimport) void redecl1();
|
|
|
|
|
2014-03-31 22:56:15 +08:00
|
|
|
__declspec(dllimport) void redecl2(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
|
|
|
|
void redecl2(); // expected-warning{{'redecl2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
|
|
|
|
|
2016-05-25 19:32:42 +08:00
|
|
|
#ifdef GNU
|
|
|
|
// expected-note@+2{{previous attribute is here}}
|
|
|
|
#endif
|
|
|
|
__declspec(dllimport) void redecl3(); // expected-note{{previous declaration is here}}
|
|
|
|
// NB: Both MSVC and Clang issue a warning and make redecl3 dllexport.
|
|
|
|
#ifdef MS
|
|
|
|
// expected-warning@+4{{'redecl3' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
|
|
|
|
#else
|
|
|
|
// expected-warning@+2{{'redecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
|
|
|
|
#endif
|
|
|
|
void redecl3() {}
|
2014-03-31 22:56:15 +08:00
|
|
|
|
|
|
|
void redecl4(); // expected-note{{previous declaration is here}}
|
2014-08-28 05:27:40 +08:00
|
|
|
void useRedecl4() { redecl4(); }
|
2015-07-23 07:54:51 +08:00
|
|
|
__declspec(dllimport) void redecl4(); // expected-warning{{redeclaration of 'redecl4' should not add 'dllimport' attribute}}
|
2014-03-31 22:56:58 +08:00
|
|
|
|
2014-08-28 05:27:40 +08:00
|
|
|
// Allow with a warning if the decl hasn't been used yet.
|
|
|
|
void redecl5(); // expected-note{{previous declaration is here}}
|
|
|
|
__declspec(dllimport) void redecl5(); // expected-warning{{redeclaration of 'redecl5' should not add 'dllimport' attribute}}
|
|
|
|
|
|
|
|
|
2014-11-03 22:24:45 +08:00
|
|
|
// Inline redeclarations.
|
|
|
|
#ifdef GNU
|
|
|
|
// expected-warning@+3{{'redecl6' redeclared inline; 'dllimport' attribute ignored}}
|
|
|
|
#endif
|
2014-08-28 05:27:40 +08:00
|
|
|
__declspec(dllimport) void redecl6();
|
|
|
|
inline void redecl6() {}
|
2014-05-24 03:07:49 +08:00
|
|
|
|
2014-11-03 22:24:45 +08:00
|
|
|
#ifdef MS
|
|
|
|
// expected-note@+5{{previous declaration is here}}
|
|
|
|
// expected-warning@+5{{redeclaration of 'redecl7' should not add 'dllimport' attribute}}
|
|
|
|
#else
|
|
|
|
// expected-warning@+3{{'dllimport' attribute ignored on inline function}}
|
|
|
|
#endif
|
|
|
|
void redecl7();
|
|
|
|
__declspec(dllimport) inline void redecl7() {}
|
2014-05-22 23:46:15 +08:00
|
|
|
|
2016-11-30 06:31:00 +08:00
|
|
|
// PR31069: Don't crash trying to merge attributes for redeclaration of invalid decl.
|
|
|
|
void __declspec(dllimport) redecl8(unknowntype X); // expected-error{{unknown type name 'unknowntype'}}
|
|
|
|
void redecl8(unknowntype X) { } // expected-error{{unknown type name 'unknowntype'}}
|
|
|
|
|
2014-03-31 22:56:58 +08:00
|
|
|
// External linkage is required.
|
|
|
|
__declspec(dllimport) static int staticFunc(); // expected-error{{'staticFunc' must have external linkage when declared 'dllimport'}}
|
2015-09-05 03:59:39 +08:00
|
|
|
|
|
|
|
// Static locals don't count as having external linkage.
|
|
|
|
void staticLocalFunc() {
|
|
|
|
__declspec(dllimport) static int staticLocal; // expected-error{{'staticLocal' must have external linkage when declared 'dllimport'}}
|
|
|
|
}
|