Skip to content

Commit c81d666

Browse files
authored
[clang][bytecode] Fix IntegralAP::is{Positive,Negative} (llvm#105924)
This depends on signed-ness.
1 parent 75ef955 commit c81d666

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

clang/lib/AST/ByteCode/IntegralAP.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,16 @@ template <bool Signed> class IntegralAP final {
136136
APValue toAPValue(const ASTContext &) const { return APValue(toAPSInt()); }
137137

138138
bool isZero() const { return V.isZero(); }
139-
bool isPositive() const { return V.isNonNegative(); }
140-
bool isNegative() const { return !V.isNonNegative(); }
139+
bool isPositive() const {
140+
if constexpr (Signed)
141+
return V.isNonNegative();
142+
return true;
143+
}
144+
bool isNegative() const {
145+
if constexpr (Signed)
146+
return !V.isNonNegative();
147+
return false;
148+
}
141149
bool isMin() const { return V.isMinValue(); }
142150
bool isMax() const { return V.isMaxValue(); }
143151
static constexpr bool isSigned() { return Signed; }

clang/test/AST/ByteCode/intap.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ static_assert(INT128_MAX == 0, ""); // expected-error {{failed}} \
104104
// ref-note {{evaluates to '170141183460469231731687303715884105727 == 0'}}
105105
static const __int128_t INT128_MIN = -INT128_MAX - 1;
106106

107+
108+
namespace PointerArithmeticOverflow {
109+
int n;
110+
constexpr int *p = (&n + 1) + (unsigned __int128)-1; // expected-error {{constant expression}} \
111+
// expected-note {{cannot refer to element 3402}} \
112+
// ref-error {{constant expression}} \
113+
// ref-note {{cannot refer to element 3402}}
114+
}
115+
107116
namespace i128 {
108117

109118
constexpr int128_t I128_1 = 12;

0 commit comments

Comments
 (0)