// 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
// RUN: %clang_cc1 -triple aarch64-win32 -fsyntax-only -fms-extensions -verify -std=c99 -DMS %s
// RUN: %clang_cc1 -triple i686-windows-itanium -fsyntax-only -fms-extensions -verify -std=c99 -DWI %s
// RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c11 -DWI %s
// RUN: %clang_cc1 -triple x86_64-scei-ps4 -fsyntax-only -fms-extensions -verify -std=c11 -DWI %s
// RUN: %clang_cc1 -triple x86_64-scei-ps4 -fsyntax-only -fms-extensions -verify -std=c99 -DWI %s
// RUN: %clang_cc1 -triple x86_64-sie-ps5 -fsyntax-only -fms-extensions -verify -std=c11 -DWI %s
// Invalid usage.
__declspec typedef int typedef1;
// expected-warning@-1{{'dllimport' attribute only applies to functions, variables, classes, and Objective-C interfaces}}
typedef __declspec int typedef2;
// expected-warning@-1{{'dllimport' attribute only applies to}}
typedef int __declspec typedef3;
// expected-warning@-1{{'dllimport' attribute only applies to}}
typedef __declspec void ;
// expected-warning@-1{{'dllimport' attribute only applies to}}
;
// expected-warning@-1{{'dllimport' attribute only applies to}}
;
// expected-warning@-1{{'dllimport' attribute only applies to}}
//===----------------------------------------------------------------------===//
// Globals
//===----------------------------------------------------------------------===//
// Import declaration.
__declspec extern int ExternGlobalDecl;
// dllimport implies a declaration.
__declspec int GlobalDecl;
int *** GlobalDeclChunkAttr;
int GlobalDeclAttr ;
// 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}}
// Not allowed on definitions.
__declspec extern int ExternGlobalInit = 1; // expected-error{{definition of dllimport data}}
__declspec int GlobalInit1 = 1; // expected-error{{definition of dllimport data}}
int __declspec GlobalInit2 = 1; // expected-error{{definition of dllimport data}}
// Declare, then reject definition.
// expected-note@+2{{previous attribute is here}}
__declspec extern int ExternGlobalDeclInit; // expected-note{{previous declaration is here}}
// expected-warning@+4{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
// expected-warning@+2{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
int ExternGlobalDeclInit = 1;
// expected-note@+2{{previous attribute is here}}
__declspec int GlobalDeclInit; // expected-note{{previous declaration is here}}
// expected-warning@+4{{'GlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
// expected-warning@+2{{'GlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
int GlobalDeclInit = 1;
// expected-note@+2{{previous attribute is here}}
int * GlobalDeclChunkAttrInit; // expected-note{{previous declaration is here}}
// expected-warning@+4{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
// expected-warning@+2{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
int *GlobalDeclChunkAttrInit = 0;
// expected-note@+2{{previous attribute is here}}
int GlobalDeclAttrInit ; // expected-note{{previous declaration is here}}
// expected-warning@+4{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
// expected-warning@+2{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
int GlobalDeclAttrInit = 1;
// Redeclarations
__declspec extern int GlobalRedecl1;
__declspec extern int GlobalRedecl1;
__declspec int GlobalRedecl2a;
__declspec int GlobalRedecl2a;
int * GlobalRedecl2b;
int * GlobalRedecl2b;
int GlobalRedecl2c ;
int GlobalRedecl2c ;
// We follow GCC and drop the dllimport with a warning.
__declspec 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}}
// Adding an attribute on redeclaration.
extern int GlobalRedecl4; // expected-note{{previous declaration is here}}
int
__declspec extern int GlobalRedecl4; // expected-error{{redeclaration of 'GlobalRedecl4' cannot add 'dllimport' attribute}}
// Allow with a warning if the decl hasn't been used yet.
extern int GlobalRedecl5; // expected-note{{previous declaration is here}}
__declspec extern int GlobalRedecl5; // expected-warning{{redeclaration of 'GlobalRedecl5' should not add 'dllimport' attribute}}
// External linkage is required.
__declspec static int StaticGlobal; // expected-error{{'StaticGlobal' must have external linkage when declared 'dllimport'}}
// Thread local variables are invalid.
__declspec __thread int ThreadLocalGlobal; // expected-error{{'ThreadLocalGlobal' cannot be thread local when declared 'dllimport'}}
// Import in local scope.
__declspec float LocalRedecl1; // expected-note{{previous declaration is here}}
__declspec float LocalRedecl2; // expected-note{{previous declaration is here}}
__declspec float LocalRedecl3; // expected-note{{previous declaration is here}}
__declspec float LocalRedecl4;
void
//===----------------------------------------------------------------------===//
// Functions
//===----------------------------------------------------------------------===//
// Import function declaration. Check different placements.
void ; // Basic check with __attribute__
__declspec void ;
void ;
void __declspec ;
// 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.
= &decl2A;
// Not allowed on function definitions.
__declspec void // expected-error{{dllimport cannot be applied to non-inline function definition}}
// Import inline function.
// expected-warning@+3{{'dllimport' attribute ignored on inline function}}
// expected-warning@+3{{'dllimport' attribute ignored on inline function}}
__declspec inline void
inline void
// Redeclarations
__declspec void ;
__declspec void ;
__declspec void ; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
void ; // expected-warning{{'redecl2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
// expected-note@+2{{previous attribute is here}}
__declspec void ; // expected-note{{previous declaration is here}}
// NB: Both MSVC and Clang issue a warning and make redecl3 dllexport.
// expected-warning@+4{{'redecl3' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
// expected-warning@+2{{'redecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
void
void ; // expected-note{{previous declaration is here}}
void
__declspec void ; // expected-warning{{redeclaration of 'redecl4' should not add 'dllimport' attribute}}
// Allow with a warning if the decl hasn't been used yet.
void ; // expected-note{{previous declaration is here}}
__declspec void ; // expected-warning{{redeclaration of 'redecl5' should not add 'dllimport' attribute}}
// Inline redeclarations.
// expected-warning@+3{{'redecl6' redeclared inline; 'dllimport' attribute ignored}}
__declspec void ;
inline void
// expected-note@+5{{previous declaration is here}}
// expected-warning@+5{{redeclaration of 'redecl7' should not add 'dllimport' attribute}}
// expected-warning@+3{{'dllimport' attribute ignored on inline function}}
void ;
__declspec inline void
// PR31069: Don't crash trying to merge attributes for redeclaration of invalid
// decl.
void __declspec ; // expected-error{{unknown type name 'unknowntype'}}
void // expected-error{{unknown type name 'unknowntype'}}
// PR32021: Similarly, don't crash trying to merge attributes from a valid
// decl to an invalid redeclaration.
void __declspec ; // expected-note{{previous declaration is here}}
int // expected-error{{conflicting types for 'redecl9'}}
// External linkage is required.
__declspec static int ; // expected-error{{'staticFunc' must have external linkage when declared 'dllimport'}}
// Static locals don't count as having external linkage.
void