r289360 - [CrashReproducer] Collect headermap files

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 10 20:27:28 PST 2016


Author: bruno
Date: Sat Dec 10 22:27:28 2016
New Revision: 289360

URL: http://llvm.org/viewvc/llvm-project?rev=289360&view=rev
Log:
[CrashReproducer] Collect headermap files

Include headermaps (.hmap files) in the .cache directory and
add VFS entries. All headermaps are known after HeaderSearch
setup, collect them right after.

rdar://problem/27913709

Added:
    cfe/trunk/test/Modules/crash-vfs-headermaps.m
Modified:
    cfe/trunk/include/clang/Lex/HeaderSearch.h
    cfe/trunk/lib/Frontend/CompilerInstance.cpp
    cfe/trunk/lib/Lex/HeaderSearch.cpp

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=289360&r1=289359&r2=289360&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Sat Dec 10 22:27:28 2016
@@ -464,6 +464,9 @@ public:
   /// FileEntry, uniquing them through the 'HeaderMaps' datastructure.
   const HeaderMap *CreateHeaderMap(const FileEntry *FE);
 
+  /// \brief Get filenames for all registered header maps.
+  void getHeaderMapFileNames(SmallVectorImpl<std::string> &Names) const;
+
   /// \brief Retrieve the name of the module file that should be used to 
   /// load the given module.
   ///

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=289360&r1=289359&r2=289360&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Sat Dec 10 22:27:28 2016
@@ -141,6 +141,14 @@ void CompilerInstance::setModuleDepColle
   ModuleDepCollector = std::move(Collector);
 }
 
+static void collectHeaderMaps(const HeaderSearch &HS,
+                              std::shared_ptr<ModuleDependencyCollector> MDC) {
+  SmallVector<std::string, 4> HeaderMapFileNames;
+  HS.getHeaderMapFileNames(HeaderMapFileNames);
+  for (auto &Name : HeaderMapFileNames)
+    MDC->addFile(Name);
+}
+
 // Diagnostics
 static void SetUpDiagnosticLog(DiagnosticOptions *DiagOpts,
                                const CodeGenOptions *CodeGenOpts,
@@ -366,8 +374,12 @@ void CompilerInstance::createPreprocesso
         DepOpts.ModuleDependencyOutputDir);
   }
 
-  if (ModuleDepCollector)
+  // If there is a module dep collector, register with other dep collectors
+  // and also (a) collect header maps and (b) TODO: input vfs overlay files.
+  if (ModuleDepCollector) {
     addDependencyCollector(ModuleDepCollector);
+    collectHeaderMaps(PP->getHeaderSearchInfo(), ModuleDepCollector);
+  }
 
   for (auto &Listener : DependencyCollectors)
     Listener->attachToPreprocessor(*PP);

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=289360&r1=289359&r2=289360&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Sat Dec 10 22:27:28 2016
@@ -121,6 +121,13 @@ const HeaderMap *HeaderSearch::CreateHea
   return nullptr;
 }
 
+/// \brief Get filenames for all registered header maps.
+void HeaderSearch::getHeaderMapFileNames(
+    SmallVectorImpl<std::string> &Names) const {
+  for (auto &HM : HeaderMaps)
+    Names.push_back(HM.first->getName());
+}
+
 std::string HeaderSearch::getModuleFileName(Module *Module) {
   const FileEntry *ModuleMap =
       getModuleMap().getModuleMapFileForUniquing(Module);

Added: cfe/trunk/test/Modules/crash-vfs-headermaps.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/crash-vfs-headermaps.m?rev=289360&view=auto
==============================================================================
--- cfe/trunk/test/Modules/crash-vfs-headermaps.m (added)
+++ cfe/trunk/test/Modules/crash-vfs-headermaps.m Sat Dec 10 22:27:28 2016
@@ -0,0 +1,48 @@
+// REQUIRES: crash-recovery, shell, system-darwin
+
+// This uses a headermap with this entry:
+//   Foo.h -> Foo/Foo.h
+
+// Copy out the headermap from test/Preprocessor/Inputs/headermap-rel and avoid
+// adding another binary format to the repository.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/m
+// RUN: cp -a %S/../Preprocessor/Inputs/headermap-rel %t/i
+// RUN: echo '// Foo.h' > %t/i/Foo.framework/Headers/Foo.h
+
+// RUN: not env FORCE_CLANG_DIAGNOSTICS_CRASH= TMPDIR=%t TEMP=%t TMP=%t \
+// RUN: %clang -fsyntax-only -fmodules -fmodules-cache-path=%t/m %s \
+// RUN:     -I %t/i/foo.hmap -F %t/i 2>&1 | FileCheck %s
+
+// RUN: FileCheck --check-prefix=CHECKSH %s -input-file %t/crash-vfs-*.sh
+// RUN: FileCheck --check-prefix=CHECKYAML %s -input-file \
+// RUN:   %t/crash-vfs-*.cache/vfs/vfs.yaml
+
+#include "Foo.h"
+#include "Foo.h"
+
+// CHECK: Preprocessed source(s) and associated run script(s) are located at:
+// CHECK-NEXT: note: diagnostic msg: {{.*}}.m
+// CHECK-NEXT: note: diagnostic msg: {{.*}}.cache
+
+// CHECKSH: # Crash reproducer
+// CHECKSH-NEXT: # Driver args: "-fsyntax-only"
+// CHECKSH-NEXT: # Original command: {{.*$}}
+// CHECKSH-NEXT: "-cc1"
+// CHECKSH: "-I" "/[[INCPATH:.*]]/foo.hmap"
+// CHECKSH: "crash-vfs-{{[^ ]*}}.m"
+// CHECKSH: "-ivfsoverlay" "crash-vfs-{{[^ ]*}}.cache/vfs/vfs.yaml"
+// CHECKSH: "-fmodules-cache-path=crash-vfs-{{[^ ]*}}.cache/repro-modules"
+
+// CHECKYAML: 'case-sensitive':
+// CHECKYAML-NEXT: 'use-external-names': 'false',
+// CHECKYAML-NEXT: 'overlay-relative': 'true',
+// CHECKYAML-NEXT: 'ignore-non-existent-contents': 'false'
+// CHECKYAML: 'type': 'directory'
+// CHECKYAML: 'name': "/[[PATH:.*]]/i",
+// CHECKYAML-NEXT: 'contents': [
+// CHECKYAML-NEXT:   {
+// CHECKYAML-NEXT:     'type': 'file',
+// CHECKYAML-NEXT:     'name': "foo.hmap",
+// CHECKYAML-NEXT:     'external-contents': "/[[PATH]]/i/foo.hmap"




More information about the cfe-commits mailing list