================
@@ -2879,6 +2877,23 @@ 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) {
+ S.FFDiag(S.Current->getLocation(OpPC),
+ diag::note_invalid_subexpr_in_const_expr)
+ << S.Current->getRange(OpPC);
+ return false;
----------------
tbaederr wrote:
```suggestion
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