[PATCH] D102891: [llvm-reduce] Exit when input module is malformed

Langston Barrett via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 20 17:08:19 PDT 2021


langston-barrett created this revision.
langston-barrett requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102891

Files:
  llvm/tools/llvm-reduce/llvm-reduce.cpp


Index: llvm/tools/llvm-reduce/llvm-reduce.cpp
===================================================================
--- llvm/tools/llvm-reduce/llvm-reduce.cpp
+++ llvm/tools/llvm-reduce/llvm-reduce.cpp
@@ -116,6 +116,10 @@
   std::unique_ptr<Module> OriginalProgram =
       parseInputFile(InputFilename, Context);
 
+  if (!OriginalProgram) {
+    return 1;
+  }
+
   // Initialize test environment
   TestRunner Tester(TestFilename, TestArguments);
   Tester.setProgram(std::move(OriginalProgram));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102891.346897.patch
Type: text/x-patch
Size: 499 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210521/51e60726/attachment.bin>


More information about the llvm-commits mailing list