summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Lex/HeaderSearch.h6
-rw-r--r--clang/lib/Lex/HeaderSearch.cpp5
-rw-r--r--clang/test/Modules/unnecessary-module-map-parsing.c8
-rw-r--r--clang/test/Modules/unnecessary-module-map-parsing/a1.h1
-rw-r--r--clang/test/Modules/unnecessary-module-map-parsing/module.map3
5 files changed, 23 insertions, 0 deletions
diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h
index fb1a8620635..283bd5714f0 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -232,6 +232,8 @@ class HeaderSearch {
unsigned NumMultiIncludeFileOptzn;
unsigned NumFrameworkLookups, NumSubFrameworkLookups;
+ bool EnabledModules;
+
// HeaderSearch doesn't support default or copy construction.
HeaderSearch(const HeaderSearch&) LLVM_DELETED_FUNCTION;
void operator=(const HeaderSearch&) LLVM_DELETED_FUNCTION;
@@ -458,6 +460,9 @@ public:
/// FileEntry, uniquing them through the 'HeaderMaps' datastructure.
const HeaderMap *CreateHeaderMap(const FileEntry *FE);
+ /// Returns true if modules are enabled.
+ bool enabledModules() const { return EnabledModules; }
+
/// \brief Retrieve the name of the module file that should be used to
/// load the given module.
///
@@ -491,6 +496,7 @@ public:
/// \brief Determine whether there is a module map that may map the header
/// with the given file name to a (sub)module.
+ /// Always returns false if modules are disabled.
///
/// \param Filename The name of the file.
///
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 9e43dda226b..5770aaadf40 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -59,6 +59,8 @@ HeaderSearch::HeaderSearch(IntrusiveRefCntPtr<HeaderSearchOptions> HSOpts,
NumIncluded = 0;
NumMultiIncludeFileOptzn = 0;
NumFrameworkLookups = NumSubFrameworkLookups = 0;
+
+ EnabledModules = LangOpts.Modules;
}
HeaderSearch::~HeaderSearch() {
@@ -953,6 +955,9 @@ StringRef HeaderSearch::getUniqueFrameworkName(StringRef Framework) {
bool HeaderSearch::hasModuleMap(StringRef FileName,
const DirectoryEntry *Root,
bool IsSystem) {
+ if (!enabledModules())
+ return false;
+
SmallVector<const DirectoryEntry *, 2> FixUpDirectories;
StringRef DirName = FileName;
diff --git a/clang/test/Modules/unnecessary-module-map-parsing.c b/clang/test/Modules/unnecessary-module-map-parsing.c
new file mode 100644
index 00000000000..621bb0195dd
--- /dev/null
+++ b/clang/test/Modules/unnecessary-module-map-parsing.c
@@ -0,0 +1,8 @@
+// This checks that we are not parsing module maps if modules are not enabled.
+
+// RUN: not %clang_cc1 -fmodules -I %S/unnecessary-module-map-parsing -fsyntax-only %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -I %S/unnecessary-module-map-parsing -fsyntax-only %s
+
+// CHECK: error: header 'unknown.h' not found
+
+#include "a1.h"
diff --git a/clang/test/Modules/unnecessary-module-map-parsing/a1.h b/clang/test/Modules/unnecessary-module-map-parsing/a1.h
new file mode 100644
index 00000000000..56757a701bf
--- /dev/null
+++ b/clang/test/Modules/unnecessary-module-map-parsing/a1.h
@@ -0,0 +1 @@
+void f() {}
diff --git a/clang/test/Modules/unnecessary-module-map-parsing/module.map b/clang/test/Modules/unnecessary-module-map-parsing/module.map
new file mode 100644
index 00000000000..2d2104177ff
--- /dev/null
+++ b/clang/test/Modules/unnecessary-module-map-parsing/module.map
@@ -0,0 +1,3 @@
+module a {
+ header "unknown.h"
+}
OpenPOWER on IntegriCloud