Skip to content

[clang dependency scanning] Make Current Working Directory Optimization Off by Default #129809

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
merged 2 commits into from
Mar 5, 2025

Conversation

qiongsiwu
Copy link
Contributor

@qiongsiwu qiongsiwu commented Mar 5, 2025

#124786 implemented current working directory (CWD) optimization and the optimization was on by default. We have discovered that build system needs to be compatible with the CWD optimization and default off is a better behavior. The build system needs to be aware that the current working directory is ignored. Without a good way of notifying the build system, it is less risky to default to off. This PR implement the change.

rdar://145860213

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Mar 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 5, 2025

@llvm/pr-subscribers-clang

Author: Qiongsi Wu (qiongsiwu)

Changes

#124786 implemented current working directory (CWD) optimization and the optimization was on by default. We have discovered that build system needs to be compatible with the CWD optimization and default off is a better behavior. The build system needs to be aware that the current working directory is ignored. Without a good way of notifying the build system, it is less risky to default to off. This PR implement the change.

rdar://145860213


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

3 Files Affected:

  • (modified) clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h (+1-1)
  • (modified) clang/test/ClangScanDeps/modules-context-hash-cwd.c (+5-5)
  • (modified) clang/test/ClangScanDeps/modules-debug-dir.c (+1-1)
diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
index f002f8645d3f6..b22ba0b1c1dea 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
@@ -67,7 +67,7 @@ enum class ScanningOptimizations {
   IgnoreCWD = (1 << 4),
 
   DSS_LAST_BITMASK_ENUM(IgnoreCWD),
-  Default = All
+  Default = All & (~IgnoreCWD)
 };
 
 #undef DSS_LAST_BITMASK_ENUM
diff --git a/clang/test/ClangScanDeps/modules-context-hash-cwd.c b/clang/test/ClangScanDeps/modules-context-hash-cwd.c
index 459d2c90debe6..c609a7dcbc80e 100644
--- a/clang/test/ClangScanDeps/modules-context-hash-cwd.c
+++ b/clang/test/ClangScanDeps/modules-context-hash-cwd.c
@@ -9,14 +9,14 @@
 // RUN: sed -e "s|DIR|%/t|g" %t/cdb3.json.in > %t/cdb3.json
 // RUN: sed -e "s|DIR|%/t|g" %t/cdb4.json.in > %t/cdb4.json
 // RUN: sed -e "s|DIR|%/t|g" %t/cdb5.json.in > %t/cdb5.json
-// RUN: clang-scan-deps -compilation-database %t/cdb0.json -format experimental-full > %t/result0.json
-// RUN: clang-scan-deps -compilation-database %t/cdb1.json -format experimental-full > %t/result1.json
+// RUN: clang-scan-deps -compilation-database %t/cdb0.json -format experimental-full -optimize-args=all > %t/result0.json
+// RUN: clang-scan-deps -compilation-database %t/cdb1.json -format experimental-full -optimize-args=all > %t/result1.json
 // It is not a typo to use cdb1.json for result2. We intend to use the same
 // compilation database, but different clang-scan-deps optimize-args options.
 // RUN: clang-scan-deps -compilation-database %t/cdb1.json -format experimental-full -optimize-args=header-search,system-warnings,vfs,canonicalize-macros > %t/result2.json
-// RUN: clang-scan-deps -compilation-database %t/cdb3.json -format experimental-full > %t/result3.json
-// RUN: clang-scan-deps -compilation-database %t/cdb4.json -format experimental-full > %t/result4.json
-// RUN: clang-scan-deps -compilation-database %t/cdb5.json -format experimental-full > %t/result5.json
+// RUN: clang-scan-deps -compilation-database %t/cdb3.json -format experimental-full -optimize-args=all > %t/result3.json
+// RUN: clang-scan-deps -compilation-database %t/cdb4.json -format experimental-full -optimize-args=all > %t/result4.json
+// RUN: clang-scan-deps -compilation-database %t/cdb5.json -format experimental-full -optimize-args=all > %t/result5.json
 // RUN: cat %t/result0.json %t/result1.json | FileCheck %s
 // RUN: cat %t/result0.json %t/result2.json | FileCheck %s -check-prefix=SKIPOPT
 // RUN: cat %t/result3.json %t/result4.json | FileCheck %s -check-prefix=RELPATH
diff --git a/clang/test/ClangScanDeps/modules-debug-dir.c b/clang/test/ClangScanDeps/modules-debug-dir.c
index fadec1ad52e35..c4fb4982ed791 100644
--- a/clang/test/ClangScanDeps/modules-debug-dir.c
+++ b/clang/test/ClangScanDeps/modules-debug-dir.c
@@ -4,7 +4,7 @@
 // RUN: split-file %s %t
 // RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.in > %t/cdb.json
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format \
-// RUN:   experimental-full > %t/result.json
+// RUN:   experimental-full -optimize-args=all > %t/result.json
 // RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s
 
 //--- cdb.json.in

Copy link
Contributor

@Bigcheese Bigcheese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with the added comment.

I was going to say this should also update the documentation, but we don't actually have any here. This patch doesn't need to add it, but it would be good to have some documentation on how to actually use clang-scan-deps and the scanning API.

@qiongsiwu qiongsiwu merged commit 7bd492f into llvm:main Mar 5, 2025
11 checks passed
@qiongsiwu qiongsiwu deleted the change_default_145860213 branch March 5, 2025 17:03
qiongsiwu added a commit to swiftlang/swift that referenced this pull request Mar 12, 2025
[Dependency Scanning] Setting Default Clang Optimize Args Option to All

llvm/llvm-project#129809 turned off current working directory (CWD) optimization for clang dependency scanning, because clang needs to coordinate with the build system to safely optimize the CWD. Swift can already handle the CWDs. This PR turns the CWD optimization on for Swift.
qiongsiwu added a commit to qiongsiwu/llvm-project that referenced this pull request Mar 17, 2025
…on Off by Default (llvm#129809)

llvm#124786 implemented current
working directory (CWD) optimization and the optimization was on by
default. We have discovered that build system needs to be compatible
with the CWD optimization and default off is a better behavior. The
build system needs to be aware that the current working directory is
ignored. Without a good way of notifying the build system, it is less
risky to default to off. This PR implement the change.

rdar://145860213
(cherry picked from commit 7bd492f)

 Conflicts:
	clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
qiongsiwu added a commit to swiftlang/llvm-project that referenced this pull request Mar 18, 2025
…on Off by Default (llvm#129809)

llvm#124786 implemented current
working directory (CWD) optimization and the optimization was on by
default. We have discovered that build system needs to be compatible
with the CWD optimization and default off is a better behavior. The
build system needs to be aware that the current working directory is
ignored. Without a good way of notifying the build system, it is less
risky to default to off. This PR implement the change.

rdar://145860213
(cherry picked from commit 7bd492f)

 Conflicts:
	clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
…on Off by Default (llvm#129809)

llvm#124786 implemented current
working directory (CWD) optimization and the optimization was on by
default. We have discovered that build system needs to be compatible
with the CWD optimization and default off is a better behavior. The
build system needs to be aware that the current working directory is
ignored. Without a good way of notifying the build system, it is less
risky to default to off. This PR implement the change.

rdar://145860213
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants