[LinkerWrapper] Fix save-temps and argument name

Summary:
The previous path reworked some handling of temporary files which
exposed some bugs related to capturing local state by reference in the
callback labmda. Squashing this by copying in everything instead. There
was also a problem where the argument name was changed for
`--bitcode-library=` but clang still used `--target-library=`.
This commit is contained in:
Joseph Huber 2022-07-08 11:37:15 -04:00
parent d287051404
commit 74a8fce6e8
2 changed files with 7 additions and 11 deletions

View File

@ -8393,7 +8393,7 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
for (StringRef LibName : BCLibs)
CmdArgs.push_back(Args.MakeArgString(
"--target-library=" + Action::GetOffloadKindName(Action::OFK_OpenMP) +
"--bitcode-library=" + Action::GetOffloadKindName(Action::OFK_OpenMP) +
"-" + TC->getTripleString() + "-" + Arch + "=" + LibName));
}

View File

@ -236,7 +236,7 @@ Expected<StringRef> createOutputFile(const Twine &Prefix, StringRef Extension) {
return createFileError(OutputFile, EC);
}
TempFiles.push_back(OutputFile);
TempFiles.emplace_back(std::move(OutputFile));
return TempFiles.back();
}
@ -771,16 +771,12 @@ std::unique_ptr<lto::LTO> createLTO(
Conf.PTO.SLPVectorization = Conf.OptLevel > 1;
if (SaveTemps) {
Conf.PostInternalizeModuleHook = [&, Arch](size_t, const Module &M) {
auto TempFileOrErr =
createOutputFile(sys::path::filename(ExecutableName) + "-" +
Triple.getTriple() + "-" + Arch,
"bc");
if (!TempFileOrErr)
reportError(TempFileOrErr.takeError());
std::string TempName = (sys::path::filename(ExecutableName) + "-" +
Triple.getTriple() + "-" + Arch + ".bc")
.str();
Conf.PostInternalizeModuleHook = [=](size_t, const Module &M) {
std::error_code EC;
raw_fd_ostream LinkedBitcode(*TempFileOrErr, EC, sys::fs::OF_None);
raw_fd_ostream LinkedBitcode(TempName, EC, sys::fs::OF_None);
if (EC)
reportError(errorCodeToError(EC));
WriteBitcodeToFile(M, LinkedBitcode);