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