[PATCH] D69057: [Error] Make llvm::cantFail include the original error messages

Don Hinton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 17 14:46:47 PDT 2019


hintonda updated this revision to Diff 225526.
hintonda added a comment.

- Wrap new login in !NDEBUG.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69057/new/

https://reviews.llvm.org/D69057

Files:
  llvm/include/llvm/Support/Error.h
  llvm/unittests/Support/ErrorTest.cpp


Index: llvm/unittests/Support/ErrorTest.cpp
===================================================================
--- llvm/unittests/Support/ErrorTest.cpp
+++ llvm/unittests/Support/ErrorTest.cpp
@@ -390,7 +390,8 @@
   };
 
   EXPECT_DEATH(FailToHandle(),
-               "Failure value returned from cantFail wrapped call")
+               "Failure value returned from cantFail wrapped call\n"
+               "CustomError \\{7\\}")
       << "Unhandled Error in handleAllErrors call did not cause an "
          "abort()";
 }
@@ -409,7 +410,8 @@
   };
 
   EXPECT_DEATH(ReturnErrorFromHandler(),
-               "Failure value returned from cantFail wrapped call")
+               "Failure value returned from cantFail wrapped call\n"
+               "CustomError \\{7\\}")
       << " Error returned from handler in handleAllErrors call did not "
          "cause abort()";
 }
@@ -510,11 +512,12 @@
 // Test that cantFail results in a crash if you pass it a failure value.
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS && !defined(NDEBUG)
 TEST(Error, CantFailDeath) {
-  EXPECT_DEATH(
-      cantFail(make_error<StringError>("foo", inconvertibleErrorCode()),
-               "Cantfail call failed"),
-      "Cantfail call failed")
-    << "cantFail(Error) did not cause an abort for failure value";
+  EXPECT_DEATH(cantFail(make_error<StringError>("Original error message",
+                                                inconvertibleErrorCode()),
+                        "Cantfail call failed"),
+               "Cantfail call failed\n"
+               "Original error message")
+      << "cantFail(Error) did not cause an abort for failure value";
 
   EXPECT_DEATH(
       {
Index: llvm/include/llvm/Support/Error.h
===================================================================
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -704,6 +704,12 @@
   if (Err) {
     if (!Msg)
       Msg = "Failure value returned from cantFail wrapped call";
+#ifndef NDEBUG
+    std::string Str;
+    raw_string_ostream OS(Str);
+    OS << Msg << "\n" << Err;
+    Msg = OS.str().c_str();
+#endif
     llvm_unreachable(Msg);
   }
 }
@@ -728,6 +734,13 @@
   else {
     if (!Msg)
       Msg = "Failure value returned from cantFail wrapped call";
+#ifndef NDEBUG
+    std::string Str;
+    raw_string_ostream OS(Str);
+    auto E = ValOrErr.takeError();
+    OS << Msg << "\n" << E;
+    Msg = OS.str().c_str();
+#endif
     llvm_unreachable(Msg);
   }
 }
@@ -752,6 +765,13 @@
   else {
     if (!Msg)
       Msg = "Failure value returned from cantFail wrapped call";
+#ifndef NDEBUG
+    std::string Str;
+    raw_string_ostream OS(Str);
+    auto E = ValOrErr.takeError();
+    OS << Msg << "\n" << E;
+    Msg = OS.str().c_str();
+#endif
     llvm_unreachable(Msg);
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69057.225526.patch
Type: text/x-patch
Size: 2792 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191017/b3b41244/attachment.bin>


More information about the llvm-commits mailing list