Skip to content

Commit

Permalink
[clang][Interp] Fix creating APSInt from IntegralAP (#71410)
Browse files Browse the repository at this point in the history
The boolean argument in the APSInt constructor is IsUnsigned, not
IsSigned.
  • Loading branch information
tbaederr committed Nov 8, 2023
1 parent 32a3f2a commit e6a94dc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clang/lib/AST/Interp/IntegralAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ template <bool Signed> class IntegralAP final {

constexpr unsigned bitWidth() const { return V.getBitWidth(); }

APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, Signed); }
APValue toAPValue() const { return APValue(APSInt(V, Signed)); }
APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, !Signed); }
APValue toAPValue() const { return APValue(APSInt(V, !Signed)); }

bool isZero() const { return V.isZero(); }
bool isPositive() const { return V.isNonNegative(); }
Expand Down
4 changes: 4 additions & 0 deletions clang/test/AST/Interp/intap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ namespace i128 {

static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L));
static_assert(UINT128_MAX == -1, "");
static_assert(UINT128_MAX == 1, ""); // expected-error {{static assertion failed}} \
// expected-note {{'340282366920938463463374607431768211455 == 1'}} \
// ref-error {{static assertion failed}} \
// ref-note {{'340282366920938463463374607431768211455 == 1'}}

static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
static_assert(INT128_MAX != 0, "");
Expand Down

0 comments on commit e6a94dc

Please sign in to comment.