]> granicus.if.org Git - clang/commitdiff
Fix 41 of the 61 tests which fail with modules enabled: we were computing and
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 4 Apr 2013 01:51:11 +0000 (01:51 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 4 Apr 2013 01:51:11 +0000 (01:51 +0000)
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
lib/AST/Decl.cpp
lib/Sema/SemaDecl.cpp
test/PCH/chain-late-anonymous-namespace.cpp
test/PCH/cxx-constexpr.cpp
test/Sema/private-extern.c
test/SemaCXX/linkage2.cpp

index 0294b9fde8af5177898312e365ff0b3599cb6546..7927279ddd6d4276de665db93b9f780ccca71507 100644 (file)
@@ -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();
index 9505d299ab1debfc7990d2bcd1a465b141f38069..bf807aeb1d690de662c2c3b34f69e2ace42dcd94 100644 (file)
@@ -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);
index 12885684016294b522de84c123a9624ec800fc42..42d7d2bdf5fb2a0a7a839097f64857dc73fdad80 100644 (file)
@@ -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()) {
index 87205c631b3a8adbc02b36261493e6348e125d67..edae285c9084eeff0d0a63f6d0ae8c289fccf366 100644 (file)
@@ -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
 
index 8fe48f7377ec1403effe466a9c2d7384ad324f94..13f04a79477b652cef40e397248c95b0a496ec78 100644 (file)
@@ -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
index e480f3f224811340bf8fd734cfe65ec1430aeb27..e9b67d5070b5212761ff63529cb899f4a2ee0829 100644 (file)
@@ -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}}
index 2cee581b49c1c57dc4721afac237437d0c7eb5d7..c2dbf1e3085d29580c60f9b253b6de8a3eab668c 100644 (file)
@@ -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}}