From 1fb0caaa7bef765b85972274e3b434af2572c141 Mon Sep 17 00:00:00 2001 From: John McCall Date: Fri, 22 Oct 2010 21:05:15 +0000 Subject: Substantially revise how clang computes the visibility of a declaration to more closely parallel the computation of linkage. This gets us to a state much closer to what gcc emits, modulo bugs, which will undoubtedly arise in abundance. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117147 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 75 ++++++------------------------------------- 1 file changed, 10 insertions(+), 65 deletions(-) (limited to 'lib/CodeGen/CodeGenModule.cpp') diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 9199f6cfbd..d35965e2c4 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -164,81 +164,23 @@ void CodeGenModule::ErrorUnsupported(const Decl *D, const char *Type, getDiags().Report(Context.getFullLoc(D->getLocation()), DiagID) << Msg; } -LangOptions::VisibilityMode -CodeGenModule::getDeclVisibilityMode(const Decl *D) const { - if (const VarDecl *VD = dyn_cast(D)) - if (VD->getStorageClass() == SC_PrivateExtern) - return LangOptions::Hidden; - - if (const VisibilityAttr *attr = D->getAttr()) { - switch (attr->getVisibility()) { - default: assert(0 && "Unknown visibility!"); - case VisibilityAttr::Default: - return LangOptions::Default; - case VisibilityAttr::Hidden: - return LangOptions::Hidden; - case VisibilityAttr::Protected: - return LangOptions::Protected; - } - } - - if (getLangOptions().CPlusPlus) { - // Entities subject to an explicit instantiation declaration get default - // visibility. - if (const FunctionDecl *Function = dyn_cast(D)) { - if (Function->getTemplateSpecializationKind() - == TSK_ExplicitInstantiationDeclaration) - return LangOptions::Default; - } else if (const ClassTemplateSpecializationDecl *ClassSpec - = dyn_cast(D)) { - if (ClassSpec->getSpecializationKind() - == TSK_ExplicitInstantiationDeclaration) - return LangOptions::Default; - } else if (const CXXRecordDecl *Record = dyn_cast(D)) { - if (Record->getTemplateSpecializationKind() - == TSK_ExplicitInstantiationDeclaration) - return LangOptions::Default; - } else if (const VarDecl *Var = dyn_cast(D)) { - if (Var->isStaticDataMember() && - (Var->getTemplateSpecializationKind() - == TSK_ExplicitInstantiationDeclaration)) - return LangOptions::Default; - } - - // If -fvisibility-inlines-hidden was provided, then inline C++ member - // functions get "hidden" visibility by default. - if (getLangOptions().InlineVisibilityHidden) - if (const CXXMethodDecl *Method = dyn_cast(D)) - if (Method->isInlined()) - return LangOptions::Hidden; - } - - // If this decl is contained in a class, it should have the same visibility - // as the parent class. - if (const DeclContext *DC = D->getDeclContext()) - if (DC->isRecord()) - return getDeclVisibilityMode(cast(DC)); - - return getLangOptions().getVisibilityMode(); -} - void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV, - const Decl *D) const { + const NamedDecl *D) const { // Internal definitions always have default visibility. if (GV->hasLocalLinkage()) { GV->setVisibility(llvm::GlobalValue::DefaultVisibility); return; } - switch (getDeclVisibilityMode(D)) { - default: assert(0 && "Unknown visibility!"); - case LangOptions::Default: + switch (D->getVisibility()) { + case DefaultVisibility: return GV->setVisibility(llvm::GlobalValue::DefaultVisibility); - case LangOptions::Hidden: + case HiddenVisibility: return GV->setVisibility(llvm::GlobalValue::HiddenVisibility); - case LangOptions::Protected: + case ProtectedVisibility: return GV->setVisibility(llvm::GlobalValue::ProtectedVisibility); } + llvm_unreachable("unknown visibility!"); } /// Set the symbol visibility of type information (vtable and RTTI) @@ -498,7 +440,10 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, void CodeGenModule::SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV) { - setGlobalVisibility(GV, D); + if (isa(D)) + setGlobalVisibility(GV, cast(D)); + else + GV->setVisibility(llvm::GlobalValue::DefaultVisibility); if (D->hasAttr()) AddUsedGlobal(GV); -- cgit v1.2.3-70-g09d2