Skip to content

Commit 2cd3dc3

Browse files
Fix bug with -fcas-emit-casid-file during replay.
When using MCCAS replay with the option -fcas-emit-casid-file, we would see the error: fatal error: caching backend error: cached output file has unknown path <path-to-file>/file.casid This patch fixes that issue by just having a raw_fd_ostream in the CompilerInstance that points to the .casid file rather than having it be one of the outputs of the CompilerInstance. This patch also makes sure that the .casid file is written even if there is a ResultCallback in the MachOCASWriter.
1 parent 9594299 commit 2cd3dc3

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,11 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
10481048
BA == Backend_EmitObj && OutputFile != "-") {
10491049
std::string OutputPathCASIDFile = std::string(OutputFile);
10501050
OutputPathCASIDFile.append(".casid");
1051-
CasIDOS = CI.createOutputFile(OutputPathCASIDFile, true, true,
1052-
CI.getFrontendOpts().UseTemporary, false);
1051+
std::error_code EC;
1052+
CasIDOS = std::make_unique<raw_fd_ostream>(OutputPathCASIDFile, EC);
1053+
if (EC)
1054+
CI.getDiagnostics().Report(diag::err_fe_unable_to_open_output)
1055+
<< EC.message();
10531056
}
10541057
}
10551058

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// REQUIRES: x86-registered-target
2+
// RUN: rm -rf %t && mkdir %t
3+
4+
// RUN: %clang -cc1depscan -o %t/args.rsp -cc1-args -cc1 -triple x86_64-apple-darwin10 \
5+
// RUN: -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=lldb \
6+
// RUN: -emit-obj -fcas-backend -fcas-path %t/cas -fcas-emit-casid-file %s
7+
8+
// RUN: %clang @%t/args.rsp -o %t/output1.o
9+
10+
// cat %t/output1.o.casid | FileCheck %s
11+
12+
// CHECK: llvmcas://{{[a-z0-9]+}}
13+
14+
int foo(int x) {
15+
return x+1;
16+
}

llvm/lib/MC/MachOCASWriter.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ uint64_t MachOCASWriter::writeObject(MCAssembler &Asm,
8080

8181
return Error::success();
8282
};
83+
84+
if (CasIDOS)
85+
writeCASIDBuffer(CASObj.getID(), *CasIDOS);
86+
8387
// If there is a callback, then just hand off the result through callback.
8488
if (ResultCallBack) {
8589
cantFail((*ResultCallBack)(CASObj.getID()));
@@ -115,9 +119,6 @@ uint64_t MachOCASWriter::writeObject(MCAssembler &Asm,
115119
}
116120
}
117121

118-
if (CasIDOS)
119-
writeCASIDBuffer(CASObj.getID(), *CasIDOS);
120-
121122
return OS.tell() - StartOffset;
122123
}
123124

0 commit comments

Comments
 (0)