Skip to content

[clang][bytecode] Fix IntegralAP::is{Positive,Negative} #105924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions clang/lib/AST/ByteCode/IntegralAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
9 changes: 9 additions & 0 deletions clang/test/AST/ByteCode/intap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading