]> granicus.if.org Git - clang/commitdiff
Short-circuit a couple of queries (and avoid corrupting
authorJohn McCall <rjmccall@apple.com>
Wed, 29 Jan 2014 08:33:09 +0000 (08:33 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 29 Jan 2014 08:33:09 +0000 (08:33 +0000)
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

lib/Sema/SemaDecl.cpp
test/SemaCXX/linkage.cpp

index a70bece3e892af4518a10f961f91b2f68c336262..a054adfa731f5e5766c0dbb9a06d35ba7bf646c9 100644 (file)
@@ -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())
index 13d295a5d59b03bd252a1dd6c57b0db68f99deb6..46bd3b2441cd8d30968570d032317ef4f0675964 100644 (file)
@@ -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;
+}