================
@@ -19389,7 +19284,19 @@ bool IntExprEvaluator::VisitOffsetOfExpr(const
OffsetOfExpr *OOE) {
return Error(OOE);
CurrentType = AT->getElementType();
CharUnits ElementSize = Info.Ctx.getTypeSizeInChars(CurrentType);
- Result += IdxResult.getSExtValue() * ElementSize;
+ // Reject negative indices, indices too large to fit in int64_t,
+ // and overflow in the offset computation.
+ if (IdxResult.isNegative() || IdxResult.getActiveBits() > 63)
+ return Error(OOE);
----------------
marlus wrote:
Done. Added note_constexpr_offsetof_overflow ("overflow in offsetof") to
DiagnosticASTKinds.td and use it in both the ExprConstant.cpp and
InterpBuiltin.cpp paths when the multiply or add step of the offset computation
overflows int64_t. The test has been updated to expect the new note.
https://github.com/llvm/llvm-project/pull/204139
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits