Skip to content

Commit 9d6062c

Browse files
[clang][Dependency Scanning] Canonicalize Defines of a Compiler Invocation As Early As Possible (llvm#159620)
Before this patch, we only perform `-D` canonicalization on the deep copy of the `CompilerInvocation` instance, since the canonicalization should have no impact on scanning. However, in the presence of CAS, the content of the `builtin` macros are included in the context hash. This patch makes sure that we canonicalize the scanning `CompilerInvocation`'s `-D`s. Part of work for rdar://136303612. --------- Co-authored-by: Jan Svoboda <[email protected]>
1 parent 1de6f65 commit 9d6062c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,14 @@ class DependencyScanningAction {
391391
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
392392
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
393393
DiagnosticConsumer *DiagConsumer) {
394+
// Making sure that we canonicalize the defines before we create the deep
395+
// copy to avoid unnecessary variants in the scanner and in the resulting
396+
// explicit command lines.
397+
if (any(Service.getOptimizeArgs() & ScanningOptimizations::Macros))
398+
canonicalizeDefines(Invocation->getPreprocessorOpts());
399+
394400
// Make a deep copy of the original Clang invocation.
395401
CompilerInvocation OriginalInvocation(*Invocation);
396-
if (any(Service.getOptimizeArgs() & ScanningOptimizations::Macros))
397-
canonicalizeDefines(OriginalInvocation.getPreprocessorOpts());
398402

399403
if (Scanned) {
400404
// Scanning runs once for the first -cc1 invocation in a chain of driver

clang/test/ClangScanDeps/optimize-canonicalize-macros.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// RUN: -j 1 -format experimental-full -optimize-args=canonicalize-macros > %t/deps.db
99
// RUN: cat %t/deps.db | FileCheck %s -DPREFIX=%/t
1010

11+
// This tests that we have two scanning module variants.
12+
// RUN: find %t/module-cache -name "*.pcm" | wc -l | grep 2
13+
1114
// Verify that there are only two variants and that the expected merges have
1215
// happened.
1316

0 commit comments

Comments
 (0)