Skip to content

Commit 593f1bf

Browse files
authored
Merge pull request #10609 from cachemeifyoucan/eng/PR-149707188-release
[6.2][CAS] Improve error message when module cache key is missing
2 parents 6f7787b + 5da2f66 commit 593f1bf

File tree

6 files changed

+40
-37
lines changed

6 files changed

+40
-37
lines changed

clang/include/clang/Basic/DiagnosticCASKinds.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ def err_cas_depscan_daemon_connection: Error<
2323
def err_cas_depscan_failed: Error<
2424
"CAS-based dependency scan failed: %0">, DefaultFatal;
2525
def err_cas_store: Error<"failed to store to CAS: %0">, DefaultFatal;
26-
def err_cas_cannot_get_module_cache_key : Error<
27-
"CAS cannot load module with key '%0' from %1: %2">, DefaultFatal;
26+
def err_cas_unloadable_module : Error<
27+
"module file '%0' not found: unloadable module cache key %1: %2">, DefaultFatal;
28+
def err_cas_missing_module : Error<
29+
"module file '%0' not found: missing module cache key %1: %2">, DefaultFatal;
2830
def err_cas_missing_root_id : Error<
2931
"CAS missing expected root-id '%0'">, DefaultFatal;
3032
def err_cas_cannot_parse_root_id_for_module : Error<

clang/lib/Frontend/CompileJobCacheKey.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,7 @@ Error clang::printCompileJobCacheKey(ObjectStore &CAS, const CASID &Key,
304304
if (!H)
305305
return H.takeError();
306306
TreeSchema Schema(CAS);
307-
if (!Schema.isNode(*H)) {
308-
std::string ErrStr;
309-
llvm::raw_string_ostream Err(ErrStr);
310-
Err << "expected cache key to be a CAS tree; got ";
311-
H->getID().print(Err);
312-
return createStringError(inconvertibleErrorCode(), Err.str());
313-
}
307+
if (!Schema.isNode(*H))
308+
return createStringError("unexpected cache key schema");
314309
return ::printCompileJobCacheKey(CAS, *H, OS);
315310
}

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,40 +2543,45 @@ static bool addCachedModuleFileToInMemoryCache(
25432543

25442544
auto ID = CAS.parseID(CacheKey);
25452545
if (!ID) {
2546-
Diags.Report(diag::err_cas_cannot_get_module_cache_key)
2547-
<< CacheKey << Provider << ID.takeError();
2546+
Diags.Report(diag::err_cas_unloadable_module)
2547+
<< Path << CacheKey << ID.takeError();
25482548
return true;
25492549
}
25502550

25512551
auto Value = Cache.get(*ID);
2552-
if (!Value || !*Value) {
2553-
auto Diag = Diags.Report(diag::err_cas_cannot_get_module_cache_key)
2554-
<< CacheKey << Provider;
2555-
if (!Value) {
2556-
Diag << Value.takeError();
2557-
} else {
2558-
std::string ErrStr("no such entry in action cache; expected compile:\n");
2559-
llvm::raw_string_ostream Err(ErrStr);
2560-
if (auto E = printCompileJobCacheKey(CAS, *ID, Err))
2561-
Diag << std::move(E);
2562-
else
2563-
Diag << Err.str();
2564-
}
2552+
if (!Value) {
2553+
Diags.Report(diag::err_cas_unloadable_module)
2554+
<< Path << CacheKey << Value.takeError();
2555+
return true;
2556+
}
2557+
if (!*Value) {
2558+
auto Diag = Diags.Report(diag::err_cas_missing_module)
2559+
<< Path << CacheKey;
2560+
std::string ErrStr("expected to be produced by:\n");
2561+
llvm::raw_string_ostream Err(ErrStr);
2562+
if (auto E = printCompileJobCacheKey(CAS, *ID, Err)) {
2563+
// Ignore the error and skip printing the cache key. The cache key can
2564+
// be setup by a different compiler that is using an unknown schema.
2565+
llvm::consumeError(std::move(E));
2566+
Diag << "module file is not available in the CAS";
2567+
} else
2568+
Diag << Err.str();
2569+
25652570
return true;
25662571
}
25672572
auto ValueRef = CAS.getReference(**Value);
25682573
if (!ValueRef) {
2569-
Diags.Report(diag::err_cas_cannot_get_module_cache_key)
2570-
<< CacheKey << Provider << "result module doesn't exist in CAS";
2574+
Diags.Report(diag::err_cas_unloadable_module)
2575+
<< Path << CacheKey << "result module cannot be loaded from CAS";
25712576

25722577
return true;
25732578
}
25742579

25752580
std::optional<cas::CompileJobCacheResult> Result;
25762581
cas::CompileJobResultSchema Schema(CAS);
25772582
if (llvm::Error E = Schema.load(*ValueRef).moveInto(Result)) {
2578-
Diags.Report(diag::err_cas_cannot_get_module_cache_key)
2579-
<< CacheKey << Provider << std::move(E);
2583+
Diags.Report(diag::err_cas_unloadable_module)
2584+
<< Path << CacheKey << std::move(E);
25802585
return true;
25812586
}
25822587
auto Output =
@@ -2589,8 +2594,8 @@ static bool addCachedModuleFileToInMemoryCache(
25892594
// better network utilization.
25902595
auto OutputProxy = CAS.getProxy(Output->Object);
25912596
if (!OutputProxy) {
2592-
Diags.Report(diag::err_cas_cannot_get_module_cache_key)
2593-
<< CacheKey << Provider << OutputProxy.takeError();
2597+
Diags.Report(diag::err_cas_unloadable_module)
2598+
<< Path << CacheKey << OutputProxy.takeError();
25942599
return true;
25952600
}
25962601

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,10 +657,11 @@ static void checkCompileCacheKeyMatch(cas::ObjectStore &CAS,
657657
llvm::report_fatal_error(OldKey.takeError());
658658
SmallString<256> Err;
659659
llvm::raw_svector_ostream OS(Err);
660-
OS << "Compile cache key for module changed; previously:";
660+
OS << "Compile cache key for module changed; previously: "
661+
<< OldKey->toString() << ": ";
661662
if (auto E = printCompileJobCacheKey(CAS, *OldKey, OS))
662663
OS << std::move(E);
663-
OS << "\nkey is now:";
664+
OS << "\nkey is now: " << NewKey.toString() << ": ";
664665
if (auto E = printCompileJobCacheKey(CAS, NewKey, OS))
665666
OS << std::move(E);
666667
llvm::report_fatal_error(OS.str());

clang/test/CAS/fmodule-file-cache-key-errors.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// RUN: -fcache-compile-job -Rcompile-job-cache &> %t/invalid2.txt
2727
// RUN: FileCheck %s -check-prefix=INVALID2 -input-file=%t/invalid2.txt
2828

29-
// INVALID2: error: CAS cannot load module with key '-fsyntax-only' from -fmodule-file-cache-key
29+
// INVALID2: error: module file 'INVALID' not found: unloadable module cache key -fsyntax-only: invalid cas-id '-fsyntax-only'
3030

3131
// RUN: not %clang_cc1 -triple x86_64-apple-macos11 \
3232
// RUN: -fmodules -fno-implicit-modules \
@@ -46,7 +46,7 @@
4646
// RUN: -fcache-compile-job -Rcompile-job-cache &> %t/bad_key.txt
4747
// RUN: cat %t/bad_key.txt | FileCheck %s -check-prefix=BAD_KEY
4848

49-
// BAD_KEY: error: CAS cannot load module with key 'KEY' from -fmodule-file-cache-key: invalid cas-id 'KEY'
49+
// BAD_KEY: error: module file 'PATH' not found: unloadable module cache key KEY: invalid cas-id 'KEY'
5050

5151
// RUN: echo -n '-fmodule-file-cache-key PATH ' > %t/bad_key2.rsp
5252
// RUN: cat %t/casid >> %t/bad_key2.rsp
@@ -59,7 +59,7 @@
5959
// RUN: -fcache-compile-job -Rcompile-job-cache &> %t/bad_key2.txt
6060
// RUN: cat %t/bad_key2.txt | FileCheck %s -check-prefix=BAD_KEY2
6161

62-
// BAD_KEY2: error: CAS cannot load module with key '{{.*}}' from -fmodule-file-cache-key: cas object is not a valid cache key
62+
// BAD_KEY2: error: module file 'PATH' not found: missing module cache key {{.*}}: module file is not available in the CAS
6363

6464
// == Build A
6565

@@ -87,7 +87,7 @@
8787
// RUN: -fcache-compile-job -Rcompile-job-cache &> %t/not_in_cache.txt
8888
// RUN: cat %t/not_in_cache.txt | FileCheck %s -check-prefix=NOT_IN_CACHE -DPREFIX=%/t
8989

90-
// NOT_IN_CACHE: error: CAS cannot load module with key '{{.*}}' from -fmodule-file-cache-key: no such entry in action cache; expected compile:
90+
// NOT_IN_CACHE: error: module file 'PATH' not found: missing module cache key {{.*}}: expected to be produced by:
9191
// NOT_IN_CACHE: command-line:
9292
// NOT_IN_CACHE: -cc1
9393
// NOT_IN_CACHE: filesystem:

clang/test/ClangScanDeps/modules-cas-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
// Missing pcm in action cache
4343
// RUN: not %clang @%t/Left.rsp 2> %t/error.txt
4444
// RUN: cat %t/error.txt | FileCheck %s -check-prefix=MISSING
45-
// MISSING: error: CAS cannot load module with key '{{.*}}' from -fmodule-file-cache-key: no such entry in action cache
45+
// MISSING: error: module file '{{.*}}.pcm' not found: missing module cache key {{.*}}: expected to be produced by:
4646

4747
// Build everything
4848
// RUN: %clang @%t/Top.rsp 2>&1 | FileCheck %s -check-prefix=CACHE-MISS

0 commit comments

Comments
 (0)