[clang][bytecode] Reject float-to-int casts on non-numbers (#193968)

This commit is contained in:
Timm Baeder
2026-04-24 16:44:00 +02:00
committed by GitHub
parent 08992737d2
commit 25a035d944
2 changed files with 8 additions and 0 deletions

View File

@@ -2785,6 +2785,12 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
bool CastIntegralFloating(InterpState &S, CodePtr OpPC,
const llvm::fltSemantics *Sem, uint32_t FPOI) {
const T &From = S.Stk.pop<T>();
if constexpr (isIntegralOrPointer<T>()) {
if (!From.isNumber())
return false;
}
APSInt FromAP = From.toAPSInt();
FPOptions FPO = FPOptions::getFromOpaqueInt(FPOI);

View File

@@ -449,3 +449,5 @@ void strcpyDouble(void) {
int *iptr;
void ignoredConditional(void) { *iptr = (((_Complex double)1.0 ? 2 : 3), a); } // all-warning {{left operand of comma operator has no effect}}
float r = (float) (intptr_t) &r; // all-error {{initializer element is not a compile-time constant}}