]> granicus.if.org Git - clang/commitdiff
[Modules] Don't parse any module map if modules are disabled.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 12 Dec 2013 16:08:33 +0000 (16:08 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 12 Dec 2013 16:08:33 +0000 (16:08 +0000)
Fixes rdar://15644663.

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

include/clang/Lex/HeaderSearch.h
lib/Lex/HeaderSearch.cpp
test/Modules/unnecessary-module-map-parsing.c [new file with mode: 0644]
test/Modules/unnecessary-module-map-parsing/a1.h [new file with mode: 0644]
test/Modules/unnecessary-module-map-parsing/module.map [new file with mode: 0644]

index fb1a862063540b18333152e9d37d9b2b30d106e2..283bd5714f067ed57e1b77e3a9e2dbdbe07c01f0 100644 (file)
@@ -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.
   ///
index 9e43dda226bf47837fcb402cca677479f0b958ca..5770aaadf4046d6b2263e4052145668a9db13a14 100644 (file)
@@ -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/test/Modules/unnecessary-module-map-parsing.c b/test/Modules/unnecessary-module-map-parsing.c
new file mode 100644 (file)
index 0000000..621bb01
--- /dev/null
@@ -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/test/Modules/unnecessary-module-map-parsing/a1.h b/test/Modules/unnecessary-module-map-parsing/a1.h
new file mode 100644 (file)
index 0000000..56757a7
--- /dev/null
@@ -0,0 +1 @@
+void f() {}
diff --git a/test/Modules/unnecessary-module-map-parsing/module.map b/test/Modules/unnecessary-module-map-parsing/module.map
new file mode 100644 (file)
index 0000000..2d21041
--- /dev/null
@@ -0,0 +1,3 @@
+module a {
+  header "unknown.h"
+}