Skip to content

Commit 836ff36

Browse files
authored
[clang][bytecode] Fix IntegralAP::{isMin,isMax} (#145339)
We need to take signeness into account here.
1 parent c445ca5 commit 836ff36

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

clang/lib/AST/ByteCode/IntegralAP.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,16 @@ template <bool Signed> class IntegralAP final {
163163
return !getValue().isNonNegative();
164164
return false;
165165
}
166-
bool isMin() const { return getValue().isMinValue(); }
167-
bool isMax() const { return getValue().isMaxValue(); }
166+
bool isMin() const {
167+
if constexpr (Signed)
168+
return getValue().isMinSignedValue();
169+
return getValue().isMinValue();
170+
}
171+
bool isMax() const {
172+
if constexpr (Signed)
173+
return getValue().isMaxSignedValue();
174+
return getValue().isMaxValue();
175+
}
168176
static constexpr bool isSigned() { return Signed; }
169177
bool isMinusOne() const { return Signed && getValue().isAllOnes(); }
170178

clang/test/AST/ByteCode/intap.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ static_assert(DivA / DivB == 2, "");
4848
constexpr _BitInt(4) DivC = DivA / 0; // both-error {{must be initialized by a constant expression}} \
4949
// both-note {{division by zero}}
5050

51+
constexpr __int128 isMinDiv() {
52+
return __int128{0} / __int128{-1};
53+
}
54+
static_assert(isMinDiv() == 0, "");
55+
56+
57+
5158
constexpr _BitInt(7) RemA = 47;
5259
constexpr _BitInt(6) RemB = 9;
5360
static_assert(RemA % RemB == 2, "");

0 commit comments

Comments
 (0)