Author: Timm Baeder Date: 2024-08-24T07:50:23+02:00 New Revision: c81d6665601d648c1a5349b665ee6019f3786352
URL: https://github.com/llvm/llvm-project/commit/c81d6665601d648c1a5349b665ee6019f3786352 DIFF: https://github.com/llvm/llvm-project/commit/c81d6665601d648c1a5349b665ee6019f3786352.diff LOG: [clang][bytecode] Fix IntegralAP::is{Positive,Negative} (#105924) This depends on signed-ness. Added: Modified: clang/lib/AST/ByteCode/IntegralAP.h clang/test/AST/ByteCode/intap.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/IntegralAP.h b/clang/lib/AST/ByteCode/IntegralAP.h index b8aa21038256c7..209b0af7da5f30 100644 --- a/clang/lib/AST/ByteCode/IntegralAP.h +++ b/clang/lib/AST/ByteCode/IntegralAP.h @@ -136,8 +136,16 @@ template <bool Signed> class IntegralAP final { APValue toAPValue(const ASTContext &) const { return APValue(toAPSInt()); } bool isZero() const { return V.isZero(); } - bool isPositive() const { return V.isNonNegative(); } - bool isNegative() const { return !V.isNonNegative(); } + bool isPositive() const { + if constexpr (Signed) + return V.isNonNegative(); + return true; + } + bool isNegative() const { + if constexpr (Signed) + return !V.isNonNegative(); + return false; + } bool isMin() const { return V.isMinValue(); } bool isMax() const { return V.isMaxValue(); } static constexpr bool isSigned() { return Signed; } diff --git a/clang/test/AST/ByteCode/intap.cpp b/clang/test/AST/ByteCode/intap.cpp index d4440124856915..d0ad641fe508cb 100644 --- a/clang/test/AST/ByteCode/intap.cpp +++ b/clang/test/AST/ByteCode/intap.cpp @@ -104,6 +104,15 @@ static_assert(INT128_MAX == 0, ""); // expected-error {{failed}} \ // ref-note {{evaluates to '170141183460469231731687303715884105727 == 0'}} static const __int128_t INT128_MIN = -INT128_MAX - 1; + +namespace PointerArithmeticOverflow { + int n; + constexpr int *p = (&n + 1) + (unsigned __int128)-1; // expected-error {{constant expression}} \ + // expected-note {{cannot refer to element 3402}} \ + // ref-error {{constant expression}} \ + // ref-note {{cannot refer to element 3402}} +} + namespace i128 { constexpr int128_t I128_1 = 12; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits