diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -901,8 +901,10 @@ std::unique_ptr 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())