Skip to content

Commit e6a94dc

Browse files
authored
[clang][Interp] Fix creating APSInt from IntegralAP (#71410)
The boolean argument in the APSInt constructor is IsUnsigned, not IsSigned.
1 parent 32a3f2a commit e6a94dc

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

clang/lib/AST/Interp/IntegralAP.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ template <bool Signed> class IntegralAP final {
119119

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

122-
APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, Signed); }
123-
APValue toAPValue() const { return APValue(APSInt(V, Signed)); }
122+
APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, !Signed); }
123+
APValue toAPValue() const { return APValue(APSInt(V, !Signed)); }
124124

125125
bool isZero() const { return V.isZero(); }
126126
bool isPositive() const { return V.isNonNegative(); }

clang/test/AST/Interp/intap.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ namespace i128 {
5656

5757
static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L));
5858
static_assert(UINT128_MAX == -1, "");
59+
static_assert(UINT128_MAX == 1, ""); // expected-error {{static assertion failed}} \
60+
// expected-note {{'340282366920938463463374607431768211455 == 1'}} \
61+
// ref-error {{static assertion failed}} \
62+
// ref-note {{'340282366920938463463374607431768211455 == 1'}}
5963

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

0 commit comments

Comments
 (0)