diff options
author | Petr Hosek <phosek@chromium.org> | 2017-11-22 19:50:17 +0000 |
---|---|---|
committer | Petr Hosek <phosek@chromium.org> | 2017-11-22 19:50:17 +0000 |
commit | 32c9de009a52a43db3a24c38f05d2543f3fd6911 (patch) | |
tree | 66ed42a4e1db787d5b9126656671c0dbb7a8969d | |
parent | 3295274725ba7d941468deb388375a66afe78baf (diff) | |
download | bcm5719-llvm-32c9de009a52a43db3a24c38f05d2543f3fd6911.tar.gz bcm5719-llvm-32c9de009a52a43db3a24c38f05d2543f3fd6911.zip |
Revert "[CodeGen] Fix vtable not receiving hidden visibility when using push(visibility)"
This reverts commit r318853: tests are failing on Windows bots
llvm-svn: 318866
-rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 2 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGVTT.cpp | 2 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGVTables.cpp | 4 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 26 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.h | 3 | ||||
-rw-r--r-- | clang/lib/CodeGen/ItaniumCXXABI.cpp | 3 | ||||
-rw-r--r-- | clang/test/CodeGen/push-hidden-visibility-subclass.cpp | 21 |
7 files changed, 19 insertions, 42 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 04585a8afbb..7350af870d2 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -240,7 +240,7 @@ llvm::Constant *CodeGenModule::getOrCreateStaticVarDecl( getModule(), LTy, Ty.isConstant(getContext()), Linkage, Init, Name, nullptr, llvm::GlobalVariable::NotThreadLocal, TargetAS); GV->setAlignment(getContext().getDeclAlign(&D).getQuantity()); - setGlobalVisibility(GV, &D, ForDefinition); + setGlobalVisibility(GV, &D); if (supportsCOMDAT() && GV->isWeakForLinker()) GV->setComdat(TheModule.getOrInsertComdat(GV->getName())); diff --git a/clang/lib/CodeGen/CGVTT.cpp b/clang/lib/CodeGen/CGVTT.cpp index 78928d04220..92fd93b5ca3 100644 --- a/clang/lib/CodeGen/CGVTT.cpp +++ b/clang/lib/CodeGen/CGVTT.cpp @@ -100,7 +100,7 @@ CodeGenVTables::EmitVTTDefinition(llvm::GlobalVariable *VTT, VTT->setComdat(CGM.getModule().getOrInsertComdat(VTT->getName())); // Set the right visibility. - CGM.setGlobalVisibility(VTT, RD, ForDefinition); + CGM.setGlobalVisibility(VTT, RD); } llvm::GlobalVariable *CodeGenVTables::GetAddrOfVTT(const CXXRecordDecl *RD) { diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp index 2d9bf3bce92..67388ee208d 100644 --- a/clang/lib/CodeGen/CGVTables.cpp +++ b/clang/lib/CodeGen/CGVTables.cpp @@ -51,7 +51,7 @@ llvm::Constant *CodeGenModule::GetAddrOfThunk(GlobalDecl GD, static void setThunkVisibility(CodeGenModule &CGM, const CXXMethodDecl *MD, const ThunkInfo &Thunk, llvm::Function *Fn) { - CGM.setGlobalVisibility(Fn, MD, ForDefinition); + CGM.setGlobalVisibility(Fn, MD); } static void setThunkProperties(CodeGenModule &CGM, const ThunkInfo &Thunk, @@ -730,7 +730,7 @@ CodeGenVTables::GenerateConstructionVTable(const CXXRecordDecl *RD, // Create the variable that will hold the construction vtable. llvm::GlobalVariable *VTable = CGM.CreateOrReplaceCXXRuntimeVariable(Name, VTType, Linkage); - CGM.setGlobalVisibility(VTable, RD, ForDefinition); + CGM.setGlobalVisibility(VTable, RD); // V-tables are always unnamed_addr. VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 0d9fab737d7..8d29022b96b 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -662,8 +662,7 @@ llvm::ConstantInt *CodeGenModule::getSize(CharUnits size) { } void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV, - const NamedDecl *D, - ForDefinition_t IsForDefinition) const { + const NamedDecl *D) const { // Internal definitions always have default visibility. if (GV->hasLocalLinkage()) { GV->setVisibility(llvm::GlobalValue::DefaultVisibility); @@ -672,8 +671,7 @@ void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV, // Set visibility for definitions. LinkageInfo LV = D->getLinkageAndVisibility(); - if (LV.isVisibilityExplicit() || - (IsForDefinition && !GV->hasAvailableExternallyLinkage())) + if (LV.isVisibilityExplicit() || !GV->hasAvailableExternallyLinkage()) GV->setVisibility(GetLLVMVisibility(LV.getVisibility())); } @@ -1054,7 +1052,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, void CodeGenModule::SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV) { if (const auto *ND = dyn_cast_or_null<NamedDecl>(D)) - setGlobalVisibility(GV, ND, ForDefinition); + setGlobalVisibility(GV, ND); else GV->setVisibility(llvm::GlobalValue::DefaultVisibility); @@ -1110,8 +1108,8 @@ void CodeGenModule::SetInternalFunctionAttributes(const Decl *D, setNonAliasAttributes(D, F); } -static void setLinkageForGV(llvm::GlobalValue *GV, - const NamedDecl *ND) { +static void setLinkageAndVisibilityForGV(llvm::GlobalValue *GV, + const NamedDecl *ND) { // Set linkage and visibility in case we never see a definition. LinkageInfo LV = ND->getLinkageAndVisibility(); if (!isExternallyVisible(LV.getLinkage())) { @@ -1127,6 +1125,10 @@ static void setLinkageForGV(llvm::GlobalValue *GV, // separate linkage types for this. GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); } + + // Set visibility on a declaration only if it's explicit. + if (LV.isVisibilityExplicit()) + GV->setVisibility(CodeGenModule::GetLLVMVisibility(LV.getVisibility())); } } @@ -1195,8 +1197,7 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F, // Only a few attributes are set on declarations; these may later be // overridden by a definition. - setLinkageForGV(F, FD); - setGlobalVisibility(F, FD, NotForDefinition); + setLinkageAndVisibilityForGV(F, FD); if (FD->getAttr<PragmaClangTextSectionAttr>()) { F->addFnAttr("implicit-section-name"); @@ -2433,8 +2434,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, GV->setAlignment(getContext().getDeclAlign(D).getQuantity()); - setLinkageForGV(GV, D); - setGlobalVisibility(GV, D, NotForDefinition); + setLinkageAndVisibilityForGV(GV, D); if (D->getTLSKind()) { if (D->getTLSKind() == VarDecl::TLS_Dynamic) @@ -3253,7 +3253,7 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD, setFunctionDLLStorageClass(GD, Fn); // FIXME: this is redundant with part of setFunctionDefinitionAttributes - setGlobalVisibility(Fn, D, ForDefinition); + setGlobalVisibility(Fn, D); MaybeHandleStaticInExternC(D, Fn); @@ -3849,7 +3849,7 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary( getModule(), Type, Constant, Linkage, InitialValue, Name.c_str(), /*InsertBefore=*/nullptr, llvm::GlobalVariable::NotThreadLocal, TargetAS); if (emitter) emitter->finalize(GV); - setGlobalVisibility(GV, VD, ForDefinition); + setGlobalVisibility(GV, VD); GV->setAlignment(Align.getQuantity()); if (supportsCOMDAT() && GV->isWeakForLinker()) GV->setComdat(TheModule.getOrInsertComdat(GV->getName())); diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 708ba3cce93..7a47c576c0d 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -710,8 +710,7 @@ public: llvm::ConstantInt *getSize(CharUnits numChars); /// Set the visibility for the given LLVM GlobalValue. - void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D, - ForDefinition_t IsForDefinition) const; + void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const; /// Set the TLS mode for the given LLVM GlobalValue for the thread-local /// variable declaration D. diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index ea5e8dd82c5..3049383a2a6 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -1527,7 +1527,7 @@ void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables &CGVT, VTable->setComdat(CGM.getModule().getOrInsertComdat(VTable->getName())); // Set the right visibility. - CGM.setGlobalVisibility(VTable, RD, ForDefinition); + CGM.setGlobalVisibility(VTable, RD); // Use pointer alignment for the vtable. Otherwise we would align them based // on the size of the initializer which doesn't make sense as only single @@ -1637,7 +1637,6 @@ llvm::GlobalVariable *ItaniumCXXABI::getAddrOfVTable(const CXXRecordDecl *RD, VTable = CGM.CreateOrReplaceCXXRuntimeVariable( Name, VTableType, llvm::GlobalValue::ExternalLinkage); VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); - CGM.setGlobalVisibility(VTable, RD, NotForDefinition); if (RD->hasAttr<DLLImportAttr>()) VTable->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); diff --git a/clang/test/CodeGen/push-hidden-visibility-subclass.cpp b/clang/test/CodeGen/push-hidden-visibility-subclass.cpp deleted file mode 100644 index 3a8c28b6c88..00000000000 --- a/clang/test/CodeGen/push-hidden-visibility-subclass.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// RUN: %clang -S -emit-llvm -o %t %s -// RUN: FileCheck --input-file=%t %s - -#pragma GCC visibility push(hidden) - -struct Base { - virtual ~Base() = default; - virtual void* Alloc() = 0; -}; - -class Child : public Base { -public: - Child() = default; - void* Alloc(); -}; - -void test() { - Child x; -} - -// CHECK: @_ZTV5Child = external hidden unnamed_addr constant |