Skip to content

Commit d9b5876

Browse files
committed
[clang][cas] Remove CASOptions from module context hash
We want to avoid spurious cache misses due to module context hash including the -fcas-path, -fcas-plugin-path, -fcas-plugin-option options. These cannot cause collisions since we only have a single CAS for the dependency scanner, and they cannot collide with non-cas invocations, because the include-tree and cas-fs-working-dir options are still present. rdar://108341513 (cherry picked from commit 64bbbc0)
1 parent 24bcd67 commit d9b5876

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ static std::string getModuleContextHash(const ModuleDeps &MD,
297297
MutableCI.getFileSystemOpts().CASFileSystemRootID, "");
298298
llvm::SaveAndRestore<std::vector<std::string>> RestorePrefixMappings(
299299
MutableCI.getFrontendOpts().PathPrefixMappings, {});
300+
llvm::SaveAndRestore<CASOptions> RestoreCASOptions(
301+
MutableCI.getCASOpts(), {});
300302

301303
// Hash the BuildInvocation without any input files.
302304
SmallVector<const char *, 32> Args;
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: sed "s|DIR|%/t|g" %t/cdb1.json.template > %t/cdb1.json
4+
// RUN: sed "s|DIR|%/t|g" %t/cdb2.json.template > %t/cdb2.json
5+
6+
// RUN: clang-scan-deps -compilation-database %t/cdb1.json -module-files-dir %t/outputs \
7+
// RUN: -cas-path %t/cas1 -format experimental-include-tree-full \
8+
// RUN: > %t/result.json
9+
// RUN: echo "=====" >> %t/result.json
10+
// RUN: clang-scan-deps -compilation-database %t/cdb2.json -module-files-dir %t/outputs \
11+
// RUN: -cas-path %t/cas2 -format experimental-include-tree-full \
12+
// RUN: >> %t/result.json
13+
14+
// RUN: cat %t/result.json | FileCheck %s -DPREFIX=%/t
15+
16+
// CHECK: "modules": [
17+
// CHECK: {
18+
// CHECK: "cache-key": "llvmcas://[[KEY:[[:xdigit:]]+]]"
19+
// CHECK: "context-hash": "[[HASH:[A-Z0-9]+]]",
20+
// CHECK: "name": "Mod"
21+
// CHECK: }
22+
// CHECK: ]
23+
// CHECK: "translation-units": [
24+
// CHECK: {
25+
// CHECK: "commands": [
26+
// CHECK: {
27+
// CHECK: "clang-module-deps": [
28+
// CHECK: {
29+
// CHECK: "context-hash": "[[HASH]]"
30+
// CHECK: "module-name": "Mod"
31+
// CHECK: }
32+
// CHECK: ],
33+
// CHECK: "command-line": [
34+
// CHECK: "-fmodule-file-cache-key"
35+
// CHECK: "[[PREFIX]]/outputs/[[HASH]]/Mod-[[HASH]].pcm"
36+
// CHECK: "llvmcas://[[KEY]]"
37+
// CHECK: ]
38+
39+
// CHECK-LABEL: =====
40+
41+
// CHECK: "modules": [
42+
// CHECK: {
43+
// CHECK: "cache-key": "llvmcas://[[KEY]]"
44+
// CHECK: "context-hash": "[[HASH]]"
45+
// CHECK: "name": "Mod"
46+
// CHECK: }
47+
// CHECK: "translation-units": [
48+
// CHECK: {
49+
// CHECK: "commands": [
50+
// CHECK: {
51+
// CHECK: "clang-module-deps": [
52+
// CHECK: {
53+
// CHECK: "context-hash": "[[HASH]]"
54+
// CHECK: "module-name": "Mod"
55+
// CHECK: }
56+
// CHECK: ],
57+
// CHECK: "command-line": [
58+
// CHECK: "-fmodule-file-cache-key"
59+
// CHECK: "[[PREFIX]]/outputs/[[HASH]]/Mod-[[HASH]].pcm"
60+
// CHECK: "llvmcas://[[KEY]]"
61+
// CHECK: ]
62+
63+
//--- cdb1.json.template
64+
[{
65+
"directory": "DIR",
66+
"command": "clang -Xclang -fcas-plugin-path -Xclang /1 -Xclang -fcas-plugin-option -Xclang a=x -fsyntax-only DIR/tu.c -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache1",
67+
"file": "DIR/tu.c"
68+
}]
69+
70+
//--- cdb2.json.template
71+
[{
72+
"directory": "DIR",
73+
"command": "clang -Xclang -fcas-plugin-path -Xclang /2 -Xclang -fcas-plugin-option -Xclang b=y -fsyntax-only DIR/tu.c -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache2",
74+
"file": "DIR/tu.c"
75+
}]
76+
77+
//--- module.modulemap
78+
module Mod { header "Mod.h" }
79+
80+
//--- Mod.h
81+
82+
//--- tu.c
83+
#include "Mod.h"

0 commit comments

Comments
 (0)