From 2a5bb509e2d33a0f7aa4bb0ba53c73b5dfdd6bb4 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 16 Jan 2013 23:11:15 +0000 Subject: 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 --- lib/Sema/SemaDecl.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/Sema/SemaDecl.cpp') 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(); + if (WA && ND.getLinkage() != ExternalLinkage) { + S.Diag(WA->getLocation(), diag::err_attribute_weak_static); + ND.dropAttr(); + } +} + 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() && -- cgit v1.2.3-70-g09d2