Index: clang/docs/ClangCommandLineReference.rst =================================================================== --- clang/docs/ClangCommandLineReference.rst +++ clang/docs/ClangCommandLineReference.rst @@ -3315,6 +3315,16 @@ .. option:: -mx32 +.. option:: -mdefault-visibility-export-mapping=\[none,explicit,all\] + +Map default visibility to an explicit shared library export (e.g. dllexport). +Exactly how and if this is manifested is target dependent. Three values are +provided for the option: + +* none: the default and behavior without the option, no additional export linkage information is created. +* explicit: add the export for entities with explict default visibility from the source, including RTTI +* all: add the export for all entities with default visibility + AARCH64 ------- .. option:: -fcall-saved-x10 Index: clang/include/clang/Basic/LangOptions.h =================================================================== --- clang/include/clang/Basic/LangOptions.h +++ clang/include/clang/Basic/LangOptions.h @@ -353,6 +353,14 @@ PerThread, }; + enum class DefaultVisiblityExportMapping { + None, + /// map only explicit public visibilities to exported + Explicit, + /// map all public visibilities to exported + All, + }; + public: /// The used language standard. LangStandard::Kind LangStd; @@ -584,6 +592,16 @@ bool isSYCL() const { return SYCLIsDevice || SYCLIsHost; } + bool isExplicitDefaultVisibilityExportMapping() const { + return getDefaultVisibilityExportMapping() == + DefaultVisiblityExportMapping::Explicit; + } + + bool isAllDefaultVisibilityExportMapping() const { + return getDefaultVisibilityExportMapping() == + DefaultVisiblityExportMapping::All; + } + /// Remap path prefix according to -fmacro-prefix-path option. void remapPathPrefix(SmallVectorImpl &Path) const; }; Index: clang/include/clang/Basic/LangOptions.def =================================================================== --- clang/include/clang/Basic/LangOptions.def +++ clang/include/clang/Basic/LangOptions.def @@ -289,6 +289,7 @@ BENIGN_LANGOPT(DumpVTableLayouts , 1, 0, "dumping the layouts of emitted vtables") LANGOPT(NoConstantCFStrings , 1, 0, "no constant CoreFoundation strings") BENIGN_LANGOPT(InlineVisibilityHidden , 1, 0, "hidden visibility for inline C++ methods") +BENIGN_ENUM_LANGOPT(DefaultVisibilityExportMapping, DefaultVisiblityExportMapping, 2, DefaultVisiblityExportMapping::None, "controls mapping of public visibility to dllexport") BENIGN_LANGOPT(IgnoreXCOFFVisibility, 1, 0, "All the visibility attributes that are specified in the source code are ignored in aix XCOFF.") BENIGN_LANGOPT(VisibilityInlinesHiddenStaticLocalVar, 1, 0, "hidden visibility for static local variables in inline C++ " Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -2908,6 +2908,13 @@ def fvisibility_global_new_delete_hidden : Flag<["-"], "fvisibility-global-new-delete-hidden">, Group, HelpText<"Give global C++ operator new and delete declarations hidden visibility">, Flags<[CC1Option]>, MarshallingInfoFlag>; +def mdefault_visibility_export_mapping_EQ : Joined<["-"], "mdefault-visibility-export-mapping=">, + Values<"none,explicit,all">, + NormalizedValuesScope<"LangOptions::DefaultVisiblityExportMapping">, + NormalizedValues<["None", "Explicit", "All"]>, + HelpText<"Mapping between default visibility and export">, + Group, Flags<[CC1Option]>, + MarshallingInfoEnum,"None">; defm new_infallible : BoolFOption<"new-infallible", LangOpts<"NewInfallible">, DefaultFalse, PosFlag, NegFlag, Index: clang/lib/CodeGen/CodeGenModule.h =================================================================== --- clang/lib/CodeGen/CodeGenModule.h +++ clang/lib/CodeGen/CodeGenModule.h @@ -798,6 +798,7 @@ void setDSOLocal(llvm::GlobalValue *GV) const; + bool shouldMapVisibilityToDLLExport(const NamedDecl *D) const; void setDLLImportDLLExport(llvm::GlobalValue *GV, GlobalDecl D) const; void setDLLImportDLLExport(llvm::GlobalValue *GV, const NamedDecl *D) const; /// Set visibility, dllimport/dllexport and dso_local. Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -1212,12 +1212,21 @@ setDLLImportDLLExport(GV, D); } +bool CodeGenModule::shouldMapVisibilityToDLLExport(const NamedDecl *D) const { + return (D->getLinkageAndVisibility().getVisibility() == DefaultVisibility) && + ((D->getLinkageAndVisibility().isVisibilityExplicit() && + getLangOpts().isExplicitDefaultVisibilityExportMapping()) || + getLangOpts().isAllDefaultVisibilityExportMapping()); +} + void CodeGenModule::setDLLImportDLLExport(llvm::GlobalValue *GV, const NamedDecl *D) const { if (D && D->isExternallyVisible()) { if (D->hasAttr()) GV->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass); - else if (D->hasAttr() && !GV->isDeclarationForLinker()) + else if ((D->hasAttr() || + shouldMapVisibilityToDLLExport(D)) && + !GV->isDeclarationForLinker()) GV->setDLLStorageClass(llvm::GlobalVariable::DLLExportStorageClass); } } Index: clang/lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -3680,12 +3680,12 @@ llvm::GlobalValue::DLLStorageClassTypes DLLStorageClass = llvm::GlobalValue::DefaultStorageClass; - if (CGM.getTriple().isWindowsItaniumEnvironment()) { - auto RD = Ty->getAsCXXRecordDecl(); - if (RD && RD->hasAttr()) + if (auto RD = Ty->getAsCXXRecordDecl()) { + if ((CGM.getTriple().isWindowsItaniumEnvironment() && + RD->hasAttr()) || + CGM.shouldMapVisibilityToDLLExport(RD)) DLLStorageClass = llvm::GlobalValue::DLLExportStorageClass; } - return BuildTypeInfo(Ty, Linkage, llvmVisibility, DLLStorageClass); } @@ -4168,7 +4168,7 @@ getContext().Char32Ty }; llvm::GlobalValue::DLLStorageClassTypes DLLStorageClass = - RD->hasAttr() + RD->hasAttr() || CGM.shouldMapVisibilityToDLLExport(RD) ? llvm::GlobalValue::DLLExportStorageClass : llvm::GlobalValue::DefaultStorageClass; llvm::GlobalValue::VisibilityTypes Visibility = Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp =================================================================== --- clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ clang/lib/CodeGen/MicrosoftCXXABI.cpp @@ -26,6 +26,7 @@ #include "clang/AST/StmtCXX.h" #include "clang/AST/VTableBuilder.h" #include "clang/CodeGen/ConstantInitBuilder.h" +#include "clang/Frontend/FrontendDiagnostic.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSet.h" #include "llvm/IR/Intrinsics.h" @@ -47,7 +48,11 @@ : CGCXXABI(CGM), BaseClassDescriptorType(nullptr), ClassHierarchyDescriptorType(nullptr), CompleteObjectLocatorType(nullptr), CatchableTypeType(nullptr), - ThrowInfoType(nullptr) {} + ThrowInfoType(nullptr) { + assert(!(CGM.getLangOpts().isExplicitDefaultVisibilityExportMapping() || + CGM.getLangOpts().isAllDefaultVisibilityExportMapping()) && + "visibility export mapping option unimplemented in this ABI"); + } bool HasThisReturn(GlobalDecl GD) const override; bool hasMostDerivedReturn(GlobalDecl GD) const override; Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -5966,6 +5966,15 @@ << A->getAsString(Args) << TripleStr; } + if (const Arg *A = + Args.getLastArg(options::OPT_mdefault_visibility_export_mapping_EQ)) { + if (Triple.isOSAIX()) + CmdArgs.push_back(Args.MakeArgString( + "-mdefault-visibility-export-mapping=" + Twine(A->getValue(0)))); + else + D.Diag(diag::err_drv_unsupported_opt_for_target) + << A->getAsString(Args) << TripleStr; + } if (Args.hasFlag(options::OPT_fvisibility_inlines_hidden, options::OPT_fno_visibility_inlines_hidden, false)) Index: clang/test/CodeGen/mdefault-visibility-export-mapping.c =================================================================== --- /dev/null +++ clang/test/CodeGen/mdefault-visibility-export-mapping.c @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -S -emit-llvm -o - | \ +// RUN: FileCheck -check-prefixes=CHECK --implicit-check-not dllexport %s +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -mdefault-visibility-export-mapping=none -S -emit-llvm -o - | \ +// RUN: FileCheck -check-prefixes=CHECK --implicit-check-not dllexport %s +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -mdefault-visibility-export-mapping=explicit -S -emit-llvm -o - | \ +// RUN: FileCheck -check-prefixes=CHECK,EXPLICIT,PRAGMA --implicit-check-not dllexport %s +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -mdefault-visibility-export-mapping=all -S -emit-llvm -o - | \ +// RUN: FileCheck -check-prefixes=CHECK,UNSPECIFIED,EXPLICIT,PRAGMA --implicit-check-not dllexport %s +// RUN: %clang -target powerpc-ibm-aix %s -mdefault-visibility-export-mapping=all -fvisibility=hidden -S -emit-llvm -o - | \ +// RUN: FileCheck -check-prefixes=CHECK,EXPLICIT,PRAGMA --implicit-check-not dllexport %s + +// RUN: not %clang -mdefault-visibility-export-mapping=explicit -target powerpc-unknown-linux %s 2>&1 | \ +// RUN: FileCheck -check-prefix=ERROR %s +// ERROR: unsupported option '-mdefault-visibility-export-mapping=explicit' for target 'powerpc-unknown-linux' + +// CHECK: define hidden void @hiddenfunc() +void __attribute__((visibility("hidden"))) hiddenfunc() {} + +// CHECK: define +// UNSPECIFIED-SAME: dllexport +// CHECK-SAME: void @func() +void func() {} + +#pragma GCC visibility push(default) +// CHECK: define +// PRAGMA-SAME: dllexport +// CHECK-SAME: void @pragmafunc() +void pragmafunc() {} +#pragma GCC visibility pop + +// CHECK: define +// EXPLICIT-SAME: dllexport +// CHECK-SAME: void @explicitfunc() +void __attribute__((visibility("default"))) explicitfunc() {} Index: clang/test/CodeGenCXX/mdefault-visibility-export-mapping-rtti.cpp =================================================================== --- /dev/null +++ clang/test/CodeGenCXX/mdefault-visibility-export-mapping-rtti.cpp @@ -0,0 +1,569 @@ +// RUN: %clang_cc1 -triple powerpc64-ibm-aix %s -internal-isystem %S -mdefault-visibility-export-mapping=none -S -emit-llvm -o - | \ +// RUN: FileCheck -check-prefixes=CHECK --implicit-check-not dllexport %s +// RUN: %clang_cc1 -triple powerpc64-ibm-aix %s -internal-isystem %S -mdefault-visibility-export-mapping=explicit -S -emit-llvm -o - | \ +// RUN: FileCheck -check-prefixes=CHECK,EXPLICIT --implicit-check-not dllexport %s +// RUN: %clang_cc1 -triple powerpc64-ibm-aix %s -internal-isystem %S -mdefault-visibility-export-mapping=explicit -DFUNDAMENTAL_IS_EXPLICIT -S -emit-llvm -o - | \ +// RUN: FileCheck -check-prefixes=CHECK,EXPLICIT,EXPORTED_FUNDAMENTAL --implicit-check-not dllexport %s +// RUN: %clang_cc1 -triple powerpc64-ibm-aix %s -internal-isystem %S -mdefault-visibility-export-mapping=all -S -emit-llvm -o - | \ +// RUN: FileCheck -check-prefixes=CHECK,UNSPECIFIED,EXPLICIT,EXPORTED_FUNDAMENTAL --implicit-check-not dllexport %s +// RUN: %clang_cc1 -triple powerpc64-ibm-aix %s -internal-isystem %S -mdefault-visibility-export-mapping=all -fvisibility hidden -S -emit-llvm -o - | \ +// RUN: FileCheck -check-prefixes=CHECK,EXPLICIT --implicit-check-not dllexport %s + +#include + +// unspecified visibility RTTI & vtable +struct s { + virtual void foo(); +}; +void s::foo() {} +// CHECK: @_ZTV1s = +// UNSPECIFIED-SAME: dllexport +// CHECK-SAME: unnamed_addr constant +// CHECK: @_ZTS1s = +// UNSPECIFIED-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTI1s = +// UNSPECIFIED-SAME: dllexport +// CHECK-SAME: constant + +// explicit default visibility RTTI & vtable +struct __attribute__((type_visibility("default"))) t { + virtual void foo(); +}; +void t::foo() {} +// CHECK: @_ZTV1t = +// EXPLICIT-SAME: dllexport +// CHECK-SAME: unnamed_addr constant +// CHECK: @_ZTS1t = +// EXPLICIT-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTI1t = +// EXPLICIT-SAME: dllexport +// CHECK-SAME: constant + +#ifdef FUNDAMENTAL_IS_EXPLICIT +#define TYPE_VIS __attribute__((type_visibility("default"))) +#else +#define TYPE_VIS +#endif + +// Invoke the compiler magic to emit RTTI for fundamental types. +namespace __cxxabiv1 { +class TYPE_VIS __fundamental_type_info { + __attribute__((visibility("hidden"))) virtual ~__fundamental_type_info(); +}; + +__fundamental_type_info::~__fundamental_type_info() {} + +} // namespace __cxxabiv1 + +// __cxxabiv1::__fundamental_type_info +// CHECK: @_ZTVN10__cxxabiv123__fundamental_type_infoE +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSN10__cxxabiv123__fundamental_type_infoE +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIN10__cxxabiv123__fundamental_type_infoE +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// void +// CHECK: @_ZTSv +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIv +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPv +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPv +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKv +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKv +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// std::nullptr_t +// CHECK: @_ZTSDn +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIDn +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPDn +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPDn +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKDn +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKDn +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// bool +// CHECK: @_ZTSb +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIb +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPb +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPb +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKb +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKb +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// wchar_t +// CHECK: @_ZTSw +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIw +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPw +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPw +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKw +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKw +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// char +// CHECK: @_ZTSc +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIc +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPc +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPc +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKc +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKc +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// unsigned char +// CHECK: @_ZTSh +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIh +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPh +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPh +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKh +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKh +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// signed char +// CHECK: @_ZTSa +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIa +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPa +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPa +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKa +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKa +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// short +// CHECK: @_ZTSs +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIs +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPs +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPs +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKs +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKs +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// unsigned short +// CHECK: @_ZTSt +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIt +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPt +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPt +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKt +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKt +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// int +// CHECK: @_ZTSi +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIi +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPi +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPi +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKi +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKi +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// unsigned int +// CHECK: @_ZTSj +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIj +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPj +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPj +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKj +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKj +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// long +// CHECK: @_ZTSl +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIl +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPl +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPl +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKl +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKl +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// unsigned long +// CHECK: @_ZTSm +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIm +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPm +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPm +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKm +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKm +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// long long +// CHECK: @_ZTSx +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIx +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPx +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPx +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKx +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKx +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// unsigned long long +// CHECK: @_ZTSy +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIy +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPy +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPy +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKy +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKy +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// __int128 +// CHECK: @_ZTSn +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIn +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPn +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPn +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKn +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKn +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// unsigned __int128 +// CHECK: @_ZTSo +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIo +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPo +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPo +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKo +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKo +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// half +// CHECK: @_ZTSDh +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIDh +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPDh +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPDh +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKDh +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKDh +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// float +// CHECK: @_ZTSf +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIf +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPf +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPf +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKf +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKf +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// double +// CHECK: @_ZTSd +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTId +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPd +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPd +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKd +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKd +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// long double +// CHECK: @_ZTSe +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIe +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPe +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPe +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKe +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKe +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// __ieee128 +// CHECK: @_ZTSu9__ieee128 +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIu9__ieee128 +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPu9__ieee128 +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPu9__ieee128 +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKu9__ieee128 +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKu9__ieee128 +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// char8_t +// CHECK: @_ZTSDu +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIDu +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPDu +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPDu +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKDu +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKDu +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// char16_t +// CHECK: @_ZTSDs +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIDs +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPDs +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPDs +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKDs +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKDs +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant + +// char32_t +// CHECK: @_ZTSDi +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIDi +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPDi +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPDi +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTSPKDi +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant +// CHECK: @_ZTIPKDi +// EXPORTED_FUNDAMENTAL-SAME: dllexport +// CHECK-SAME: constant Index: clang/test/CodeGenCXX/mdefault-visibility-export-mapping.cpp =================================================================== --- /dev/null +++ clang/test/CodeGenCXX/mdefault-visibility-export-mapping.cpp @@ -0,0 +1,111 @@ +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -S -emit-llvm -o - | \ +// RUN: FileCheck -check-prefixes=CHECK --implicit-check-not dllexport %s +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -mdefault-visibility-export-mapping=none -S -emit-llvm -o - | \ +// RUN: FileCheck -check-prefixes=CHECK --implicit-check-not dllexport %s +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -mdefault-visibility-export-mapping=explicit -S -emit-llvm -o - | \ +// RUN: FileCheck -check-prefixes=CHECK,EXPLICIT --implicit-check-not dllexport %s +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -mdefault-visibility-export-mapping=all -S -emit-llvm -o - | \ +// RUN: FileCheck -check-prefixes=CHECK,UNSPECIFIED,EXPLICIT --implicit-check-not dllexport %s + +struct A {}; + +template +class B { +public: + T x; + B(T _x) : x(_x) {} + ~B() {} + void func(T x) {} +}; + +template +class __attribute__((visibility("default"))) C { +public: + T x; + C(T _x) : x(_x) {} + ~C() {} + void func(T x) {} +}; + +extern template class B; +extern template class C; + +// CHECK: define +// UNSPECIFIED-SAME: dllexport +// CHECK-SAME: @_Z4funcv +void func() { + B x({}); + C y({}); + x.func({}); y.func({}); + B xi(0); + C yi(0); + xi.func(0); yi.func(0); +} + +// B::B(A) (complete object constructor) +// CHECK: define linkonce_odr +// UNSPECIFIED-SAME: dllexport +// CHECK-SAME: void @_ZN1BI1AEC1ES0_ + +// C::C(A) (complete object constructor) +// CHECK: define linkonce_odr +// EXPLICIT-SAME: dllexport +// CHECK-SAME: void @_ZN1CI1AEC1ES0_ + +// B::func(A) +// CHECK: define linkonce_odr +// UNSPECIFIED-SAME: dllexport +// CHECK-SAME: void @_ZN1BI1AE4funcES0_ + +// C::func(A) +// CHECK: define linkonce_odr +// EXPLICIT-SAME: dllexport +// CHECK-SAME: void @_ZN1CI1AE4funcES0_ + +// B::B(int) (complete object constructor) +// CHECK: declare void @_ZN1BIiEC1Ei + +// C::C(int) (complete object constructor) +// CHECK: declare void @_ZN1CIiEC1Ei + +// B::func(int) +// CHECK: declare void @_ZN1BIiE4funcEi + +// C::func(int) +// CHECK: declare void @_ZN1CIiE4funcEi + +// C::~C() (complete object destructor) +// CHECK: declare void @_ZN1CIiED1Ev + +// B::~B() (complete object destructor) +// CHECK: declare void @_ZN1BIiED1Ev + +// C::~c() (complete object destructor) +// CHECK: define linkonce_odr +// EXPLICIT-SAME: dllexport +// CHECK-SAME: void @_ZN1CI1AED1Ev + +// B::~B() (complete object destructor) +// CHECK: define linkonce_odr +// UNSPECIFIED-SAME: dllexport +// CHECK-SAME: void @_ZN1BI1AED1Ev + +// B::B(A) (base object constructor) +// CHECK: define linkonce_odr +// UNSPECIFIED-SAME: dllexport +// CHECK-SAME: void @_ZN1BI1AEC2ES0_ + +// B::~B() (base object destructor) +// CHECK: define linkonce_odr +// UNSPECIFIED-SAME: dllexport +// CHECK-SAME: void @_ZN1BI1AED2Ev + +// C::C(A) (base object constructor) +// CHECK: define linkonce_odr +// EXPLICIT-SAME: dllexport +// CHECK-SAME: void @_ZN1CI1AEC2ES0_ + +// C::~C() (base object destructor) +// CHECK: define linkonce_odr +// EXPLICIT-SAME: dllexport +// CHECK-SAME: void @_ZN1CI1AED2Ev