[modules] When building a module, if there are multiple matches for a header
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 22 Jun 2015 22:20:47 +0000 (22:20 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 22 Jun 2015 22:20:47 +0000 (22:20 +0000)
file in the loaded module maps and one of them is from the current module,
that's the right match.

llvm-svn: 240350

clang/lib/Lex/ModuleMap.cpp
clang/test/Modules/Inputs/explicit-build-prefer-self/a.h [new file with mode: 0644]
clang/test/Modules/Inputs/explicit-build-prefer-self/b.h [new file with mode: 0644]
clang/test/Modules/Inputs/explicit-build-prefer-self/map [new file with mode: 0644]
clang/test/Modules/Inputs/explicit-build-prefer-self/x.h [new file with mode: 0644]
clang/test/Modules/explicit-build-prefer-self.cpp [new file with mode: 0644]

index 075a17f..4ef0674 100644 (file)
@@ -346,6 +346,9 @@ ModuleMap::KnownHeader ModuleMap::findModuleForHeader(const FileEntry *File) {
     ModuleMap::KnownHeader Result;
     // Iterate over all modules that 'File' is part of to find the best fit.
     for (KnownHeader &H : Known->second) {
+      // Prefer a header from the current module over all others.
+      if (H.getModule() == CompilingModule)
+        return MakeResult(H);
       // Cannot use a module if it is unavailable.
       if (!H.getModule()->isAvailable())
         continue;
diff --git a/clang/test/Modules/Inputs/explicit-build-prefer-self/a.h b/clang/test/Modules/Inputs/explicit-build-prefer-self/a.h
new file mode 100644 (file)
index 0000000..d457612
--- /dev/null
@@ -0,0 +1,2 @@
+// a
+#include "x.h"
diff --git a/clang/test/Modules/Inputs/explicit-build-prefer-self/b.h b/clang/test/Modules/Inputs/explicit-build-prefer-self/b.h
new file mode 100644 (file)
index 0000000..76e2042
--- /dev/null
@@ -0,0 +1,2 @@
+// b
+#include "x.h"
diff --git a/clang/test/Modules/Inputs/explicit-build-prefer-self/map b/clang/test/Modules/Inputs/explicit-build-prefer-self/map
new file mode 100644 (file)
index 0000000..26be8e6
--- /dev/null
@@ -0,0 +1,2 @@
+module a { header "a.h" header "x.h" }
+module b { header "b.h" header "x.h" }
diff --git a/clang/test/Modules/Inputs/explicit-build-prefer-self/x.h b/clang/test/Modules/Inputs/explicit-build-prefer-self/x.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/clang/test/Modules/explicit-build-prefer-self.cpp b/clang/test/Modules/explicit-build-prefer-self.cpp
new file mode 100644 (file)
index 0000000..aa21979
--- /dev/null
@@ -0,0 +1,3 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fno-implicit-modules -emit-module -fmodule-name=a %S/Inputs/explicit-build-prefer-self/map -o a.pcm
+// RUN: %clang_cc1 -fmodules -fno-implicit-modules -emit-module -fmodule-name=b %S/Inputs/explicit-build-prefer-self/map -o b.pcm