From 81c5b5d80efab9de616d6f8e42cd007f9c16e36b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timm=20B=C3=A4der?= Date: Tue, 27 Sep 2022 17:10:20 +0200 Subject: [PATCH] [clang][Interp][NFC] Simplify Integral using constexpr if Just keep one version of the function and differentiate between std::is_signed() and unsigned using a constexpr if, instead of having two different versions for the signed and unsigned cases. --- clang/lib/AST/Interp/Integral.h | 71 ++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 44 deletions(-) diff --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h index 50c9d7b..b5d20fb 100644 --- a/clang/lib/AST/Interp/Integral.h +++ b/clang/lib/AST/Interp/Integral.h @@ -213,55 +213,38 @@ public: } private: - template - static std::enable_if_t::value, bool> CheckAddUB(T A, T B, - T &R) { - return llvm::AddOverflow(A, B, R); + template static bool CheckAddUB(T A, T B, T &R) { + if constexpr (std::is_signed_v) { + return llvm::AddOverflow(A, B, R); + } else { + R = A + B; + return false; + } } - template - static std::enable_if_t::value, bool> CheckAddUB(T A, T B, - T &R) { - R = A + B; - return false; - } - - template - static std::enable_if_t::value, bool> CheckSubUB(T A, T B, - T &R) { - return llvm::SubOverflow(A, B, R); - } - - template - static std::enable_if_t::value, bool> CheckSubUB(T A, T B, - T &R) { - R = A - B; - return false; + template static bool CheckSubUB(T A, T B, T &R) { + if constexpr (std::is_signed_v) { + return llvm::SubOverflow(A, B, R); + } else { + R = A - B; + return false; + } } - template - static std::enable_if_t::value, bool> CheckMulUB(T A, T B, - T &R) { - return llvm::MulOverflow(A, B, R); + template static bool CheckMulUB(T A, T B, T &R) { + if constexpr (std::is_signed_v) { + return llvm::MulOverflow(A, B, R); + } else { + R = A * B; + return false; + } } - - template - static std::enable_if_t::value, bool> CheckMulUB(T A, T B, - T &R) { - R = A * B; - return false; - } - - template - static std::enable_if_t::value, bool> - CheckRange(int64_t V) { - return Min <= V && V <= Max; - } - - template - static std::enable_if_t::value, bool> - CheckRange(int64_t V) { - return V >= 0 && static_cast(V) <= Max; + template static bool CheckRange(int64_t V) { + if constexpr (std::is_signed_v) { + return Min <= V && V <= Max; + } else { + return V >= 0 && static_cast(V) <= Max; + } } }; -- 2.7.4