Skip to content

Cherry-pick https://github.com/swiftlang/llvm-project/pull/9164 to next #9190

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

Merged
merged 1 commit into from
Aug 28, 2024
Merged
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
7 changes: 2 additions & 5 deletions clang/lib/Frontend/CompileJobCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ Error ObjectStoreCachingOutputs::finishComputedResult(
std::optional<int> ObjectStoreCachingOutputs::replayCachedResult(
const llvm::cas::CASID &ResultCacheKey, llvm::cas::ObjectRef ResultID,
bool JustComputedResult) {
if (JustComputedResult && !ComputedJobNeedsReplay)
if (JustComputedResult && !WriteOutputAsCASID)
return std::nullopt;

// FIXME: Stop calling report_fatal_error().
Expand All @@ -745,10 +745,7 @@ std::optional<int> ObjectStoreCachingOutputs::replayCachedResult(
Expected<std::optional<int>> ObjectStoreCachingOutputs::replayCachedResult(
const llvm::cas::CASID &ResultCacheKey,
clang::cas::CompileJobCacheResult &Result, bool JustComputedResult) {
// FIXME: The correct fix for MCCAS replay is that you have an official CASID
// file output going all the way down into ObjectWriter, we can remove this
// callback and special case.
if (JustComputedResult && !ComputedJobNeedsReplay)
if (JustComputedResult && !WriteOutputAsCASID)
return std::nullopt;

llvm::cas::ObjectStore &CAS = Result.getCAS();
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CAS/cas-backend.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: llvm-cas --cas %t/cas --ingest %s > %t/casid
//
// RUN: %clang -cc1 -triple x86_64-apple-macos11 -fcas-backend \
// RUN: %clang -cc1 -fcas-emit-casid-file -triple x86_64-apple-macos11 -fcas-backend \
// RUN: -fcas-path %t/cas -fcas-fs @%t/casid -fcache-compile-job \
// RUN: -Rcompile-job-cache %s -emit-obj -o %t/output.o \
// RUN: -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=lldb \
Expand All @@ -11,7 +11,7 @@
// RUN: ls %t/output.o && rm %t/output.o
// RUN: ls %t/deps.d && mv %t/deps.d %t/deps.d.orig
//
// RUN: CLANG_CAS_BACKEND_SAVE_CASID_FILE=1 %clang -cc1 \
// RUN: %clang -cc1 -fcas-emit-casid-file\
// RUN: -triple x86_64-apple-macos11 -fcas-backend \
// RUN: -fcas-path %t/cas -fcas-fs @%t/casid -fcache-compile-job \
// RUN: -Rcompile-job-cache %s -emit-obj -o %t/output.o \
Expand Down
25 changes: 25 additions & 0 deletions clang/test/CAS/casid-output-test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: rm -rf %t && mkdir -p %t

// Check if -fcasid-output works on a cache miss with file based caching
// RUN: env LLVM_CACHE_CAS_PATH=%t/cas CLANG_CACHE_DISABLE_MCCAS=1 %clang-cache %clang -target x86_64-apple-macos11 -Xclang -fcasid-output -g -c %s -o %t/test.o
// RUN: cat %t/test.o | FileCheck %s
// RUN: rm -rf %t/test.o
// Check if -fcasid-output works on a cache hit with file based caching
// RUN: env LLVM_CACHE_CAS_PATH=%t/cas CLANG_CACHE_DISABLE_MCCAS=1 %clang-cache %clang -target x86_64-apple-macos11 -Xclang -fcasid-output -g -c %s -o %t/test.o
// RUN: cat %t/test.o | FileCheck %s
// RUN: rm -rf %t/test.o
// RUN: rm -rf %t/cas

// Check if -fcasid-output works on a cache miss with MCCAS
// RUN: env LLVM_CACHE_CAS_PATH=%t/cas %clang-cache %clang -target x86_64-apple-macos11 -Xclang -fcasid-output -g -c %s -o %t/test.o
// RUN: cat %t/test.o | FileCheck %s
// RUN: rm -rf %t/test.o

// Check if -fcasid-output works on a cache hit with MCCAS
// RUN: env LLVM_CACHE_CAS_PATH=%t/cas %clang-cache %clang -target x86_64-apple-macos11 -Xclang -fcasid-output -g -c %s -o %t/test.o
// RUN: cat %t/test.o | FileCheck %s

// CHECK: llvmcas://{{[a-f0-9]+}}


void foo() {}
17 changes: 2 additions & 15 deletions llvm/lib/MC/MachOCASWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ uint64_t MachOCASWriter::writeObject(MCAssembler &Asm) {
inconvertibleErrorCode(),
"CASBackend output round-trip verification error");

OS << ObjectBuffer;
return Error::success();
};

Expand All @@ -85,11 +86,6 @@ uint64_t MachOCASWriter::writeObject(MCAssembler &Asm) {
// If there is a callback, then just hand off the result through callback.
if (ResultCallBack) {
cantFail((*ResultCallBack)(CASObj.getID()));
if (Mode == CASBackendMode::Verify) {
if (auto E = VerifyObject())
report_fatal_error(std::move(E));
}
return 0;
}

switch (Mode) {
Expand All @@ -103,17 +99,8 @@ uint64_t MachOCASWriter::writeObject(MCAssembler &Asm) {
break;
}
case CASBackendMode::Verify: {
SmallString<512> ObjectBuffer;
raw_svector_ostream ObjectOS(ObjectBuffer);
auto E = SerializeObjectFile(CASObj, CAS, ObjectOS);
if (E)
if (auto E = VerifyObject())
report_fatal_error(std::move(E));

if (!ObjectBuffer.equals(InternalBuffer))
report_fatal_error("CASBackend output round-trip verification error");

OS << ObjectBuffer;
break;
}
}

Expand Down