diff options
author | David Blaikie <dblaikie@gmail.com> | 2019-09-12 00:31:57 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2019-09-12 00:31:57 +0000 |
commit | aaef97a55e4885e95c8528e6dc761a63323d19b3 (patch) | |
tree | 10b97fb8dd2c87133d4f3cdf6a52e12c92437367 /llvm/tools/llvm-reduce/llvm-reduce.cpp | |
parent | 635d383fad2baef4cb4b241c8dd31c91913c0f32 (diff) | |
download | bcm5719-llvm-aaef97a55e4885e95c8528e6dc761a63323d19b3.tar.gz bcm5719-llvm-aaef97a55e4885e95c8528e6dc761a63323d19b3.zip |
PR43278: llvm-reduce: Use temporary file names (and ToolOutputFile) rather than unique ones - to ensure they're cleaned up
This modifies the tool somewhat to only create files when about to run
the "interestingness" test, and delete them immediately after - this
means some more files will be created sometimes (when "double checking"
work - which should probably be fixed/avoided anyway).
This now creates temporary files, rather than only unique ones, and also
uses ToolOutputFile (without ever calling "keep") to ensure the files
are deleted as soon as the interestingness test is run.
llvm-svn: 371696
Diffstat (limited to 'llvm/tools/llvm-reduce/llvm-reduce.cpp')
-rw-r--r-- | llvm/tools/llvm-reduce/llvm-reduce.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/llvm/tools/llvm-reduce/llvm-reduce.cpp b/llvm/tools/llvm-reduce/llvm-reduce.cpp index 6836e1dbee4..83dcf980a78 100644 --- a/llvm/tools/llvm-reduce/llvm-reduce.cpp +++ b/llvm/tools/llvm-reduce/llvm-reduce.cpp @@ -81,14 +81,13 @@ int main(int argc, char **argv) { parseInputFile(InputFilename, Context); // Initialize test environment - TestRunner Tester(TestFilename, TestArguments, InputFilename); + TestRunner Tester(TestFilename, TestArguments); Tester.setProgram(std::move(OriginalProgram)); // Try to reduce code runDeltaPasses(Tester); - StringRef ReducedFilename = sys::path::filename(Tester.getReducedFilepath()); - if (ReducedFilename == sys::path::filename(InputFilename)) { + if (!Tester.getProgram()) { errs() << "\nCouldnt reduce input :/\n"; } else { // Print reduced file to STDOUT @@ -100,7 +99,13 @@ int main(int argc, char **argv) { else if (OutputFilename.empty()) OutputFilename = "reduced.ll"; - sys::fs::copy_file(Tester.getReducedFilepath(), OutputFilename); + std::error_code EC; + raw_fd_ostream Out(OutputFilename, EC); + if (EC) { + errs() << "Error opening output file: " << EC.message() << "!\n"; + exit(1); + } + Tester.getProgram()->print(Out, /*AnnotationWriter=*/nullptr); errs() << "\nDone reducing! Reduced testcase: " << OutputFilename << "\n"; } } |