Skip to content

Commit

Permalink
[clang][Interp] Fix IntAP(s) to IntAP(s) casts (#69915)
Browse files Browse the repository at this point in the history
This was still assert(false)'ed out, it's for casts between two IntAP/IntAPS expressions.
We can't just short-circuit for FromT == ToT because we need to consider the bitwidth when doing the cast.
  • Loading branch information
tbaederr committed Nov 6, 2023
1 parent bdac972 commit feedb7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 2 additions & 5 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,13 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
if (!this->visit(SubExpr))
return false;

if (FromT == ToT) {
assert(ToT != PT_IntAP && ToT != PT_IntAPS);
return true;
}

if (ToT == PT_IntAP)
return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE);
if (ToT == PT_IntAPS)
return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE);

if (FromT == ToT)
return true;
return this->emitCast(*FromT, *ToT, CE);
}

Expand Down
11 changes: 11 additions & 0 deletions clang/test/AST/Interp/intap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ static_assert(UBitIntZero1 == 0, "");
constexpr unsigned _BitInt(2) BI1 = 3u;
static_assert(BI1 == 3, "");

namespace APCast {
constexpr _BitInt(10) A = 1;
constexpr _BitInt(11) B = A;
static_assert(B == 1, "");
constexpr _BitInt(16) B2 = A;
static_assert(B2 == 1, "");
constexpr _BitInt(32) B3 = A;
static_assert(B3 == 1, "");
constexpr unsigned _BitInt(32) B4 = A;
static_assert(B4 == 1, "");
}

#ifdef __SIZEOF_INT128__
namespace i128 {
Expand Down

0 comments on commit feedb7c

Please sign in to comment.