[PATCH] D76385: Allow remapping Clang module include paths

Adrian Prantl via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 19 10:20:01 PDT 2020


aprantl updated this revision to Diff 251411.
aprantl added a comment.

Don't try to be too clever.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76385/new/

https://reviews.llvm.org/D76385

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/Modules/debug-info-moduleimport.m


Index: clang/test/Modules/debug-info-moduleimport.m
===================================================================
--- clang/test/Modules/debug-info-moduleimport.m
+++ clang/test/Modules/debug-info-moduleimport.m
@@ -34,9 +34,11 @@
 
 // RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps \
 // RUN:   -fmodules-cache-path=%t -fdebug-prefix-map=%t=/MODULE-CACHE \
+// RUN:   -fdebug-prefix-map=%S=/SRCDIR \
 // RUN:   -fmodule-format=obj -dwarf-ext-refs \
 // RUN:   %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
 // RUN:     | FileCheck %s --check-prefix=SKEL-CHECK
+// SKEL-CHECK: includePath: "/SRCDIR/Inputs"
 // SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[CUFILE:[0-9]+]]
 // SKEL-CHECK: ![[CUFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR:.*]]"
 // SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[DWOFILE:[0-9]+]]{{.*}}splitDebugFilename: "/MODULE-CACHE{{.*}}dwoId
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2483,6 +2483,14 @@
     assert(StringRef(M->Name).startswith(CGM.getLangOpts().ModuleName) &&
            "clang module without ASTFile must be specified by -fmodule-name");
 
+  // Return a StringRef to the remapped Path.
+  auto RemapPath = [&](std::string Path) -> std::string {
+    Path = remapDIPath(Path);
+    StringRef Relative(Path);
+    Relative.consume_front(TheCU->getDirectory());
+    return Relative.str();
+  };
+
   if (CreateSkeletonCU && IsRootModule && !Mod.getASTFile().empty()) {
     // PCH files don't have a signature field in the control block,
     // but LLVM detects skeleton CUs by looking for a non-zero DWO id.
@@ -2492,14 +2500,12 @@
             ? (uint64_t)Mod.getSignature()[1] << 32 | Mod.getSignature()[0]
             : ~1ULL;
     llvm::DIBuilder DIB(CGM.getModule());
-    std::string PCM = remapDIPath(Mod.getASTFile());
-    StringRef RelativePCM(PCM);
-    RelativePCM.consume_front(TheCU->getDirectory());
+    std::string PCM = Mod.getASTFile().str();
     DIB.createCompileUnit(
         TheCU->getSourceLanguage(),
         // TODO: Support "Source" from external AST providers?
         DIB.createFile(Mod.getModuleName(), TheCU->getDirectory()),
-        TheCU->getProducer(), false, StringRef(), 0, RelativePCM,
+        TheCU->getProducer(), false, StringRef(), 0, RemapPath(PCM),
         llvm::DICompileUnit::FullDebug, Signature);
     DIB.finalize();
   }
@@ -2508,9 +2514,10 @@
       IsRootModule ? nullptr
                    : getOrCreateModuleRef(ASTSourceDescriptor(*M->Parent),
                                           CreateSkeletonCU);
+  std::string IncludePath = Mod.getPath().str();
   llvm::DIModule *DIMod =
       DBuilder.createModule(Parent, Mod.getModuleName(), ConfigMacros,
-                            Mod.getPath());
+                            RemapPath(IncludePath));
   ModuleCache[M].reset(DIMod);
   return DIMod;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76385.251411.patch
Type: text/x-patch
Size: 3014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200319/30bd1125/attachment-0001.bin>


More information about the cfe-commits mailing list