Author: Joseph Huber
Date: 2022-07-08T11:38:33-04:00
New Revision: 74a8fce6e87e81802b4fe69769daec19504753bf

URL: 
https://github.com/llvm/llvm-project/commit/74a8fce6e87e81802b4fe69769daec19504753bf
DIFF: 
https://github.com/llvm/llvm-project/commit/74a8fce6e87e81802b4fe69769daec19504753bf.diff

LOG: [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=`.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index c11806ff692a..10d2b9202b7c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -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));
   }
 

diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 75e1a1b8a72c..06e5cf843da0 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -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);


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to