[llvm] e39e9d3 - llvm-reduce: Fix crashing on file opening error for mir path

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 27 15:15:57 PDT 2022


Author: Matt Arsenault
Date: 2022-04-27T18:15:12-04:00
New Revision: e39e9d339c94cb7f421403a2980998b4a4b6a1a1

URL: https://github.com/llvm/llvm-project/commit/e39e9d339c94cb7f421403a2980998b4a4b6a1a1
DIFF: https://github.com/llvm/llvm-project/commit/e39e9d339c94cb7f421403a2980998b4a4b6a1a1.diff

LOG: llvm-reduce: Fix crashing on file opening error for mir path

Added: 
    llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir

Modified: 
    llvm/tools/llvm-reduce/ReducerWorkItem.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir b/llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
new file mode 100644
index 000000000000..3f70ff0dd819
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
@@ -0,0 +1,4 @@
+# REQUIRES: amdgpu-registered-target
+# RUN: not llvm-reduce -mtriple=amdgcn-amd-amdhsa --test FileCheck --test-arg %s --test-arg --input-file does-not-exist.mir 2>&1 | FileCheck -check-prefix=ERR %s
+
+# ERR: {{.*}}llvm-reduce{{.*}}: No such file or directory

diff  --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
index d77fe024e475..ce2068d40603 100644
--- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
+++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
@@ -300,6 +300,11 @@ parseReducerWorkItem(const char *ToolName, StringRef Filename,
 
   if (IsMIR) {
     auto FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/true);
+    if (std::error_code EC = FileOrErr.getError()) {
+      WithColor::error(errs(), ToolName) << EC.message() << '\n';
+      return nullptr;
+    }
+
     std::unique_ptr<MIRParser> MParser =
         createMIRParser(std::move(FileOrErr.get()), Ctxt);
 


        


More information about the llvm-commits mailing list