[LinkerWrapper] Fix save-temps and argument name
authorJoseph Huber <jhuber6@vols.utk.edu>
Fri, 8 Jul 2022 15:37:15 +0000 (11:37 -0400)
committerJoseph Huber <jhuber6@vols.utk.edu>
Fri, 8 Jul 2022 15:38:33 +0000 (11:38 -0400)
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=`.

clang/lib/Driver/ToolChains/Clang.cpp
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

index c11806f..10d2b92 100644 (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));
   }
 
index 75e1a1b..06e5cf8 100644 (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);