From: John McCall Date: Wed, 29 Jan 2014 08:33:09 +0000 (+0000) Subject: Short-circuit a couple of queries (and avoid corrupting X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=44f56e4c8797dc691c3bf57af2a0910b7f110991;p=clang Short-circuit a couple of queries (and avoid corrupting the linkage cache) when type-checking static local variables. There's a very deep problem here where the linkage of a declaration can suddenly massively change as soon as it's given a typedef name; these fixes, while optimizations in their own right, are really just targeted workarounds. rdar://15928125 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200380 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index a70bece3e8..a054adfa73 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -8773,7 +8773,13 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) { } } + // Warn about externally-visible variables being defined without a + // prior declaration. We only want to do this for global + // declarations, but we also specifically need to avoid doing it for + // class members because the linkage of an anonymous class can + // change if it's later given a typedef name. if (var->isThisDeclarationADefinition() && + var->getDeclContext()->getRedeclContext()->isFileContext() && var->isExternallyVisible() && var->hasLinkage() && getDiagnostics().getDiagnosticLevel( diag::warn_missing_variable_declarations, @@ -8910,7 +8916,7 @@ Sema::FinalizeDeclaration(Decl *ThisDecl) { const DeclContext *DC = VD->getDeclContext(); // If there's a #pragma GCC visibility in scope, and this isn't a class // member, set the visibility of this variable. - if (!DC->isRecord() && VD->isExternallyVisible()) + if (DC->getRedeclContext()->isFileContext() && VD->isExternallyVisible()) AddPushedVisibilityAttribute(VD); if (VD->isFileVarDecl()) diff --git a/test/SemaCXX/linkage.cpp b/test/SemaCXX/linkage.cpp index 13d295a5d5..46bd3b2441 100644 --- a/test/SemaCXX/linkage.cpp +++ b/test/SemaCXX/linkage.cpp @@ -103,3 +103,13 @@ namespace test5 { }; } } + +// Test that we don't compute linkage too hastily before we're done +// processing a record decl. rdar://15928125 +namespace test6 { + typedef struct { + void foo() { + static int bar = 0; + } + } A; +}