Skip to content
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
9 changes: 6 additions & 3 deletions clang/lib/AST/ByteCode/Integral.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,14 @@ template <unsigned Bits, bool Signed> class Integral final {
APSInt toAPSInt() const {
return APSInt(APInt(Bits, static_cast<uint64_t>(V), Signed), !Signed);
}
APSInt toAPSInt(unsigned NumBits) const {
APSInt toAPSInt(unsigned BitWidth) const { return APSInt(toAPInt(BitWidth)); }
APInt toAPInt(unsigned BitWidth) const {
if constexpr (Signed)
return APSInt(toAPSInt().sextOrTrunc(NumBits), !Signed);
return APInt(Bits, static_cast<uint64_t>(V), Signed)
.sextOrTrunc(BitWidth);
else
return APSInt(toAPSInt().zextOrTrunc(NumBits), !Signed);
return APInt(Bits, static_cast<uint64_t>(V), Signed)
.zextOrTrunc(BitWidth);
}
APValue toAPValue(const ASTContext &) const { return APValue(toAPSInt()); }

Expand Down
7 changes: 1 addition & 6 deletions clang/lib/AST/ByteCode/IntegralAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,7 @@ template <bool Signed> class IntegralAP final {

template <unsigned Bits, bool InputSigned>
static IntegralAP from(Integral<Bits, InputSigned> I, unsigned BitWidth) {
// TODO: Avoid implicit trunc?
// See https://github.com/llvm/llvm-project/issues/112510.
APInt Copy = APInt(BitWidth, static_cast<uint64_t>(I), InputSigned,
/*implicitTrunc=*/true);

return IntegralAP<Signed>(Copy);
return IntegralAP<Signed>(I.toAPInt(BitWidth));
}

static IntegralAP zero(int32_t BitWidth) {
Expand Down
Loading