[PATCH] D86802: [Modules] Don't parse/load explicit module maps if modules are disabled

Andrew Gallagher via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 28 13:32:04 PDT 2020


andrewjcg updated this revision to Diff 288695.
andrewjcg added a comment.

add test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86802/new/

https://reviews.llvm.org/D86802

Files:
  clang/lib/Frontend/FrontendAction.cpp
  clang/test/Modules/Inputs/explicit-module-maps/invalid.modulemap
  clang/test/Modules/explicit-module-maps.cpp


Index: clang/test/Modules/explicit-module-maps.cpp
===================================================================
--- /dev/null
+++ clang/test/Modules/explicit-module-maps.cpp
@@ -0,0 +1,5 @@
+// Test that an explicit module map (which fails to parse/load in this case)
+// isn't used if modules aren't enabled.
+
+// RUN: %clang_cc1 -fmodule-map-file=%S/Inputs/explicit-module-maps/invalid.modulemap -verify %s
+// expected-no-diagnostics
Index: clang/test/Modules/Inputs/explicit-module-maps/invalid.modulemap
===================================================================
--- /dev/null
+++ clang/test/Modules/Inputs/explicit-module-maps/invalid.modulemap
@@ -0,0 +1 @@
+DOES NOT PARSE!
Index: clang/lib/Frontend/FrontendAction.cpp
===================================================================
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -807,12 +807,14 @@
     goto failure;
 
   // If we were asked to load any module map files, do so now.
-  for (const auto &Filename : CI.getFrontendOpts().ModuleMapFiles) {
-    if (auto File = CI.getFileManager().getFile(Filename))
-      CI.getPreprocessor().getHeaderSearchInfo().loadModuleMapFile(
-          *File, /*IsSystem*/false);
-    else
-      CI.getDiagnostics().Report(diag::err_module_map_not_found) << Filename;
+  if (CI.getLangOpts().Modules) {
+    for (const auto &Filename : CI.getFrontendOpts().ModuleMapFiles) {
+      if (auto File = CI.getFileManager().getFile(Filename))
+        CI.getPreprocessor().getHeaderSearchInfo().loadModuleMapFile(
+            *File, /*IsSystem*/ false);
+      else
+        CI.getDiagnostics().Report(diag::err_module_map_not_found) << Filename;
+    }
   }
 
   // Add a module declaration scope so that modules from -fmodule-map-file


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86802.288695.patch
Type: text/x-patch
Size: 1793 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200828/cbbda23a/attachment.bin>


More information about the cfe-commits mailing list