[clang][Interp] Fix BooleanToSignedIntegral casts for IntAP(S) (#102302)

We were not doing the final Neg here.
This commit is contained in:
Timm Baeder 2024-08-07 13:52:00 +02:00 committed by GitHub
parent 441f94f4bd
commit f05e8186a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 5 deletions

View File

@ -480,19 +480,25 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
}
}
auto maybeNegate = [&]() -> bool {
if (CE->getCastKind() == CK_BooleanToSignedIntegral)
return this->emitNeg(*ToT, CE);
return true;
};
if (ToT == PT_IntAP)
return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE);
return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE) &&
maybeNegate();
if (ToT == PT_IntAPS)
return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE);
return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE) &&
maybeNegate();
if (FromT == ToT)
return true;
if (!this->emitCast(*FromT, *ToT, CE))
return false;
if (CE->getCastKind() == CK_BooleanToSignedIntegral)
return this->emitNeg(*ToT, CE);
return true;
return maybeNegate();
}
case CK_PointerToBoolean:

View File

@ -90,3 +90,14 @@ namespace Temporaries {
};
int &&s = S().w[1];
}
#ifdef __SIZEOF_INT128__
namespace bigint {
typedef __attribute__((__ext_vector_type__(4))) __int128 bigint4;
constexpr bigint4 A = (bigint4)true;
static_assert(A[0] == -1, "");
static_assert(A[1] == -1, "");
static_assert(A[2] == -1, "");
static_assert(A[3] == -1, "");
}
#endif