Skip to content

Explicit integer overflow: checked arithmetic, wrapping builtins, int to float coercion - #556

Merged
blacktrs merged 5 commits into
mainfrom
fix/int-overflow
Nov 2, 2026
Merged

blacktrs merged 5 commits into
mainfrom
fix/int-overflow

Conversation

@blacktrs

@blacktrs blacktrs commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Integer overflow is explicit: + - *, ++/--, unary - and abs() over ints either compute the float php would (when the result feeds a float) or throw ArithmeticError("Integer overflow"). Silent wrap is gone. Design: docs/design/numeric-vra.md (branch design/numeric-vra).

Not covered

  • ** on ints still wraps (__mir_ipow).
  • A local $s = 1.5; $s = $a + $b is an int|float cell, not a float slot: it throws instead of promoting.
  • PHP_INT_MIN % -1 was checked on arm64 only (already 0); x86 needs the Linux amd64 gate.
  • #47 and #46 follow later (analysis of where int and float are observable).

Costs (arm64, 1e8 iterations, best of 3)

kernel before after
$c += $i & 7 14 ms 33 ms (LLVM no longer folds the loop)
$h = (($h*31)+$i) & 0xFFFFFFFF 99 ms 133 ms
$s += ($i*6) % 7 61 ms 88 ms
foreach sum over ints 450 ms 452 ms

bin/manticore +2.3%, lib/manticore_stdlib.o +2.6%. Planned follow-ups to win this back: constant-multiplier overflow test without smulh, and a bit-width range lattice with masked loop phis. Not in this PR.

Testing

Targeted tests/aot/run.sh -k over ~70 filters (int, big, ds_, rand, json, serialize, hash, sort, date, ffi, closure, generator, spl, float, str_, array_ ...), self-host twice with the checked compiler. New cases: int_to_float_coercion_sites, wrapping_builtins, int_overflow_checked.
Not run: full AOT suite, difftest, fixpoint, Linux gate. Code that wraps deliberately in examples/, the symfony/laravel corpora and cs-fixer now throws and has not been swept.

Fixes #48, fixes #552.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant