summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-01-16 23:11:15 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-01-16 23:11:15 +0000
commitf1d2f0ea21a5a66864da5cd8d39404df5b3fd652 (patch)
treefce2167eb760cedd2d50ac60a7b518cae65912ac /clang/lib/Sema/SemaDecl.cpp
parent3302f2bd466930e094f0197e35835525dcfe7437 (diff)
downloadbcm5719-llvm-f1d2f0ea21a5a66864da5cd8d39404df5b3fd652.tar.gz
bcm5719-llvm-f1d2f0ea21a5a66864da5cd8d39404df5b3fd652.zip
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. llvm-svn: 172667
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 994b2126132..03166546606 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/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>() &&
OpenPOWER on IntegriCloud