diff options
| author | Peter Kokai <kokaipeter@gmail.com> | 2019-12-30 00:22:55 -0800 |
|---|---|---|
| committer | Fangrui Song <maskray@google.com> | 2019-12-30 00:42:46 -0800 |
| commit | 36ae255663cfbe1813fcda7de421e3e10c00c91b (patch) | |
| tree | 7b367dbb67dcc2b4bb886d619e19a9f2797f64a8 /llvm/tools | |
| parent | b47b35ff51b355a446483777155290541ab64fae (diff) | |
| download | bcm5719-llvm-36ae255663cfbe1813fcda7de421e3e10c00c91b.tar.gz bcm5719-llvm-36ae255663cfbe1813fcda7de421e3e10c00c91b.zip | |
[opt] Fix run-twice crash and detection problem
1. Execute `opt -run-twice a.ll` with in a terminal will crash.
https://bugs.llvm.org/show_bug.cgi?id=44382
2. `-run-twice` saves output into two buffers and compares them.
When outputing the result is disabled, that produces two empty string thus
they are going to be equal all the time resulting false-positive results.
The proposed solution is to generate the results even if the output will not be
emitted, as that is required for the comparision.
Differential Revision: https://reviews.llvm.org/D71967
Diffstat (limited to 'llvm/tools')
| -rw-r--r-- | llvm/tools/opt/opt.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp index e701000f697..1cfc56e1f56 100644 --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -901,8 +901,10 @@ int main(int argc, char **argv) { 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 @@ int main(int argc, char **argv) { "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()) |

