https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/105924
This depends on signed-ness. >From c773015150b8a93a37cd6121091a2072b6df5710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Sat, 24 Aug 2024 07:16:54 +0200 Subject: [PATCH] [clang][bytecode] Fix IntegralAP::is{Positive,Negative} This depends on signed-ness. --- clang/lib/AST/ByteCode/IntegralAP.h | 12 ++++++++++-- clang/test/AST/ByteCode/intap.cpp | 9 +++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) 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