[clang] 836ff36 - [clang][bytecode] Fix IntegralAP::{isMin, isMax} (#145339)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 23 10:11:20 PDT 2025
Author: Timm Baeder
Date: 2025-06-23T19:11:17+02:00
New Revision: 836ff367d0bca9369fd2db237e9b5d7b929bb593
URL: https://github.com/llvm/llvm-project/commit/836ff367d0bca9369fd2db237e9b5d7b929bb593
DIFF: https://github.com/llvm/llvm-project/commit/836ff367d0bca9369fd2db237e9b5d7b929bb593.diff
LOG: [clang][bytecode] Fix IntegralAP::{isMin,isMax} (#145339)
We need to take signeness into account here.
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 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