Index: include/llvm/Support/Error.h =================================================================== --- include/llvm/Support/Error.h +++ include/llvm/Support/Error.h @@ -14,6 +14,7 @@ #ifndef LLVM_SUPPORT_ERROR_H #define LLVM_SUPPORT_ERROR_H +#include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" @@ -264,35 +265,31 @@ } ErrorInfoBase *getPtr() const { - return reinterpret_cast( - reinterpret_cast(Payload) & - ~static_cast(0x1)); + return Payload.getPointer(); } void setPtr(ErrorInfoBase *EI) { #if LLVM_ENABLE_ABI_BREAKING_CHECKS - Payload = reinterpret_cast( - (reinterpret_cast(EI) & - ~static_cast(0x1)) | - (reinterpret_cast(Payload) & 0x1)); + Payload.setPointer(EI); #else - Payload = EI; + // This #else isn't strictly necessary, but should be more optimizable. + Payload.setPointerAndInt(EI, false); #endif } bool getChecked() const { #if LLVM_ENABLE_ABI_BREAKING_CHECKS - return (reinterpret_cast(Payload) & 0x1) == 0; + return !Payload.getInt(); #else + // This #else isn't strictly necessary, but should be more optimizable. return true; #endif } void setChecked(bool V) { - Payload = reinterpret_cast( - (reinterpret_cast(Payload) & - ~static_cast(0x1)) | - (V ? 0 : 1)); +#if LLVM_ENABLE_ABI_BREAKING_CHECKS + Payload.setInt(!V); +#endif } std::unique_ptr takePayload() { @@ -302,7 +299,7 @@ return Tmp; } - ErrorInfoBase *Payload = nullptr; + PointerIntPair Payload; }; /// Subclass of Error for the sole purpose of identifying the success path in Index: unittests/Support/ErrorTest.cpp =================================================================== --- unittests/Support/ErrorTest.cpp +++ unittests/Support/ErrorTest.cpp @@ -379,7 +379,7 @@ // Test that handleAllUnhandledErrors crashes if an error is not caught. // Test runs in debug mode only. -#if LLVM_ENABLE_ABI_BREAKING_CHECKS +#if LLVM_ENABLE_ABI_BREAKING_CHECKS && !NDEBUG TEST(Error, FailureToHandle) { auto FailToHandle = []() { handleAllErrors(make_error(7), [&](const CustomSubError &SE) { @@ -398,7 +398,7 @@ // Test that handleAllUnhandledErrors crashes if an error is returned from a // handler. // Test runs in debug mode only. -#if LLVM_ENABLE_ABI_BREAKING_CHECKS +#if LLVM_ENABLE_ABI_BREAKING_CHECKS && !NDEBUG TEST(Error, FailureFromHandler) { auto ReturnErrorFromHandler = []() { handleAllErrors(make_error(7),