]> granicus.if.org Git - clang/commitdiff
When we leave a module header, make that header visible in its
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 12 Sep 2018 23:09:23 +0000 (23:09 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 12 Sep 2018 23:09:23 +0000 (23:09 +0000)
includer's context, even if its overall module is unavailable.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342096 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/Module.cpp
test/Modules/Inputs/unavailable-local-visibility/a.h [new file with mode: 0644]
test/Modules/Inputs/unavailable-local-visibility/b.h [new file with mode: 0644]
test/Modules/Inputs/unavailable-local-visibility/module.modulemap [new file with mode: 0644]
test/Modules/Inputs/unavailable-local-visibility/x.h [new file with mode: 0644]
test/Modules/unavailable-local-visibility.test [new file with mode: 0644]

index 1a0c190590589472d6234ccd5730e7f6a89cb5c1..9ff976c03b9c36c8c6a5c82a46718d96033b5c34 100644 (file)
@@ -577,10 +577,6 @@ void VisibleModuleSet::setVisible(Module *M, SourceLocation Loc,
   };
 
   std::function<void(Visiting)> VisitModule = [&](Visiting V) {
-    // Modules that aren't available cannot be made visible.
-    if (!V.M->isAvailable())
-      return;
-
     // Nothing to do for a module that's already visible.
     unsigned ID = V.M->getVisibilityID();
     if (ImportLocs.size() <= ID)
@@ -594,8 +590,11 @@ void VisibleModuleSet::setVisible(Module *M, SourceLocation Loc,
     // Make any exported modules visible.
     SmallVector<Module *, 16> Exports;
     V.M->getExportedModules(Exports);
-    for (Module *E : Exports)
-      VisitModule({E, &V});
+    for (Module *E : Exports) {
+      // Don't recurse to unavailable submodules.
+      if (E->isAvailable())
+        VisitModule({E, &V});
+    }
 
     for (auto &C : V.M->Conflicts) {
       if (isVisible(C.Other)) {
diff --git a/test/Modules/Inputs/unavailable-local-visibility/a.h b/test/Modules/Inputs/unavailable-local-visibility/a.h
new file mode 100644 (file)
index 0000000..865bb65
--- /dev/null
@@ -0,0 +1,4 @@
+#ifndef A_H
+#define A_H
+#include "x.h"
+#endif
diff --git a/test/Modules/Inputs/unavailable-local-visibility/b.h b/test/Modules/Inputs/unavailable-local-visibility/b.h
new file mode 100644 (file)
index 0000000..71360e3
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef B_H
+#define B_H
+#include "a.h"
+
+#ifndef A_H
+#error where is a?
+#endif
+
+#ifndef X_H
+#error where is x?
+#endif
+X f();
+#endif
diff --git a/test/Modules/Inputs/unavailable-local-visibility/module.modulemap b/test/Modules/Inputs/unavailable-local-visibility/module.modulemap
new file mode 100644 (file)
index 0000000..8da3d3c
--- /dev/null
@@ -0,0 +1,9 @@
+module M {
+  module a { header "a.h" export * }
+  module b { header "b.h" export * }
+  module doesnotexist { header "doesnotexist.h" }
+}
+module X {
+  header "x.h"
+  export *
+}
diff --git a/test/Modules/Inputs/unavailable-local-visibility/x.h b/test/Modules/Inputs/unavailable-local-visibility/x.h
new file mode 100644 (file)
index 0000000..0498c5d
--- /dev/null
@@ -0,0 +1,4 @@
+#ifndef X_H
+#define X_H
+struct X {};
+#endif
diff --git a/test/Modules/unavailable-local-visibility.test b/test/Modules/unavailable-local-visibility.test
new file mode 100644 (file)
index 0000000..10b316a
--- /dev/null
@@ -0,0 +1,2 @@
+// RUN: %clang_cc1 -fmodules -I%S/Inputs/unavailable-local-visibility -fmodule-name=X -emit-module -x c++-module-map %S/Inputs/unavailable-local-visibility/module.modulemap -o %t/x.pcm
+// RUN: %clang_cc1 -fmodules -I%S/Inputs/unavailable-local-visibility -fmodule-name=M -fmodule-map-file=%S/Inputs/unavailable-local-visibility/module.modulemap -fmodules-local-submodule-visibility -fmodule-file=%t/x.pcm -fsyntax-only -x c++-header %S/Inputs/unavailable-local-visibility/b.h