]> granicus.if.org Git - clang/commitdiff
Make sure pragmas don't attach visibility attributes to auto variables with
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 22 Feb 2013 17:59:16 +0000 (17:59 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 22 Feb 2013 17:59:16 +0000 (17:59 +0000)
internal linkage.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175903 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/auto-pragma.cpp [new file with mode: 0644]

index f062c0386d1bcbfc608a66b2cece9b412b71cba5..20c1b1015e40da6f521862ad95fbdfcdce096107 100644 (file)
@@ -4908,11 +4908,6 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
       !NewVD->isInvalidDecl())
     RegisterLocallyScopedExternCDecl(NewVD, Previous, S);
 
-  // If there's a #pragma GCC visibility in scope, and this isn't a class
-  // member, set the visibility of this variable.
-  if (NewVD->getLinkage() == ExternalLinkage && !DC->isRecord())
-    AddPushedVisibilityAttribute(NewVD);
-
   return NewVD;
 }
 
@@ -7880,10 +7875,16 @@ Sema::FinalizeDeclaration(Decl *ThisDecl) {
   // Note that we are no longer parsing the initializer for this declaration.
   ParsingInitForAutoVars.erase(ThisDecl);
 
-  const VarDecl *VD = dyn_cast_or_null<VarDecl>(ThisDecl);
+  VarDecl *VD = dyn_cast_or_null<VarDecl>(ThisDecl);
   if (!VD)
     return;
 
+  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 (VD->getLinkage() == ExternalLinkage && !DC->isRecord())
+    AddPushedVisibilityAttribute(VD);
+
   if (VD->isFileVarDecl())
     MarkUnusedFileScopedDecl(VD);
 
diff --git a/test/SemaCXX/auto-pragma.cpp b/test/SemaCXX/auto-pragma.cpp
new file mode 100644 (file)
index 0000000..1cd0781
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -ast-dump -ast-dump-filter AutoVar | FileCheck %s
+
+namespace {
+  class foo {
+  };
+}
+
+#pragma GCC visibility push(hidden)
+auto AutoVar = foo();
+
+// CHECK: VarDecl {{.*}} AutoVar
+// CHECK-NOT: VisibilityAttr