Skip to content

Commit 64e7610

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. (cherry picked from commit 2cd3dc3)
1 parent c385bf3 commit 64e7610

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
@@ -1093,8 +1093,11 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
10931093
BA == Backend_EmitObj && OutputFile != "-") {
10941094
std::string OutputPathCASIDFile = std::string(OutputFile);
10951095
OutputPathCASIDFile.append(".casid");
1096-
CasIDOS = CI.createOutputFile(OutputPathCASIDFile, true, true,
1097-
CI.getFrontendOpts().UseTemporary, false);
1096+
std::error_code EC;
1097+
CasIDOS = std::make_unique<raw_fd_ostream>(OutputPathCASIDFile, EC);
1098+
if (EC)
1099+
CI.getDiagnostics().Report(diag::err_fe_unable_to_open_output)
1100+
<< EC.message();
10981101
}
10991102
}
11001103

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)