Index: clang/include/clang/Basic/Attr.td =================================================================== --- clang/include/clang/Basic/Attr.td +++ clang/include/clang/Basic/Attr.td @@ -368,8 +368,8 @@ def TargetX86 : TargetArch<["x86"]>; def TargetAnyX86 : TargetArch<["x86", "x86_64"]>; def TargetWebAssembly : TargetArch<["wasm32", "wasm64"]>; -def TargetWindows : TargetArch<["x86", "x86_64", "arm", "thumb", "aarch64"]> { - let OSes = ["Win32"]; +def TargetHasDLLImportExport : TargetSpec { + let CustomCode = [{ Target.getTriple().hasDLLImportExport() }]; } def TargetItaniumCXXABI : TargetSpec { let CustomCode = [{ Target.getCXXABI().isItaniumFamily() }]; @@ -3144,24 +3144,24 @@ let SimpleHandler = 1; } -def DLLExport : InheritableAttr, TargetSpecificAttr { +def DLLExport : InheritableAttr, TargetSpecificAttr { let Spellings = [Declspec<"dllexport">, GCC<"dllexport">]; let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>; let Documentation = [DLLExportDocs]; } -def DLLExportStaticLocal : InheritableAttr, TargetSpecificAttr { +def DLLExportStaticLocal : InheritableAttr, TargetSpecificAttr { // This attribute is used internally only when -fno-dllexport-inlines is - // passed. This attribute is added to inline function of class having - // dllexport attribute. And if the function has static local variables, this - // attribute is used to whether the variables are exported or not. Also if - // function has local static variables, the function is dllexported too. + // passed. This attribute is added to inline functions of a class having the + // dllexport attribute. If the function has static local variables, this + // attribute is used to determine whether the variables are exported or not. If + // the function has local static variables, the function is dllexported too. let Spellings = []; let Subjects = SubjectList<[Function]>; let Documentation = [Undocumented]; } -def DLLImport : InheritableAttr, TargetSpecificAttr { +def DLLImport : InheritableAttr, TargetSpecificAttr { let Spellings = [Declspec<"dllimport">, GCC<"dllimport">]; let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>; let Documentation = [DLLImportDocs]; @@ -3177,11 +3177,11 @@ }]; } -def DLLImportStaticLocal : InheritableAttr, TargetSpecificAttr { +def DLLImportStaticLocal : InheritableAttr, TargetSpecificAttr { // This attribute is used internally only when -fno-dllexport-inlines is - // passed. This attribute is added to inline function of class having - // dllimport attribute. And if the function has static local variables, this - // attribute is used to whether the variables are imported or not. + // passed. This attribute is added to inline functions of a class having the + // dllimport attribute. If the function has static local variables, this + // attribute is used to determine whether the variables are imported or not. let Spellings = []; let Subjects = SubjectList<[Function]>; let Documentation = [Undocumented]; Index: clang/test/CodeGen/ps4-dllimport-dllexport.c =================================================================== --- /dev/null +++ clang/test/CodeGen/ps4-dllimport-dllexport.c @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 \ +// RUN: -triple x86_64-scei-ps4 \ +// RUN: -fdeclspec \ +// RUN: -Werror \ +// RUN: -emit-llvm %s -o - | \ +// RUN: FileCheck %s + +__declspec(dllexport) int export_int; + +__declspec(dllimport) int import_int; + +__declspec(dllexport) void export_declared_function(); + +__declspec(dllexport) void export_implemented_function() { +} + +__declspec(dllimport) void import_function(int); + +void call_imported_function() { + export_declared_function(); + return import_function(import_int); +} + +// CHECK-DAG: @import_int = external dllimport +// CHECK-DAG: @export_int = dllexport global i32 0 +// CHECK-DAG: define dllexport void @export_implemented_function() +// CHECK-DAG: declare dllimport void @import_function(i32) Index: llvm/include/llvm/ADT/Triple.h =================================================================== --- llvm/include/llvm/ADT/Triple.h +++ llvm/include/llvm/ADT/Triple.h @@ -782,6 +782,9 @@ return isOSBinFormatXCOFF() || isWasm(); } + /// Tests if the environment supports dllimport/export annotations. + bool hasDLLImportExport() const { return isOSWindows() || isPS4CPU(); } + /// @} /// @name Mutators /// @{