[clang] [Clang] Fix offsetof sign-extending unsigned array indices >= 128 (PR #204139)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 25 22:50:21 PDT 2026
================
@@ -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
More information about the cfe-commits
mailing list