Skip to content

Commit df22cff

Browse files
committed
[clang][cas] Prevent module cache sharing between cas-fs and include-tree
Modules built by the dependency scanner for include-tree and cas-fs are not compatible, so prevent them from being shared by modifying the hash. rdar://108746813 (cherry picked from commit 6b8edd2)
1 parent 7266dc6 commit df22cff

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ class FrontendOptions {
371371
/// is specified.
372372
unsigned CacheCompileJob : 1;
373373

374+
/// Whether this invocation is dependency scanning for include-tree. Used to
375+
/// separate module cache for include-tree from cas-fs.
376+
unsigned ForIncludeTreeScan : 1;
377+
374378
/// Avoid checking if the compile job is already cached, force compilation and
375379
/// caching of compilation outputs. This is used for testing purposes.
376380
unsigned DisableCachedCompileJobReplay : 1;
@@ -574,7 +578,7 @@ class FrontendOptions {
574578
ASTDumpLookups(false), BuildingImplicitModule(false),
575579
BuildingImplicitModuleUsesLock(true), ModulesEmbedAllFiles(false),
576580
IncludeTimestamps(true), UseTemporary(true), CacheCompileJob(false),
577-
DisableCachedCompileJobReplay(false),
581+
ForIncludeTreeScan(false), DisableCachedCompileJobReplay(false),
578582
MayEmitDiagnosticsAfterProcessingSourceFiles(false),
579583
AllowPCMWithCompilerErrors(false),
580584
ModulesShareFileManager(true), TimeTraceGranularity(500) {}

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5234,8 +5234,9 @@ std::string CompilerInvocation::getModuleHash(DiagnosticsEngine &Diags) const {
52345234
}
52355235

52365236
// Caching + implicit modules, which is only set in clang-scan-deps, puts
5237-
// additional CASIDs in the pcm.
5238-
HBuilder.add(getFrontendOpts().CacheCompileJob);
5237+
// additional CASIDs in the pcm for either cas-fs or include-tree.
5238+
HBuilder.add(getFrontendOpts().CacheCompileJob,
5239+
getFrontendOpts().ForIncludeTreeScan);
52395240

52405241
llvm::MD5::MD5Result Result;
52415242
HBuilder.getHasher().final(Result);

clang/lib/Tooling/DependencyScanning/IncludeTreeActionController.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ Error IncludeTreeActionController::initialize(
327327

328328
// Enable caching in the resulting commands.
329329
ScanInstance.getFrontendOpts().CacheCompileJob = true;
330+
ScanInstance.getFrontendOpts().ForIncludeTreeScan = true;
330331
CASOpts = ScanInstance.getCASOpts();
331332

332333
return Error::success();
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Check that using the same module cache does not cause errors when switching
2+
// between cas-fs and include-tree.
3+
4+
// RUN: rm -rf %t
5+
// RUN: split-file %s %t
6+
// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
7+
8+
// RUN: clang-scan-deps -compilation-database %t/cdb.json \
9+
// RUN: -cas-path %t/cas -module-files-dir %t/outputs \
10+
// RUN: -format experimental-include-tree-full | FileCheck %s -check-prefix=INCLUDE_TREE
11+
12+
// RUN: clang-scan-deps -compilation-database %t/cdb.json \
13+
// RUN: -cas-path %t/cas -module-files-dir %t/outputs \
14+
// RUN: -format experimental-full | FileCheck %s -check-prefix=CAS_FS
15+
16+
// INCLUDE_TREE: "-fcas-include-tree"
17+
// CAS_FS: "-fcas-fs"
18+
19+
//--- cdb.json.template
20+
[{
21+
"file": "DIR/tu.c",
22+
"directory": "DIR",
23+
"command": "clang -fsyntax-only -fmodules -fimplicit-modules -fmodules-cache-path=DIR/mcp DIR/tu.c"
24+
}]
25+
26+
//--- module.modulemap
27+
module M { header "M.h" }
28+
29+
//--- M.h
30+
31+
//--- tu.c
32+
#include "M.h"

0 commit comments

Comments
 (0)