diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 485893d58f487a..a2cf682b2532bd 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -200,16 +200,13 @@ bool ByteCodeExprGen::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); } diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp index db9f516131af47..45961e6fc74b7a 100644 --- a/clang/test/AST/Interp/intap.cpp +++ b/clang/test/AST/Interp/intap.cpp @@ -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 {