r230558 - [modules] Even if we already have a definition of a class, loading in another

Richard Smith richard-llvm at metafoo.co.uk
Wed Feb 25 14:20:13 PST 2015


Author: rsmith
Date: Wed Feb 25 16:20:13 2015
New Revision: 230558

URL: http://llvm.org/viewvc/llvm-project?rev=230558&view=rev
Log:
[modules] Even if we already have a definition of a class, loading in another
one can give us more lookup results (due to implicit special members). Be sure
to complete the redecl chain for every kind of DeclContext before performing a
lookup into it, rather than only doing so for NamespaceDecls.

Added:
    cfe/trunk/test/Modules/Inputs/merge-decl-context/
    cfe/trunk/test/Modules/Inputs/merge-decl-context/a.h
    cfe/trunk/test/Modules/Inputs/merge-decl-context/b.h
    cfe/trunk/test/Modules/Inputs/merge-decl-context/c.h
    cfe/trunk/test/Modules/Inputs/merge-decl-context/merge-decl-context.modulemap
    cfe/trunk/test/Modules/merge-decl-context.cpp
Modified:
    cfe/trunk/lib/AST/DeclBase.cpp
    cfe/trunk/lib/Frontend/CompilerInstance.cpp

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=230558&r1=230557&r2=230558&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Wed Feb 25 16:20:13 2015
@@ -1308,12 +1308,16 @@ DeclContext::lookup(DeclarationName Name
   if (PrimaryContext != this)
     return PrimaryContext->lookup(Name);
 
-  // If this is a namespace, ensure that any later redeclarations of it have
-  // been loaded, since they may add names to the result of this lookup.
-  if (auto *ND = dyn_cast<NamespaceDecl>(this))
-    (void)ND->getMostRecentDecl();
+  // If we have an external source, ensure that any later redeclarations of this
+  // context have been loaded, since they may add names to the result of this
+  // lookup (or add external visible storage).
+  ExternalASTSource *Source = getParentASTContext().getExternalSource();
+  if (Source)
+    (void)cast<Decl>(this)->getMostRecentDecl();
 
   if (hasExternalVisibleStorage()) {
+    assert(Source && "external visible storage but no external source?");
+
     if (NeedToReconcileExternalVisibleStorage)
       reconcileExternalVisibleStorage();
 
@@ -1332,7 +1336,6 @@ DeclContext::lookup(DeclarationName Name
     if (!R.second && !R.first->second.hasExternalDecls())
       return R.first->second.getLookupResult();
 
-    ExternalASTSource *Source = getParentASTContext().getExternalSource();
     if (Source->FindExternalVisibleDeclsByName(this, Name) || !R.second) {
       if (StoredDeclsMap *Map = LookupPtr.getPointer()) {
         StoredDeclsMap::iterator I = Map->find(Name);

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=230558&r1=230557&r2=230558&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Wed Feb 25 16:20:13 2015
@@ -1288,8 +1288,11 @@ bool CompilerInstance::loadModuleFile(St
     bool needsImportVisitation() const override { return true; }
 
     void visitImport(StringRef FileName) override {
-      if (!CI.ExplicitlyLoadedModuleFiles.insert(FileName).second)
+      if (!CI.ExplicitlyLoadedModuleFiles.insert(FileName).second) {
+        if (ModuleFileStack.size() == 0)
+          TopFileIsModule = true;
         return;
+      }
 
       ModuleFileStack.push_back(FileName);
       if (ASTReader::readASTFileControlBlock(FileName, CI.getFileManager(),

Added: cfe/trunk/test/Modules/Inputs/merge-decl-context/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-decl-context/a.h?rev=230558&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-decl-context/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/merge-decl-context/a.h Wed Feb 25 16:20:13 2015
@@ -0,0 +1,22 @@
+#ifndef A_H
+#define A_H
+
+template <typename T>
+struct A {
+  template <typename I>
+  A(I i1, I i2) {
+  }
+  A(double) {}
+  A(double, double) {}
+};
+
+template <typename T1, typename T2>
+T1 fff(T2* t) {
+  return T1(t, t);
+}
+
+inline A<int> ff(int i) {
+  return fff<A<int>>(&i);
+}
+
+#endif

Added: cfe/trunk/test/Modules/Inputs/merge-decl-context/b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-decl-context/b.h?rev=230558&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-decl-context/b.h (added)
+++ cfe/trunk/test/Modules/Inputs/merge-decl-context/b.h Wed Feb 25 16:20:13 2015
@@ -0,0 +1,6 @@
+#ifndef B_H
+#define B_H
+
+#include "a.h"
+
+#endif

Added: cfe/trunk/test/Modules/Inputs/merge-decl-context/c.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-decl-context/c.h?rev=230558&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-decl-context/c.h (added)
+++ cfe/trunk/test/Modules/Inputs/merge-decl-context/c.h Wed Feb 25 16:20:13 2015
@@ -0,0 +1,7 @@
+#ifndef C_H
+#define C_H
+
+#include "a.h"
+#include "b.h"
+
+#endif

Added: cfe/trunk/test/Modules/Inputs/merge-decl-context/merge-decl-context.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-decl-context/merge-decl-context.modulemap?rev=230558&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-decl-context/merge-decl-context.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/merge-decl-context/merge-decl-context.modulemap Wed Feb 25 16:20:13 2015
@@ -0,0 +1,13 @@
+module "a" {
+  textual header "a.h"
+}
+
+module "b" {
+  export *
+  header "b.h"
+}
+
+module "c" {
+  export *
+  header "c.h"
+}

Added: cfe/trunk/test/Modules/merge-decl-context.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/merge-decl-context.cpp?rev=230558&view=auto
==============================================================================
--- cfe/trunk/test/Modules/merge-decl-context.cpp (added)
+++ cfe/trunk/test/Modules/merge-decl-context.cpp Wed Feb 25 16:20:13 2015
@@ -0,0 +1,24 @@
+// RUN: rm -rf %t
+
+// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodule-name=b -o %t/b.pcm -fmodule-maps \
+// RUN:     -emit-module %S/Inputs/merge-decl-context/merge-decl-context.modulemap -I%S/Inputs \
+// RUN:     -I %S/Inputs/merge-decl-context
+// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodule-name=c -o %t/c.pcm -fmodule-maps \
+// RUN:     -fmodule-file=%t/b.pcm \
+// RUN:     -emit-module %S/Inputs/merge-decl-context/merge-decl-context.modulemap -I%S/Inputs \
+// RUN:     -I %S/Inputs/merge-decl-context
+
+// Use the two modules in a single compile.
+// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodule-file=%t/c.pcm -fmodule-file=%t/b.pcm \
+// RUN:     -fmodule-map-file=%S/Inputs/merge-decl-context/merge-decl-context.modulemap -I%S/Inputs \
+// RUN:     -emit-llvm -o %t/test.o %s
+
+#include "Inputs/merge-decl-context/a.h"
+#include "Inputs/merge-decl-context/b.h"
+#include "Inputs/merge-decl-context/c.h"
+
+void t() {
+  ff(42);
+}
+
+





More information about the cfe-commits mailing list