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

Richard Howell via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 28 14:44:04 PDT 2023


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

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.

>From 0f6bcb1b367ae74f92a15272e5a85664f901e1f4 Mon Sep 17 00:00:00 2001
From: Richard Howell <rhow at fb.com>
Date: Thu, 28 Sep 2023 14:31:16 -0700
Subject: [PATCH] [clang] set DebugCompilationDir in PCHContainer

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.
---
 .../ObjectFilePCHContainerOperations.cpp      |  2 ++
 clang/test/Modules/module-debuginfo-compdir.m | 24 +++++++++++++++++++
 2 files changed, 26 insertions(+)
 create mode 100644 clang/test/Modules/module-debuginfo-compdir.m

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")



More information about the cfe-commits mailing list