[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:22 PDT 2026


================
@@ -6670,15 +6541,33 @@ bool InterpretOffsetOf(InterpState &S, CodePtr OpPC, const OffsetOfExpr *E,
       break;
     }
     case OffsetOfNode::Array: {
-      // When generating bytecode, we put all the index expressions as Sint64 on
-      // the stack.
       int64_t Index = ArrayIndices[ArrayIndex];
+      if (Index < 0) {
+        S.FFDiag(S.Current->getLocation(OpPC),
+                 diag::note_invalid_subexpr_in_const_expr)
+            << S.Current->getRange(OpPC);
+        return false;
+      }
----------------
tbaederr wrote:

```suggestion
      if (Index < 0)
        return Invalid(S, OpPC);
```

https://github.com/llvm/llvm-project/pull/204139


More information about the cfe-commits mailing list