[PATCH] D71967: [opt] Fix run-twice crash and detection problem

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 30 00:43:22 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rG36ae255663cf: [opt] Fix run-twice crash and detection problem (authored by Kokan, committed by MaskRay).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71967/new/

https://reviews.llvm.org/D71967

Files:
  llvm/tools/opt/opt.cpp


Index: llvm/tools/opt/opt.cpp
===================================================================
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -901,8 +901,10 @@
   std::unique_ptr<raw_svector_ostream> BOS;
   raw_ostream *OS = nullptr;
 
+  const bool ShouldEmitOutput = !NoOutput && !AnalyzeOnly;
+
   // Write bitcode or assembly to the output as the last step...
-  if (!NoOutput && !AnalyzeOnly) {
+  if (ShouldEmitOutput || RunTwice) {
     assert(Out);
     OS = &Out->os();
     if (RunTwice) {
@@ -950,13 +952,16 @@
              "Writing the result of the second run to the specified output.\n"
              "To generate the one-run comparison binary, just run without\n"
              "the compile-twice option\n";
-      Out->os() << BOS->str();
-      Out->keep();
+      if (ShouldEmitOutput) {
+        Out->os() << BOS->str();
+        Out->keep();
+      }
       if (RemarksFile)
         RemarksFile->keep();
       return 1;
     }
-    Out->os() << BOS->str();
+    if (ShouldEmitOutput)
+      Out->os() << BOS->str();
   }
 
   if (DebugifyEach && !DebugifyExport.empty())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71967.235560.patch
Type: text/x-patch
Size: 1108 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191230/d91a0e8d/attachment.bin>


More information about the llvm-commits mailing list