================
@@ -2879,6 +2877,20 @@ bool CastAPS(InterpState &S, CodePtr OpPC, uint32_t
BitWidth) {
return true;
}
+// Cast an AP integer to Sint64, failing constant evaluation if the value is
+// negative or too large to fit (i.e. truncation would change the value).
+template <PrimType Name, class T = typename PrimConv<Name>::T>
+bool CastNoOverflow(InterpState &S, CodePtr OpPC) {
+ T Source = S.Stk.pop<T>();
+ APSInt Val = Source.toAPSInt();
+ if (Val.isNegative() || Val.getActiveBits() > 63) {
+ return Invalid(S, OpPC);
+ }
----------------
tbaederr wrote:
```suggestion
if (Val.isNegative() || Val.getActiveBits() > 63)
return Invalid(S, OpPC);
```
https://github.com/llvm/llvm-project/pull/204139
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits