]> granicus.if.org Git - clang/commitdiff
[modules] If we see a #include that maps to a module, but use of precompiled modules...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 18 May 2015 03:52:30 +0000 (03:52 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 18 May 2015 03:52:30 +0000 (03:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237550 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/HeaderSearch.h
lib/Lex/HeaderSearch.cpp
lib/Lex/PPDirectives.cpp
test/Modules/cstd.m
test/Modules/submodule-visibility.cpp

index 57da87e1d34b705eb711ee47aeb2144a2850f34c..0406c6d586ff21255cb764485882f153e53be0ee 100644 (file)
@@ -479,9 +479,6 @@ public:
   /// FileEntry, uniquing them through the 'HeaderMaps' datastructure.
   const HeaderMap *CreateHeaderMap(const FileEntry *FE);
 
-  /// Returns true if modules are enabled.
-  bool enabledModules() const { return LangOpts.Modules; }
-
   /// \brief Retrieve the name of the module file that should be used to 
   /// load the given module.
   ///
index 04cdb0f69f7e77f62ee225f9d4834cd3d1471915..ad7d3449ac4af52b72dfbd0bd81538a5564b94d4 100644 (file)
@@ -595,7 +595,13 @@ const FileEntry *HeaderSearch::LookupFile(
       RelativePath->append(Filename.begin(), Filename.end());
     }
     // Otherwise, just return the file.
-    return FileMgr.getFile(Filename, /*openFile=*/true);
+    const FileEntry *File = FileMgr.getFile(Filename, /*openFile=*/true);
+    if (File && SuggestedModule) {
+      // If there is a module that corresponds to this header, suggest it.
+      hasModuleMap(Filename, File->getDir(), /*SystemHeaderDir*/false);
+      *SuggestedModule = findModuleForHeader(File);
+    }
+    return File;
   }
 
   // This is the header that MSVC's header search would have found.
@@ -1070,7 +1076,7 @@ StringRef HeaderSearch::getUniqueFrameworkName(StringRef Framework) {
 bool HeaderSearch::hasModuleMap(StringRef FileName, 
                                 const DirectoryEntry *Root,
                                 bool IsSystem) {
-  if (!enabledModules() || !LangOpts.ModulesImplicitMaps)
+  if (!HSOpts->ModuleMaps || !LangOpts.ModulesImplicitMaps)
     return false;
 
   SmallVector<const DirectoryEntry *, 2> FixUpDirectories;
index a41ed8a1b4895ae1dddad0c5c095bf31620afbe2..86abe5ed898676d5ae2a60954f3bf8e951e76f98 100644 (file)
@@ -1762,13 +1762,12 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
       Callbacks->FileSkipped(*File, FilenameTok, FileCharacter);
 
     // If this is a module import, make it visible if needed.
-    if (IsModuleImport) {
-      makeModuleVisible(SuggestedModule.getModule(), HashLoc);
+    if (auto *M = SuggestedModule.getModule()) {
+      makeModuleVisible(M, HashLoc);
 
       if (IncludeTok.getIdentifierInfo()->getPPKeywordID() !=
           tok::pp___include_macros)
-        EnterAnnotationToken(*this, HashLoc, End, tok::annot_module_include,
-                             SuggestedModule.getModule());
+        EnterAnnotationToken(*this, HashLoc, End, tok::annot_module_include, M);
     }
     return;
   }
@@ -1782,31 +1781,27 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
   FileID FID = SourceMgr.createFileID(File, IncludePos, FileCharacter);
   assert(!FID.isInvalid() && "Expected valid file ID");
 
-  // Determine if we're switching to building a new submodule, and which one.
-  //
-  // FIXME: If we've already processed this header, just make it visible rather
-  // than entering it again.
-  ModuleMap::KnownHeader BuildingModule;
-  if (getLangOpts().Modules && !getLangOpts().CurrentModule.empty()) {
-    Module *RequestingModule = getModuleForLocation(FilenameLoc);
-    BuildingModule =
-        HeaderInfo.getModuleMap().findModuleForHeader(File, RequestingModule);
-  }
-
   // If all is good, enter the new file!
   if (EnterSourceFile(FID, CurDir, FilenameTok.getLocation()))
     return;
 
-  // If we're walking into another part of the same module, let the parser
-  // know that any future declarations are within that other submodule.
-  if (BuildingModule) {
+  // Determine if we're switching to building a new submodule, and which one.
+  //
+  // FIXME: If we've already processed this header, just make it visible rather
+  // than entering it again.
+  if (auto *M = SuggestedModule.getModule()) {
     assert(!CurSubmodule && "should not have marked this as a module yet");
-    CurSubmodule = BuildingModule.getModule();
+    CurSubmodule = M;
 
-    EnterSubmodule(CurSubmodule, HashLoc);
+    // Let the macro handling code know that any future macros are within
+    // the new submodule.
+    EnterSubmodule(M, HashLoc);
 
-    EnterAnnotationToken(*this, HashLoc, End, tok::annot_module_begin,
-                         CurSubmodule);
+    // Let the parser know that any future declarations are within the new
+    // submodule.
+    // FIXME: There's no point doing this if we're handling a #__include_macros
+    // directive.
+    EnterAnnotationToken(*this, HashLoc, End, tok::annot_module_begin, M);
   }
 }
 
index 24bca19b7aa9a535826fa97c01a2484d1e033316..200779a0f3d7f0eafa593b8211a4ced704934f5a 100644 (file)
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang -fsyntax-only -isystem %S/Inputs/System/usr/include -ffreestanding -fmodules -fmodules-cache-path=%t -D__need_wint_t -Werror=implicit-function-declaration %s
+// RUN: %clang_cc1 -fsyntax-only -isystem %S/Inputs/System/usr/include -ffreestanding -fmodules -fmodules-cache-path=%t -D__need_wint_t -Werror=implicit-function-declaration %s
 
 @import uses_other_constants;
 const double other_value = DBL_MAX;
index c63d942cc9ea53fcf7a326206bb2c0ec76e570d4..07be1c2d0c34f11ec37c6e0392fbc3531adb1d4d 100644 (file)
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/submodule-visibility -verify %s -DALLOW_NAME_LEAKAGE
 // RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodules-cache-path=%t -I%S/Inputs/submodule-visibility -verify %s -DIMPORT
 // RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodules-cache-path=%t -fmodule-name=x -I%S/Inputs/submodule-visibility -verify %s
+// RUN: %clang_cc1 -fmodule-maps -fmodules-local-submodule-visibility -fmodules-cache-path=%t -I%S/Inputs/submodule-visibility -verify %s
 
 #include "a.h"
 #include "b.h"