[llvm] r274249 - [Support] Fix a bug in ErrorList::join / joinErrors.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 30 10:43:06 PDT 2016
Author: lhames
Date: Thu Jun 30 12:43:06 2016
New Revision: 274249
URL: http://llvm.org/viewvc/llvm-project?rev=274249&view=rev
Log:
[Support] Fix a bug in ErrorList::join / joinErrors.
When concatenating two error lists the ErrorList::join method (which is called
by joinErrors) was failing to set the checked bit on the second error, leading
to a 'failure to check error' assertion.
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=274249&r1=274248&r2=274249&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Error.h (original)
+++ llvm/trunk/include/llvm/Support/Error.h Thu Jun 30 12:43:06 2016
@@ -345,7 +345,8 @@ private:
if (E1.isA<ErrorList>()) {
auto &E1List = static_cast<ErrorList &>(*E1.getPtr());
if (E2.isA<ErrorList>()) {
- auto &E2List = static_cast<ErrorList &>(*E2.getPtr());
+ auto E2Payload = E2.takePayload();
+ auto &E2List = static_cast<ErrorList &>(*E2Payload);
for (auto &Payload : E2List.Payloads)
E1List.Payloads.push_back(std::move(Payload));
} else
Modified: llvm/trunk/unittests/Support/ErrorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ErrorTest.cpp?rev=274249&r1=274248&r2=274249&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/ErrorTest.cpp (original)
+++ llvm/trunk/unittests/Support/ErrorTest.cpp Thu Jun 30 12:43:06 2016
@@ -314,6 +314,51 @@ TEST(Error, CheckJoinErrors) {
EXPECT_TRUE(CustomErrorInfo1 == 7 && CustomErrorInfo2 == 42 &&
CustomErrorExtraInfo == 7)
<< "Failed handling compound Error.";
+
+ // Test appending a single item to a list.
+ {
+ int Sum = 0;
+ handleAllErrors(
+ joinErrors(
+ joinErrors(make_error<CustomError>(7),
+ make_error<CustomError>(7)),
+ make_error<CustomError>(7)),
+ [&](const CustomError &CE) {
+ Sum += CE.getInfo();
+ });
+ EXPECT_EQ(Sum, 21) << "Failed to correctly append error to error list.";
+ }
+
+ // Test prepending a single item to a list.
+ {
+ int Sum = 0;
+ handleAllErrors(
+ joinErrors(
+ make_error<CustomError>(7),
+ joinErrors(make_error<CustomError>(7),
+ make_error<CustomError>(7))),
+ [&](const CustomError &CE) {
+ Sum += CE.getInfo();
+ });
+ EXPECT_EQ(Sum, 21) << "Failed to correctly prepend error to error list.";
+ }
+
+ // Test concatenating two error lists.
+ {
+ int Sum = 0;
+ handleAllErrors(
+ joinErrors(
+ joinErrors(
+ make_error<CustomError>(7),
+ make_error<CustomError>(7)),
+ joinErrors(
+ make_error<CustomError>(7),
+ make_error<CustomError>(7))),
+ [&](const CustomError &CE) {
+ Sum += CE.getInfo();
+ });
+ EXPECT_EQ(Sum, 28) << "Failed to correctly concatenate erorr lists.";
+ }
}
// Test that we can consume success values.
More information about the llvm-commits
mailing list