diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-01-16 23:11:15 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-01-16 23:11:15 +0000 |
commit | 2a5bb509e2d33a0f7aa4bb0ba53c73b5dfdd6bb4 (patch) | |
tree | 7c6012abbb1658a5d441bb07d58a7502fc6f7805 /lib/Sema | |
parent | 4f918aed75d4927e88365541c7200f0b5fe5014b (diff) |
Check for internal weak decls after merging.
This fixes pr14946. The problem was that the linkage computation was done too
early, so things like "extern int a;" would be given external linkage, even if
a previous declaration was static.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172667 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 13 | ||||
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 6 |
2 files changed, 13 insertions, 6 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 994b212613..0316654660 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4312,6 +4312,15 @@ bool Sema::inferObjCARCLifetime(ValueDecl *decl) { return false; } +static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) { + // 'weak' only applies to declarations with external linkage. + WeakAttr *WA = ND.getAttr<WeakAttr>(); + if (WA && ND.getLinkage() != ExternalLinkage) { + S.Diag(WA->getLocation(), diag::err_attribute_weak_static); + ND.dropAttr<WeakAttr>(); + } +} + NamedDecl* Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo, LookupResult &Previous, @@ -4590,6 +4599,8 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, NewVD->setInvalidDecl(); } + checkAttributesAfterMerging(*this, *NewVD); + // If this is a locally-scoped extern C variable, update the map of // such variables. if (CurContext->isFunctionOrMethod() && NewVD->isExternC() && @@ -6056,6 +6067,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, } } + checkAttributesAfterMerging(*this, *NewFD); + AddKnownFunctionAttributes(NewFD); if (NewFD->hasAttr<OverloadableAttr>() && diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 85f48ecff3..efeafa697f 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -2511,12 +2511,6 @@ static void handleWeakAttr(Sema &S, Decl *D, const AttributeList &Attr) { NamedDecl *nd = cast<NamedDecl>(D); - // 'weak' only applies to declarations with external linkage. - if (hasEffectivelyInternalLinkage(nd)) { - S.Diag(Attr.getLoc(), diag::err_attribute_weak_static); - return; - } - nd->addAttr(::new (S.Context) WeakAttr(Attr.getRange(), S.Context)); } |