diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 07eca27bee14..80662cc8a718 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -2785,6 +2785,12 @@ template ::T> bool CastIntegralFloating(InterpState &S, CodePtr OpPC, const llvm::fltSemantics *Sem, uint32_t FPOI) { const T &From = S.Stk.pop(); + + if constexpr (isIntegralOrPointer()) { + if (!From.isNumber()) + return false; + } + APSInt FromAP = From.toAPSInt(); FPOptions FPO = FPOptions::getFromOpaqueInt(FPOI); diff --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c index 78820d04ba3f..31368d0d9d62 100644 --- a/clang/test/AST/ByteCode/c.c +++ b/clang/test/AST/ByteCode/c.c @@ -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}}