r178741 - Add hasExternalLinkageUncached back with the test that Richard provided, but

Rafael Espindola rafael.espindola at gmail.com
Wed Apr 3 21:40:18 PDT 2013


Author: rafael
Date: Wed Apr  3 23:40:17 2013
New Revision: 178741

URL: http://llvm.org/viewvc/llvm-project?rev=178741&view=rev
Log:
Add hasExternalLinkageUncached back with the test that Richard provided, but
keep the call at the current location.

Added:
    cfe/trunk/test/Modules/Inputs/linkage-merge-bar.h
    cfe/trunk/test/Modules/Inputs/linkage-merge-foo.h
    cfe/trunk/test/Modules/linkage-merge.cpp
Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Modules/Inputs/module.map

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=178741&r1=178740&r2=178741&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Apr  3 23:40:17 2013
@@ -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();

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=178741&r1=178740&r2=178741&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Wed Apr  3 23:40:17 2013
@@ -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);

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=178741&r1=178740&r2=178741&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Apr  3 23:40:17 2013
@@ -1614,7 +1614,19 @@ static void filterNonConflictingPrevious
       continue;
 
     // If either has no-external linkage, ignore the old declaration.
-    if (old->getLinkage() != ExternalLinkage || !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.
+    if (old->getLinkage() != ExternalLinkage ||
+        !decl->hasExternalLinkageUncached())
       filter.erase();
   }
 

Added: cfe/trunk/test/Modules/Inputs/linkage-merge-bar.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/linkage-merge-bar.h?rev=178741&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Modules/Inputs/linkage-merge-foo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/linkage-merge-foo.h?rev=178741&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/linkage-merge-foo.h (added)
+++ cfe/trunk/test/Modules/Inputs/linkage-merge-foo.h Wed Apr  3 23:40:17 2013
@@ -0,0 +1 @@
+int f();

Modified: cfe/trunk/test/Modules/Inputs/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module.map?rev=178741&r1=178740&r2=178741&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/module.map Wed Apr  3 23:40:17 2013
@@ -199,3 +199,13 @@ module builtin {
     header "builtin_sub.h"
   }
 }
+
+module linkage_merge {
+  explicit module foo {
+    header "linkage-merge-foo.h"
+  }
+  explicit module bar {
+    header "linkage-merge-bar.h"
+  }
+
+}

Added: cfe/trunk/test/Modules/linkage-merge.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/linkage-merge.cpp?rev=178741&view=auto
==============================================================================
--- cfe/trunk/test/Modules/linkage-merge.cpp (added)
+++ cfe/trunk/test/Modules/linkage-merge.cpp Wed Apr  3 23:40:17 2013
@@ -0,0 +1,7 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs %s
+
+#include "linkage-merge-bar.h"
+
+static int f(int);
+int f(int);





More information about the cfe-commits mailing list