Repository navigation
Explicit integer overflow: checked arithmetic, wrapping builtins, int to float coercion - #556
Merged
Merged
Conversation
…andom wraps onto them and drop Ryu's wrapping multiply
…t feeds a float, ArithmeticError otherwise (closes #48 as a documented difference)
This was referenced Nov 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Integer overflow is explicit:
+ - *,++/--, unary-andabs()over ints either compute the float php would (when the result feeds a float) or throwArithmeticError("Integer overflow"). Silent wrap is gone. Design:docs/design/numeric-vra.md(branchdesign/numeric-vra).: floatfunction, or stored into afloatproperty or static, is converted instead of keeping its raw bits as a double. Sibling gaps filed as An int returned from a ?float function, or stored in a ?float property, stays int instead of converting to float. #553 (?float) and Int arguments collected by afloat ...$xsvariadic stay int instead of converting to float. #554 (float ...$xs).Manticore\wrapping_add/sub/mul: public API for deliberate wraparound (hashes, PRNGs), PHP stdlib bodies plus an inline codegen builtin. The wraps inRandom.phpuse them; Ryu's wrapping multiply inJson.phpbecame a% 5/intdivloop, becauseJson.phpis also compiled into the compiler, which cannot use the builtin before the pin moves.docs/superset.md.llvm.{sadd,ssub,smul}.with.overflow.i64with a cold throw block. Float sinks (a: floatreturn, a float argument, a float slot,(float), float arithmetic,/, float property stores) compute in double. A documented difference from Zend:docs/differences.md, "Integer overflow throws".unserializeof 19+ digit numbers,UInt64Arraydecimal parse/format,$m - 1inRandom::range64, and theds_uint64test.Not covered
**on ints still wraps (__mir_ipow).$s = 1.5; $s = $a + $bis an int|float cell, not a float slot: it throws instead of promoting.PHP_INT_MIN % -1was checked on arm64 only (already 0); x86 needs the Linux amd64 gate.#47and#46follow later (analysis of where int and float are observable).Costs (arm64, 1e8 iterations, best of 3)
$c += $i & 7$h = (($h*31)+$i) & 0xFFFFFFFF$s += ($i*6) % 7bin/manticore+2.3%,lib/manticore_stdlib.o+2.6%. Planned follow-ups to win this back: constant-multiplier overflow test withoutsmulh, and a bit-width range lattice with masked loop phis. Not in this PR.Testing
Targeted
tests/aot/run.sh -kover ~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.