Skip to content

[CAS] Improve error message when module cache key is missing #10517

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

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions clang/lib/Frontend/CompileJobCacheKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,7 @@ Error clang::printCompileJobCacheKey(ObjectStore &CAS, const CASID &Key,
if (!H)
return H.takeError();
TreeSchema Schema(CAS);
if (!Schema.isNode(*H)) {
std::string ErrStr;
llvm::raw_string_ostream Err(ErrStr);
Err << "expected cache key to be a CAS tree; got ";
H->getID().print(Err);
return createStringError(inconvertibleErrorCode(), Err.str());
}
if (!Schema.isNode(*H))
return createStringError("unexpected cache key schema");
return ::printCompileJobCacheKey(CAS, *H, OS);
}
12 changes: 8 additions & 4 deletions clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2591,11 +2591,15 @@ static bool addCachedModuleFileToInMemoryCache(
if (!Value) {
Diag << Value.takeError();
} else {
std::string ErrStr("no such entry in action cache; expected compile:\n");
std::string ErrStr("module file is not available in the CAS; expected to "
"be produced by:\n");
llvm::raw_string_ostream Err(ErrStr);
if (auto E = printCompileJobCacheKey(CAS, *ID, Err))
Diag << std::move(E);
else
if (auto E = printCompileJobCacheKey(CAS, *ID, Err)) {
// Ignore the error and skip printing the cache key. The cache key can
// be setup by a different compiler that is using an unknown schema.
llvm::consumeError(std::move(E));
Diag << "module file is not available in the CAS";
} else
Diag << Err.str();
}
return true;
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,11 @@ static void checkCompileCacheKeyMatch(cas::ObjectStore &CAS,
llvm::report_fatal_error(OldKey.takeError());
SmallString<256> Err;
llvm::raw_svector_ostream OS(Err);
OS << "Compile cache key for module changed; previously:";
OS << "Compile cache key for module changed; previously: "
<< OldKey->toString() << ": ";
if (auto E = printCompileJobCacheKey(CAS, *OldKey, OS))
OS << std::move(E);
OS << "\nkey is now:";
OS << "\nkey is now: " << NewKey.toString() << ": ";
if (auto E = printCompileJobCacheKey(CAS, NewKey, OS))
OS << std::move(E);
llvm::report_fatal_error(OS.str());
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CAS/fmodule-file-cache-key-errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
// RUN: -fcache-compile-job -Rcompile-job-cache &> %t/bad_key2.txt
// RUN: cat %t/bad_key2.txt | FileCheck %s -check-prefix=BAD_KEY2

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

// == Build A

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

// NOT_IN_CACHE: error: CAS cannot load module with key '{{.*}}' from -fmodule-file-cache-key: no such entry in action cache; expected compile:
// NOT_IN_CACHE: error: CAS cannot load module with key '{{.*}}' from -fmodule-file-cache-key: module file is not available in the CAS; expected to be produced by:
// NOT_IN_CACHE: command-line:
// NOT_IN_CACHE: -cc1
// NOT_IN_CACHE: filesystem:
Expand Down
2 changes: 1 addition & 1 deletion clang/test/ClangScanDeps/modules-cas-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
// Missing pcm in action cache
// RUN: not %clang @%t/Left.rsp 2> %t/error.txt
// RUN: cat %t/error.txt | FileCheck %s -check-prefix=MISSING
// MISSING: error: CAS cannot load module with key '{{.*}}' from -fmodule-file-cache-key: no such entry in action cache
// MISSING: error: CAS cannot load module with key '{{.*}}' from -fmodule-file-cache-key: module file is not available in the CAS

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