<div dir="rtl"><div dir="ltr">Hi Richard,</div><div dir="ltr"><br></div><div dir="ltr">This broke the tests on the Windows bot:</div><div dir="ltr"><br></div><div dir="ltr"><a href="http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/5266">http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/5266</a><br></div><div dir="ltr"><ol style="color:rgb(51,51,51);font-family:Verdana,sans-serif;font-size:10px"><li class="inbox-inbox-" style="padding:0.1em 1em"><a href="http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/5266/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Apreprocess-nested.cpp" style="color:rgb(68,68,68)">FAIL: Clang::preprocess-nested.cpp</a></li><li class="inbox-inbox-alt" style="padding:0.1em 1em;background-color:rgb(246,246,246)"><a href="http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/5266/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Apreprocess-module.cpp" style="color:rgb(68,68,68)">FAIL: Clang::preprocess-module.cpp</a></li></ol></div><div dir="ltr">r304345 was OK<br></div><div dir="ltr"><a href="http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/5265">http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/5265</a><br></div><div dir="ltr"><br></div><div dir="ltr">Yaron</div><div dir="ltr"><br></div></div><br><div class="gmail_quote"><div dir="rtl">‫בתאריך יום ד׳, 31 במאי 2017 ב-23:57 מאת ‪Richard Smith via cfe-commits‬‏ <‪<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>‬‏>:‬<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rsmith<br>
Date: Wed May 31 15:56:55 2017<br>
New Revision: 304346<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=304346&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=304346&view=rev</a><br>
Log:<br>
[modules] When compiling a preprocessed module map, look for headers relative<br>
to the original module map.<br>
<br>
Also use the path and name of the original module map when emitting that<br>
information into the .pcm file. The upshot of this is that the produced .pcm<br>
file will track information for headers in their original locations (where the<br>
module was preprocessed), not relative to whatever directory the preprocessed<br>
module map was in when it was built.<br>
<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/Module.h<br>
    cfe/trunk/include/clang/Lex/HeaderSearch.h<br>
    cfe/trunk/lib/Frontend/FrontendAction.cpp<br>
    cfe/trunk/lib/Lex/HeaderSearch.cpp<br>
    cfe/trunk/lib/Serialization/ASTWriter.cpp<br>
    cfe/trunk/test/Modules/preprocess-module.cpp<br>
    cfe/trunk/test/Modules/preprocess-nested.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Basic/Module.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Module.h?rev=304346&r1=304345&r2=304346&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Module.h?rev=304346&r1=304345&r2=304346&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/Module.h (original)<br>
+++ cfe/trunk/include/clang/Basic/Module.h Wed May 31 15:56:55 2017<br>
@@ -83,6 +83,10 @@ public:<br>
   /// are found.<br>
   const DirectoryEntry *Directory;<br>
<br>
+  /// \brief The presumed file name for the module map defining this module.<br>
+  /// Only non-empty when building from preprocessed source.<br>
+  std::string PresumedModuleMapFile;<br>
+<br>
   /// \brief The umbrella header or directory.<br>
   llvm::PointerUnion<const DirectoryEntry *, const FileEntry *> Umbrella;<br>
<br>
<br>
Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=304346&r1=304345&r2=304346&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=304346&r1=304345&r2=304346&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)<br>
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Wed May 31 15:56:55 2017<br>
@@ -543,10 +543,13 @@ public:<br>
   /// \param Offset [inout] An offset within ID to start parsing. On exit,<br>
   ///        filled by the end of the parsed contents (either EOF or the<br>
   ///        location of an end-of-module-map pragma).<br>
-  ///<br>
+  /// \param OriginalModuleMapFile The original path to the module map file,<br>
+  ///        used to resolve paths within the module (this is required when<br>
+  ///        building the module from preprocessed source).<br>
   /// \returns true if an error occurred, false otherwise.<br>
   bool loadModuleMapFile(const FileEntry *File, bool IsSystem,<br>
-                         FileID ID = FileID(), unsigned *Offset = nullptr);<br>
+                         FileID ID = FileID(), unsigned *Offset = nullptr,<br>
+                         StringRef OriginalModuleMapFile = StringRef());<br>
<br>
   /// \brief Collect the set of all known, top-level modules.<br>
   ///<br>
<br>
Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=304346&r1=304345&r2=304346&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=304346&r1=304345&r2=304346&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)<br>
+++ cfe/trunk/lib/Frontend/FrontendAction.cpp Wed May 31 15:56:55 2017<br>
@@ -373,10 +373,11 @@ collectModuleHeaderIncludes(const LangOp<br>
   return std::error_code();<br>
 }<br>
<br>
-static bool<br>
-loadModuleMapForModuleBuild(CompilerInstance &CI, StringRef Filename,<br>
-                            bool IsSystem, bool IsPreprocessed,<br>
-                            unsigned &Offset) {<br>
+static bool loadModuleMapForModuleBuild(CompilerInstance &CI,<br>
+                                        StringRef Filename, bool IsSystem,<br>
+                                        bool IsPreprocessed,<br>
+                                        std::string &PresumedModuleMapFile,<br>
+                                        unsigned &Offset) {<br>
   auto &SrcMgr = CI.getSourceManager();<br>
   HeaderSearch &HS = CI.getPreprocessor().getHeaderSearchInfo();<br>
<br>
@@ -388,16 +389,15 @@ loadModuleMapForModuleBuild(CompilerInst<br>
   // line directives are not part of the module map syntax in general.<br>
   Offset = 0;<br>
   if (IsPreprocessed) {<br>
-    std::string PresumedModuleMapFile;<br>
     SourceLocation EndOfLineMarker =<br>
         ReadOriginalFileName(CI, PresumedModuleMapFile, /*AddLineNote*/true);<br>
     if (EndOfLineMarker.isValid())<br>
       Offset = CI.getSourceManager().getDecomposedLoc(EndOfLineMarker).second;<br>
-    // FIXME: Use PresumedModuleMapFile as the MODULE_MAP_FILE in the PCM.<br>
   }<br>
<br>
   // Load the module map file.<br>
-  if (HS.loadModuleMapFile(ModuleMap, IsSystem, ModuleMapID, &Offset))<br>
+  if (HS.loadModuleMapFile(ModuleMap, IsSystem, ModuleMapID, &Offset,<br>
+                           PresumedModuleMapFile))<br>
     return true;<br>
<br>
   if (SrcMgr.getBuffer(ModuleMapID)->getBufferSize() == Offset)<br>
@@ -664,15 +664,19 @@ bool FrontendAction::BeginSourceFile(Com<br>
   if (Input.getKind().getFormat() == InputKind::ModuleMap) {<br>
     CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleMap);<br>
<br>
+    std::string PresumedModuleMapFile;<br>
     unsigned OffsetToContents;<br>
     if (loadModuleMapForModuleBuild(CI, Input.getFile(), Input.isSystem(),<br>
-                                    Input.isPreprocessed(), OffsetToContents))<br>
+                                    Input.isPreprocessed(),<br>
+                                    PresumedModuleMapFile, OffsetToContents))<br>
       goto failure;<br>
<br>
     auto *CurrentModule = prepareToBuildModule(CI, Input.getFile());<br>
     if (!CurrentModule)<br>
       goto failure;<br>
<br>
+    CurrentModule->PresumedModuleMapFile = PresumedModuleMapFile;<br>
+<br>
     if (OffsetToContents)<br>
       // If the module contents are in the same file, skip to them.<br>
       CI.getPreprocessor().setSkipMainFilePreamble(OffsetToContents, true);<br>
<br>
Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=304346&r1=304345&r2=304346&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=304346&r1=304345&r2=304346&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)<br>
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Wed May 31 15:56:55 2017<br>
@@ -1326,14 +1326,27 @@ static const FileEntry *getPrivateModule<br>
 }<br>
<br>
 bool HeaderSearch::loadModuleMapFile(const FileEntry *File, bool IsSystem,<br>
-                                     FileID ID, unsigned *Offset) {<br>
+                                     FileID ID, unsigned *Offset,<br>
+                                     StringRef OriginalModuleMapFile) {<br>
   // Find the directory for the module. For frameworks, that may require going<br>
   // up from the 'Modules' directory.<br>
   const DirectoryEntry *Dir = nullptr;<br>
   if (getHeaderSearchOpts().ModuleMapFileHomeIsCwd)<br>
     Dir = FileMgr.getDirectory(".");<br>
   else {<br>
-    Dir = File->getDir();<br>
+    if (!OriginalModuleMapFile.empty()) {<br>
+      // We're building a preprocessed module map. Find or invent the directory<br>
+      // that it originally occupied.<br>
+      Dir = FileMgr.getDirectory(<br>
+          llvm::sys::path::parent_path(OriginalModuleMapFile));<br>
+      if (!Dir) {<br>
+        auto *FakeFile = FileMgr.getVirtualFile(OriginalModuleMapFile, 0, 0);<br>
+        Dir = FakeFile->getDir();<br>
+      }<br>
+    } else {<br>
+      Dir = File->getDir();<br>
+    }<br>
+<br>
     StringRef DirName(Dir->getName());<br>
     if (llvm::sys::path::filename(DirName) == "Modules") {<br>
       DirName = llvm::sys::path::parent_path(DirName);<br>
<br>
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=304346&r1=304345&r2=304346&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=304346&r1=304345&r2=304346&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)<br>
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Wed May 31 15:56:55 2017<br>
@@ -1422,8 +1422,8 @@ void ASTWriter::WriteControlBlock(Prepro<br>
     Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record,<br>
                               getClangFullRepositoryVersion());<br>
   }<br>
-  if (WritingModule) {<br>
<br>
+  if (WritingModule) {<br>
     // Module name<br>
     auto Abbrev = std::make_shared<BitCodeAbbrev>();<br>
     Abbrev->Add(BitCodeAbbrevOp(MODULE_NAME));<br>
@@ -1466,9 +1466,10 @@ void ASTWriter::WriteControlBlock(Prepro<br>
     Record.clear();<br>
<br>
     auto &Map = PP.getHeaderSearchInfo().getModuleMap();<br>
-<br>
-    // Primary module map file.<br>
-    AddPath(Map.getModuleMapFileForUniquing(WritingModule)->getName(), Record);<br>
+    AddPath(WritingModule->PresumedModuleMapFile.empty()<br>
+                ? Map.getModuleMapFileForUniquing(WritingModule)->getName()<br>
+                : StringRef(WritingModule->PresumedModuleMapFile),<br>
+            Record);<br>
<br>
     // Additional module map files.<br>
     if (auto *AdditionalModMaps =<br>
<br>
Modified: cfe/trunk/test/Modules/preprocess-module.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/preprocess-module.cpp?rev=304346&r1=304345&r2=304346&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/preprocess-module.cpp?rev=304346&r1=304345&r2=304346&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Modules/preprocess-module.cpp (original)<br>
+++ cfe/trunk/test/Modules/preprocess-module.cpp Wed May 31 15:56:55 2017<br>
@@ -14,8 +14,6 @@<br>
 // RUN: FileCheck %s --input-file %t/rewrite.ii    --check-prefix=CHECK --check-prefix=REWRITE<br>
<br>
 // Check that we can build a module from the preprocessed output.<br>
-// FIXME: For now, we need the headers to exist.<br>
-// RUN: touch %t/file.h %t/file2.h<br>
 // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/no-rewrite.ii -emit-module -o %t/no-rewrite.pcm<br>
 // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/rewrite.ii -emit-module -o %t/rewrite.pcm<br>
<br>
@@ -27,6 +25,8 @@<br>
 // Check the module we built works.<br>
 // RUN: %clang_cc1 -fmodules -fmodule-file=%t/no-rewrite.pcm %s -I%t -verify -fno-modules-error-recovery<br>
 // RUN: %clang_cc1 -fmodules -fmodule-file=%t/rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DREWRITE<br>
+// RUN: %clang_cc1 -fmodules -fmodule-file=%t/no-rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DINCLUDE -I%S/Inputs/preprocess<br>
+// RUN: %clang_cc1 -fmodules -fmodule-file=%t/rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DREWRITE -DINCLUDE -I%S/Inputs/preprocess<br>
<br>
<br>
 // == module map<br>
@@ -102,7 +102,11 @@ __FILE *a; // expected-error {{declarati<br>
 // expected-note@no-rewrite.ii:1 {{here}}<br>
 #endif<br>
<br>
+#ifdef INCLUDE<br>
+#include "file.h"<br>
+#else<br>
 #pragma clang module import file<br>
+#endif<br>
<br>
 FILE *b;<br>
-int x = file2;<br>
+int x = file2; // ok, found in file2.h, even under -DINCLUDE<br>
<br>
Modified: cfe/trunk/test/Modules/preprocess-nested.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/preprocess-nested.cpp?rev=304346&r1=304345&r2=304346&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/preprocess-nested.cpp?rev=304346&r1=304345&r2=304346&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Modules/preprocess-nested.cpp (original)<br>
+++ cfe/trunk/test/Modules/preprocess-nested.cpp Wed May 31 15:56:55 2017<br>
@@ -8,8 +8,6 @@<br>
 // RUN: FileCheck %s --input-file %t/rewrite.ii    --check-prefix=CHECK --check-prefix=REWRITE<br>
<br>
 // Check that we can build a module from the preprocessed output.<br>
-// FIXME: For now, the files need to exist.<br>
-// RUN: touch %t/a.h %t/b.h %t/c.h<br>
 // RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodule-name=nested -x c++-module-map-cpp-output %t/no-rewrite.ii -emit-module -o %t/no-rewrite.pcm<br>
 // RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodule-name=nested -x c++-module-map-cpp-output %t/rewrite.ii -emit-module -o %t/rewrite.pcm<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>