From 3df768796aad080a71846c6614f81a35548b9381 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Thu, 30 Jun 2016 17:43:06 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274249 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/Error.h | 3 ++- unittests/Support/ErrorTest.cpp | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/llvm/Support/Error.h b/include/llvm/Support/Error.h index b817a230d0d..8206eed67d3 100644 --- a/include/llvm/Support/Error.h +++ b/include/llvm/Support/Error.h @@ -345,7 +345,8 @@ private: if (E1.isA()) { auto &E1List = static_cast(*E1.getPtr()); if (E2.isA()) { - auto &E2List = static_cast(*E2.getPtr()); + auto E2Payload = E2.takePayload(); + auto &E2List = static_cast(*E2Payload); for (auto &Payload : E2List.Payloads) E1List.Payloads.push_back(std::move(Payload)); } else diff --git a/unittests/Support/ErrorTest.cpp b/unittests/Support/ErrorTest.cpp index d5d799384f4..20509268374 100644 --- a/unittests/Support/ErrorTest.cpp +++ b/unittests/Support/ErrorTest.cpp @@ -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(7), + make_error(7)), + make_error(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(7), + joinErrors(make_error(7), + make_error(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(7), + make_error(7)), + joinErrors( + make_error(7), + make_error(7))), + [&](const CustomError &CE) { + Sum += CE.getInfo(); + }); + EXPECT_EQ(Sum, 28) << "Failed to correctly concatenate erorr lists."; + } } // Test that we can consume success values.