[llvm] 472c009 - [llvm-reduce] Exit when input module is malformed
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Tue May 25 10:01:18 PDT 2021
Author: Langston Barrett
Date: 2021-05-25T10:01:12-07:00
New Revision: 472c009139eaf5c516395e669b1a70b118a514f8
URL: https://github.com/llvm/llvm-project/commit/472c009139eaf5c516395e669b1a70b118a514f8
DIFF: https://github.com/llvm/llvm-project/commit/472c009139eaf5c516395e669b1a70b118a514f8.diff
LOG: [llvm-reduce] Exit when input module is malformed
The parseInputFile function returns an empty unique_ptr to signal an
error, like when the input file doesn't exist, or is malformed. In this
case, the tool should exit immediately rather than segfault by
dereferencing the unique_ptr later.
Reviewed By: aeubanks
Differential Revision: https://reviews.llvm.org/D102891
Added:
llvm/test/tools/llvm-reduce/fail-file-open.test
Modified:
llvm/tools/llvm-reduce/llvm-reduce.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-reduce/fail-file-open.test b/llvm/test/tools/llvm-reduce/fail-file-open.test
new file mode 100644
index 0000000000000..1136e1dbce5d4
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/fail-file-open.test
@@ -0,0 +1,5 @@
+# RUN: not llvm-reduce --test=echo %s.NotAFileInTestingDir 2>&1 | FileCheck %s
+
+This file will not be read. An invalid file path is fed to llvm-reduce.
+
+# CHECK: llvm-reduce: {{.*}}.NotAFileInTestingDir: error:
\ No newline at end of file
diff --git a/llvm/tools/llvm-reduce/llvm-reduce.cpp b/llvm/tools/llvm-reduce/llvm-reduce.cpp
index 5a00ef0ed8c70..614ca45144c25 100644
--- a/llvm/tools/llvm-reduce/llvm-reduce.cpp
+++ b/llvm/tools/llvm-reduce/llvm-reduce.cpp
@@ -116,6 +116,10 @@ int main(int Argc, char **Argv) {
std::unique_ptr<Module> OriginalProgram =
parseInputFile(InputFilename, Context);
+ if (!OriginalProgram) {
+ return 1;
+ }
+
// Initialize test environment
TestRunner Tester(TestFilename, TestArguments);
Tester.setProgram(std::move(OriginalProgram));
More information about the llvm-commits
mailing list