[llvm] r375176 - [Error] Make llvm::cantFail include the original error messages
Don Hinton via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 17 14:54:15 PDT 2019
Author: dhinton
Date: Thu Oct 17 14:54:15 2019
New Revision: 375176
URL: http://llvm.org/viewvc/llvm-project?rev=375176&view=rev
Log:
[Error] Make llvm::cantFail include the original error messages
Summary:
The current implementation eats the current errors and just outputs
the message parameter passed to llvm::cantFail. This change appends
the original error message(s), so the user can see exactly why
cantFail failed. New logic is conditional on NDEBUG.
Reviewed By: lhames
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69057
Modified:
llvm/trunk/include/llvm/Support/Error.h
llvm/trunk/unittests/Support/ErrorTest.cpp
Modified: llvm/trunk/include/llvm/Support/Error.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Error.h?rev=375176&r1=375175&r2=375176&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Error.h (original)
+++ llvm/trunk/include/llvm/Support/Error.h Thu Oct 17 14:54:15 2019
@@ -704,6 +704,12 @@ inline void cantFail(Error Err, const ch
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 @@ T cantFail(Expected<T> ValOrErr, const c
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 @@ T& cantFail(Expected<T&> ValOrErr, const
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);
}
}
Modified: llvm/trunk/unittests/Support/ErrorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ErrorTest.cpp?rev=375176&r1=375175&r2=375176&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/ErrorTest.cpp (original)
+++ llvm/trunk/unittests/Support/ErrorTest.cpp Thu Oct 17 14:54:15 2019
@@ -390,7 +390,8 @@ TEST(Error, FailureToHandle) {
};
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 @@ TEST(Error, FailureFromHandler) {
};
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(Error, CantFailSuccess) {
// 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(
{
More information about the llvm-commits
mailing list