From d5ed033d561848aa1552140a779b7d4250bdd207 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 12 Nov 2012 04:10:23 +0000 Subject: [PATCH] In Sema::MergeVarDecl we handle merging of storage classes and visibility attributes. In cases where the merged declaration is fully equivalent to the two original ones, some of the code was getLVForDecl was duplicated. Cases that are still handled in getLVForDecl are things like __private_extern__ int N; int N; For which we cannot produce a single merged decl with all the information. llvm-svn: 167703 --- clang/lib/AST/Decl.cpp | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 6a51edf7b906..7b13755979f1 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -341,25 +341,9 @@ static LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D, if (Var->getStorageClass() == SC_PrivateExtern) LV.mergeVisibility(HiddenVisibility, true); - if (!Context.getLangOpts().CPlusPlus && - (Var->getStorageClass() == SC_Extern || - Var->getStorageClass() == SC_PrivateExtern)) { - - // C99 6.2.2p4: - // For an identifier declared with the storage-class specifier - // extern in a scope in which a prior declaration of that - // identifier is visible, if the prior declaration specifies - // internal or external linkage, the linkage of the identifier - // at the later declaration is the same as the linkage - // specified at the prior declaration. If no prior declaration - // is visible, or if the prior declaration specifies no - // linkage, then the identifier has external linkage. - if (const VarDecl *PrevVar = Var->getPreviousDecl()) { - LinkageInfo PrevLV = getLVForDecl(PrevVar, OnlyTemplate); - if (PrevLV.linkage()) LV.setLinkage(PrevLV.linkage()); - LV.mergeVisibility(PrevLV); - } - } + // Note that Sema::MergeVarDecl already takes care of implementing + // C99 6.2.2p4 and propagating the visibility attribute, so we don't have + // to do it here. // - a function, unless it has internal linkage; or } else if (const FunctionDecl *Function = dyn_cast(D)) { @@ -841,13 +825,10 @@ static LinkageInfo getLVForDecl(const NamedDecl *D, bool OnlyTemplate) { if (llvm::Optional Vis = Var->getExplicitVisibility()) LV.mergeVisibility(*Vis, true); } - - if (const VarDecl *Prev = Var->getPreviousDecl()) { - LinkageInfo PrevLV = getLVForDecl(Prev, OnlyTemplate); - if (PrevLV.linkage()) LV.setLinkage(PrevLV.linkage()); - LV.mergeVisibility(PrevLV); - } + // Note that Sema::MergeVarDecl already takes care of implementing + // C99 6.2.2p4 and propagating the visibility attribute, so we don't + // have to do it here. return LV; } } -- GitLab