From d613ac9c57936d219d9eecba1d061a45ff7a3ae8 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 4 Apr 2013 01:51:11 +0000 Subject: [PATCH] Fix 41 of the 61 tests which fail with modules enabled: we were computing and caching the linkage for a declaration before we set up its redeclaration chain, when determining whether a declaration could be a redeclaration of something from an unimported submodule. We actually want to look at the declaration as if it were not a redeclaration here, so compute the linkage but don't cache it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178733 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Decl.h | 4 ++++ lib/AST/Decl.cpp | 4 ++++ lib/Sema/SemaDecl.cpp | 14 ++++++++++++-- test/PCH/chain-late-anonymous-namespace.cpp | 2 ++ test/PCH/cxx-constexpr.cpp | 3 +++ test/Sema/private-extern.c | 1 + test/SemaCXX/linkage2.cpp | 1 + 7 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 0294b9fde8..7927279ddd 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -219,6 +219,10 @@ public: return getLinkage() == ExternalLinkage; } + /// \brief True if this decl has external linkage. Don't cache the linkage, + /// because we are not finished setting up the redecl chain for the decl. + bool hasExternalLinkageUncached() const; + /// \brief Determines the visibility of this entity. Visibility getVisibility() const { return getLinkageAndVisibility().getVisibility(); diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 9505d299ab..bf807aeb1d 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -866,6 +866,10 @@ bool NamedDecl::isLinkageValid() const { Linkage(CachedLinkage); } +bool NamedDecl::hasExternalLinkageUncached() const { + return getLVForDecl(this, LVForExplicitValue).getLinkage() == ExternalLinkage; +} + Linkage NamedDecl::getLinkage() const { if (HasCachedLinkage) return Linkage(CachedLinkage); diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 1288568401..42d7d2bdf5 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1605,8 +1605,18 @@ static void filterNonConflictingPreviousDecls(ASTContext &context, if (previous.empty()) return; - // If this declaration has external - bool hasExternalLinkage = decl->hasExternalLinkage(); + // If this declaration would have external linkage if it were the first + // declaration of this name, then it may in fact be a redeclaration of + // some hidden declaration, so include those too. We don't need to worry + // about some previous visible declaration giving this declaration external + // linkage, because in that case, we'll mark this declaration as a redecl + // of the visible decl, and that decl will already be a redecl of the + // hidden declaration if that's appropriate. + // + // Don't cache this linkage computation, because it's not yet correct: we + // may later give this declaration a previous declaration which changes + // its linkage. + bool hasExternalLinkage = decl->hasExternalLinkageUncached(); LookupResult::Filter filter = previous.makeFilter(); while (filter.hasNext()) { diff --git a/test/PCH/chain-late-anonymous-namespace.cpp b/test/PCH/chain-late-anonymous-namespace.cpp index 87205c631b..edae285c90 100644 --- a/test/PCH/chain-late-anonymous-namespace.cpp +++ b/test/PCH/chain-late-anonymous-namespace.cpp @@ -2,6 +2,8 @@ // RUN: %clang_cc1 -include %s -include %s -fsyntax-only %s // with PCH // RUN: %clang_cc1 -chain-include %s -chain-include %s -fsyntax-only %s +// with PCH, with modules enabled +// RUN: %clang_cc1 -chain-include %s -chain-include %s -fsyntax-only -fmodules %s #if !defined(PASS1) #define PASS1 diff --git a/test/PCH/cxx-constexpr.cpp b/test/PCH/cxx-constexpr.cpp index 8fe48f7377..13f04a7947 100644 --- a/test/PCH/cxx-constexpr.cpp +++ b/test/PCH/cxx-constexpr.cpp @@ -4,6 +4,9 @@ // RUN: %clang_cc1 -pedantic-errors -std=c++11 -emit-pch %s -o %t-cxx11 // RUN: %clang_cc1 -pedantic-errors -std=c++11 -include-pch %t-cxx11 -verify %s +// RUN: %clang_cc1 -pedantic-errors -std=c++98 -emit-pch %s -o %t -fmodules +// RUN: %clang_cc1 -pedantic-errors -std=c++98 -include-pch %t -verify %s -fmodules + #ifndef HEADER_INCLUDED #define HEADER_INCLUDED diff --git a/test/Sema/private-extern.c b/test/Sema/private-extern.c index e480f3f224..e9b67d5070 100644 --- a/test/Sema/private-extern.c +++ b/test/Sema/private-extern.c @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -verify -fsyntax-only -Wno-private-extern %s +// RUN: %clang_cc1 -verify -fsyntax-only -Wno-private-extern -fmodules %s static int g0; // expected-note{{previous definition}} int g0; // expected-error{{non-static declaration of 'g0' follows static declaration}} diff --git a/test/SemaCXX/linkage2.cpp b/test/SemaCXX/linkage2.cpp index 2cee581b49..c2dbf1e308 100644 --- a/test/SemaCXX/linkage2.cpp +++ b/test/SemaCXX/linkage2.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -fmodules %s namespace test1 { int x; // expected-note {{previous definition is here}} -- 2.40.0