[llvm-reduce] Fix a bug, improve error handling when running test
authorReid Kleckner <rnk@google.com>
Wed, 11 Sep 2019 20:29:22 +0000 (20:29 +0000)
committerReid Kleckner <rnk@google.com>
Wed, 11 Sep 2019 20:29:22 +0000 (20:29 +0000)
llvm::sys::ExecuteAndWait can report errors, so let's make use of that.

Second, while iterating uses of functions to remove, a call can appear
multiple times. Use a SetVector so we don't attempt to erase such a call
twice.

llvm-svn: 371653

llvm/tools/llvm-reduce/TestRunner.cpp
llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp

index 2fd01ab..1940e42 100644 (file)
@@ -44,10 +44,14 @@ int TestRunner::run(StringRef Filename) {
     ProgramArgs.push_back(Arg.c_str());
 
   Optional<StringRef> Redirects[3]; // STDIN, STDOUT, STDERR
-  int Result = sys::ExecuteAndWait(TestName, ProgramArgs, None, Redirects);
+  std::string ErrMsg;
+  int Result =
+      sys::ExecuteAndWait(TestName, ProgramArgs, None, Redirects,
+                          /*SecondsToWait=*/0, /*MemoryLimit=*/0, &ErrMsg);
 
   if (Result < 0) {
-    Error E = make_error<StringError>("Error running interesting-ness test\n",
+    Error E = make_error<StringError>("Error running interesting-ness test: " +
+                                          ErrMsg,
                                       inconvertibleErrorCode());
     errs() << toString(std::move(E));
     exit(1);
index 450f78c..84dc842 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "ReduceFunctions.h"
 #include "Delta.h"
+#include "llvm/ADT/SetVector.h"
 #include <set>
 
 using namespace llvm;
@@ -35,13 +36,13 @@ static void extractFunctionsFromModule(const std::vector<Chunk> &ChunksToKeep,
 
   // Delete out-of-chunk functions, and replace their calls with undef
   std::vector<Function *> FuncsToRemove;
-  std::vector<CallInst *> CallsToRemove;
+  SetVector<CallInst *> CallsToRemove;
   for (auto &F : *Program)
     if (!FuncsToKeep.count(&F)) {
       for (auto U : F.users())
         if (auto *Call = dyn_cast<CallInst>(U)) {
           Call->replaceAllUsesWith(UndefValue::get(Call->getType()));
-          CallsToRemove.push_back(Call);
+          CallsToRemove.insert(Call);
         }
       F.replaceAllUsesWith(UndefValue::get(F.getType()));
       FuncsToRemove.push_back(&F);