From db1a47706bc4d849b5492e2beb066e538a8c4a84 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 22 Feb 2013 17:59:16 +0000 Subject: [PATCH] Make sure pragmas don't attach visibility attributes to auto variables with internal linkage. llvm-svn: 175903 --- clang/lib/Sema/SemaDecl.cpp | 13 +++++++------ clang/test/SemaCXX/auto-pragma.cpp | 12 ++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 clang/test/SemaCXX/auto-pragma.cpp diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index f062c03..20c1b10 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -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(ThisDecl); + VarDecl *VD = dyn_cast_or_null(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/clang/test/SemaCXX/auto-pragma.cpp b/clang/test/SemaCXX/auto-pragma.cpp new file mode 100644 index 0000000..1cd0781 --- /dev/null +++ b/clang/test/SemaCXX/auto-pragma.cpp @@ -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 -- 2.7.4