[clang] [clang][bytecode] Fix IntegralAP::{isMin,isMax} (PR #145339)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 23 08:11:48 PDT 2025
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/145339
We need to take signeness into account here.
>From fade41f6df27da0c20751276aa8586bb1540bbf7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 23 Jun 2025 17:10:20 +0200
Subject: [PATCH] [clang][bytecode] Fix IntegralAP::{isMin,isMax}
We need to take signeness into account here.
---
clang/lib/AST/ByteCode/IntegralAP.h | 12 ++++++++++--
clang/test/AST/ByteCode/intap.cpp | 7 +++++++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/clang/lib/AST/ByteCode/IntegralAP.h b/clang/lib/AST/ByteCode/IntegralAP.h
index e7499fc9bf5a9..6683db941c736 100644
--- a/clang/lib/AST/ByteCode/IntegralAP.h
+++ b/clang/lib/AST/ByteCode/IntegralAP.h
@@ -163,8 +163,16 @@ template <bool Signed> class IntegralAP final {
return !getValue().isNonNegative();
return false;
}
- bool isMin() const { return getValue().isMinValue(); }
- bool isMax() const { return getValue().isMaxValue(); }
+ bool isMin() const {
+ if constexpr (Signed)
+ return getValue().isMinSignedValue();
+ return getValue().isMinValue();
+ }
+ bool isMax() const {
+ if constexpr (Signed)
+ return getValue().isMaxSignedValue();
+ return getValue().isMaxValue();
+ }
static constexpr bool isSigned() { return Signed; }
bool isMinusOne() const { return Signed && getValue().isAllOnes(); }
diff --git a/clang/test/AST/ByteCode/intap.cpp b/clang/test/AST/ByteCode/intap.cpp
index 11dd9edb61a94..a7e43b34a7d2b 100644
--- a/clang/test/AST/ByteCode/intap.cpp
+++ b/clang/test/AST/ByteCode/intap.cpp
@@ -48,6 +48,13 @@ static_assert(DivA / DivB == 2, "");
constexpr _BitInt(4) DivC = DivA / 0; // both-error {{must be initialized by a constant expression}} \
// both-note {{division by zero}}
+constexpr __int128 isMinDiv() {
+ return __int128{0} / __int128{-1};
+}
+static_assert(isMinDiv() == 0, "");
+
+
+
constexpr _BitInt(7) RemA = 47;
constexpr _BitInt(6) RemB = 9;
static_assert(RemA % RemB == 2, "");
More information about the cfe-commits
mailing list