-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang][ScanDeps] Clear compilation directory if needed #150129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cachemeifyoucan
merged 7 commits into
main
from
users/cachemeifyoucan/spr/clangscandeps-clear-compilation-directory-if-needed
Aug 1, 2025
Merged
[clang][ScanDeps] Clear compilation directory if needed #150129
cachemeifyoucan
merged 7 commits into
main
from
users/cachemeifyoucan/spr/clangscandeps-clear-compilation-directory-if-needed
Aug 1, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Created using spr 1.3.6 [skip ci]
Created using spr 1.3.6
Member
|
@llvm/pr-subscribers-clang Author: Steven Wu (cachemeifyoucan) ChangesDuring explicit module build, clear the compilation directory flags when Full diff: https://github.com/llvm/llvm-project/pull/150129.diff 2 Files Affected:
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 37f8b945d785e..d67178c153e88 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -144,30 +144,8 @@ static void optimizeDiagnosticOpts(DiagnosticOptions &Opts,
static void optimizeCWD(CowCompilerInvocation &BuildInvocation, StringRef CWD) {
BuildInvocation.getMutFileSystemOpts().WorkingDir.clear();
- if (BuildInvocation.getCodeGenOpts().DwarfVersion) {
- // It is necessary to explicitly set the DebugCompilationDir
- // to a common directory (e.g. root) if IgnoreCWD is true.
- // When IgnoreCWD is true, the module's content should not
- // depend on the current working directory. However, if dwarf
- // information is needed (when CGOpts.DwarfVersion is
- // non-zero), then CGOpts.DebugCompilationDir must be
- // populated, because otherwise the current working directory
- // will be automatically embedded in the dwarf information in
- // the pcm, contradicting the assumption that it is safe to
- // ignore the CWD. Thus in such cases,
- // CGOpts.DebugCompilationDir is explicitly set to a common
- // directory.
- // FIXME: It is still excessive to create a copy of
- // CodeGenOpts for each module. Since we do not modify the
- // CodeGenOpts otherwise per module, the following code
- // ends up generating identical CodeGenOpts for each module
- // with DebugCompilationDir pointing to the root directory.
- // We can optimize this away by creating a _single_ copy of
- // CodeGenOpts whose DebugCompilationDir points to the root
- // directory and reuse it across modules.
- BuildInvocation.getMutCodeGenOpts().DebugCompilationDir =
- llvm::sys::path::root_path(CWD);
- }
+ BuildInvocation.getMutCodeGenOpts().DebugCompilationDir.clear();
+ BuildInvocation.getMutCodeGenOpts().CoverageCompilationDir.clear();
}
static std::vector<std::string> splitString(std::string S, char Separator) {
diff --git a/clang/test/ClangScanDeps/modules-debug-dir.c b/clang/test/ClangScanDeps/modules-debug-dir.c
index c4fb4982ed791..e2a0e1b7a5b01 100644
--- a/clang/test/ClangScanDeps/modules-debug-dir.c
+++ b/clang/test/ClangScanDeps/modules-debug-dir.c
@@ -1,5 +1,3 @@
-// REQUIRES: shell
-
// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.in > %t/cdb.json
@@ -7,6 +5,12 @@
// RUN: experimental-full -optimize-args=all > %t/result.json
// RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s
+// RUN: %deps-to-rsp %t/result.json --module-name=mod > %t/mod.rsp
+// RUN: %clang @%t/mod.rsp -o %t/mod.pcm
+// RUN: llvm-dwarfdump --debug-info %t/mod.pcm | FileCheck %s --check-prefix=DWARF
+// DWARF: DW_TAG_compile_unit
+// DWARF-NOT: DW_AT_comp_dir
+
//--- cdb.json.in
[{
"directory": "DIR",
@@ -28,5 +32,5 @@ module mod {
// directory when current working directory optimization is in effect.
// CHECK: "modules": [
// CHECK: "command-line": [
-// CHECK: "-fdebug-compilation-dir={{\/|.*:(\\)?}}",
+// CHECK-NOT: -fdebug-compilation-dir
// CHECK: "translation-units": [
|
Created using spr 1.3.6 [skip ci]
Created using spr 1.3.6
Created using spr 1.3.6 [skip ci]
Created using spr 1.3.6
Created using spr 1.3.6
cachemeifyoucan
added a commit
to cachemeifyoucan/llvm-project
that referenced
this pull request
Aug 5, 2025
During explicit module build, clear the compilation directory flags when CWD optimization is on. Now clang CodeGen will not add compilation directories to DIFile when the corresponding flags are not passed and make debug info not dependent on CWD.
cachemeifyoucan
added a commit
to swiftlang/llvm-project
that referenced
this pull request
Aug 8, 2025
During explicit module build, clear the compilation directory flags when CWD optimization is on. Now clang CodeGen will not add compilation directories to DIFile when the corresponding flags are not passed and make debug info not dependent on CWD.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
During explicit module build, clear the compilation directory flags when
CWD optimization is on. Now clang CodeGen will not add compilation
directories to DIFile when the corresponding flags are not passed and
make debug info not dependent on CWD.