[clang] [clang] set DebugCompilationDir in PCHContainer (PR #67744)

via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 28 14:45:07 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-modules

<details>
<summary>Changes</summary>

This change sets the debug compilation directory when generating debug information for PCH object containers. This allows for overriding the compilation directory in debug information in precompiled pcm files.

---
Full diff: https://github.com/llvm/llvm-project/pull/67744.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp (+2) 
- (added) clang/test/Modules/module-debuginfo-compdir.m (+24) 


``````````diff
diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
index 9ffeef026bd1b76..ee543e40b46099d 100644
--- a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
+++ b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
@@ -161,6 +161,8 @@ class PCHContainerGenerator : public ASTConsumer {
     CodeGenOpts.setDebugInfo(llvm::codegenoptions::FullDebugInfo);
     CodeGenOpts.setDebuggerTuning(CI.getCodeGenOpts().getDebuggerTuning());
     CodeGenOpts.DwarfVersion = CI.getCodeGenOpts().DwarfVersion;
+    CodeGenOpts.DebugCompilationDir =
+        CI.getInvocation().getCodeGenOpts().DebugCompilationDir;
     CodeGenOpts.DebugPrefixMap =
         CI.getInvocation().getCodeGenOpts().DebugPrefixMap;
     CodeGenOpts.DebugStrictDwarf = CI.getCodeGenOpts().DebugStrictDwarf;
diff --git a/clang/test/Modules/module-debuginfo-compdir.m b/clang/test/Modules/module-debuginfo-compdir.m
new file mode 100644
index 000000000000000..fced242624f75b3
--- /dev/null
+++ b/clang/test/Modules/module-debuginfo-compdir.m
@@ -0,0 +1,24 @@
+// UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
+// REQUIRES: asserts
+
+// Modules:
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x objective-c -fmodules -fmodule-format=obj \
+// RUN:   -fdebug-compilation-dir=/OVERRIDE \
+// RUN:   -fimplicit-module-maps -DMODULES -fmodules-cache-path=%t %s \
+// RUN:   -I %S/Inputs -I %t -emit-llvm -o %t.ll \
+// RUN:   -mllvm -debug-only=pchcontainer &>%t-mod.ll
+// RUN: cat %t-mod.ll | FileCheck %s
+
+// PCH:
+// RUN: %clang_cc1 -x objective-c -emit-pch -fmodule-format=obj -I %S/Inputs \
+// RUN:   -fdebug-compilation-dir=/OVERRIDE \
+// RUN:   -o %t.pch %S/Inputs/DebugObjC.h \
+// RUN:   -mllvm -debug-only=pchcontainer &>%t-pch.ll
+// RUN: cat %t-pch.ll | FileCheck %s
+
+#ifdef MODULES
+ at import DebugObjC;
+#endif
+
+// CHECK: !DIFile(filename: "{{.*}}DebugObjC{{(\.h)?}}", directory: "/OVERRIDE")

``````````

</details>


https://github.com/llvm/llvm-project/pull/67744


More information about the cfe-commits mailing list