From c3402f3fd55c7c69f93e53e76e063f0f6eab27aa Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Mon, 28 Nov 2016 22:57:11 +0000 Subject: [PATCH] Put ABI breaking test in Error checking behind LLVM_ENABLE_ABI_BREAKING_CHECKS This macro is supposed to be the one controlling the compatibility of ABI breaks induced when enabling or disabling assertions in LLVM. The macro is enabled by default in assertions build, so this commit won't disable the tests. Differential Revision: https://reviews.llvm.org/D26700 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288087 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/Error.h | 39 +++++++++++++++--------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/include/llvm/Support/Error.h b/include/llvm/Support/Error.h index 01ee0354337..22588c299d0 100644 --- a/include/llvm/Support/Error.h +++ b/include/llvm/Support/Error.h @@ -224,7 +224,7 @@ public: private: void assertIsChecked() { -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS if (!getChecked() || getPtr()) { dbgs() << "Program aborted due to an unhandled Error:\n"; if (getPtr()) @@ -245,7 +245,7 @@ private: } void setPtr(ErrorInfoBase *EI) { -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS Payload = reinterpret_cast( (reinterpret_cast(EI) & ~static_cast(0x1)) | @@ -256,7 +256,7 @@ private: } bool getChecked() const { -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS return (reinterpret_cast(Payload) & 0x1) == 0; #else return true; @@ -637,17 +637,11 @@ private: public: /// Create an Expected error value from the given Error. Expected(Error Err) - : HasError(true), -#ifndef NDEBUG + : HasError(true) +#if LLVM_ENABLE_ABI_BREAKING_CHECKS // Expected is unchecked upon construction in Debug builds. - Unchecked(true) -#else - // Expected's unchecked flag is set to false in Release builds. This - // allows Expected values constructed in a Release build library to be - // consumed by a Debug build application. - Unchecked(false) + , Unchecked(true) #endif - { assert(Err && "Cannot create Expected from Error success value."); new (getErrorStorage()) error_type(Err.takePayload()); @@ -664,15 +658,10 @@ public: Expected(OtherT &&Val, typename std::enable_if::value>::type * = nullptr) - : HasError(false), -#ifndef NDEBUG + : HasError(false) +#if LLVM_ENABLE_ABI_BREAKING_CHECKS // Expected is unchecked upon construction in Debug builds. - Unchecked(true) -#else - // Expected's 'unchecked' flag is set to false in Release builds. This - // allows Expected values constructed in a Release build library to be - // consumed by a Debug build application. - Unchecked(false) + , Unchecked(true) #endif { new (getStorage()) storage_type(std::forward(Val)); @@ -717,7 +706,7 @@ public: /// \brief Return false if there is an error. explicit operator bool() { -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS Unchecked = HasError; #endif return !HasError; @@ -745,7 +734,7 @@ public: /// only be safely destructed. No further calls (beside the destructor) should /// be made on the Expected vaule. Error takeError() { -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS Unchecked = false; #endif return HasError ? Error(std::move(*getErrorStorage())) : Error::success(); @@ -788,8 +777,10 @@ private: template void moveConstruct(Expected &&Other) { HasError = Other.HasError; +#if LLVM_ENABLE_ABI_BREAKING_CHECKS Unchecked = true; Other.Unchecked = false; +#endif if (!HasError) new (getStorage()) storage_type(std::move(*Other.getStorage())); @@ -831,7 +822,7 @@ private: } void assertIsChecked() { -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS if (Unchecked) { dbgs() << "Expected must be checked before access or destruction.\n"; if (HasError) { @@ -851,7 +842,9 @@ private: AlignedCharArrayUnion ErrorStorage; }; bool HasError : 1; +#if LLVM_ENABLE_ABI_BREAKING_CHECKS bool Unchecked : 1; +#endif }; /// This class wraps a std::error_code in a Error. -- 2.50.1