Skip to content

AOT: integer overflow promotes to float on + and * (#31964) - #31980

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-31964-aot-int-overflow
Aug 17, 2026
Merged

AOT: integer overflow promotes to float on + and * (#31964)#31980
PurHur merged 1 commit into
masterfrom
agent/issue-31964-aot-int-overflow

Conversation

@PurHur

@PurHur PurHur commented Aug 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add lib/JIT/JitLongArithOverflow.php implementing Zend ZEND_SIGNED_ADD_OVERFLOW / ZEND_LONG_MUL_OVERFLOW for JIT/AOT long arithmetic.
  • Wire overflow promotion into native-long pairs in Helper.php and boxed numeric paths in JitValueNumeric.php.
  • Repro + compliance .phpt and targeted JIT/AOT PHPUnit guards.

Closes #31964

php-src reference

  • Zend/zend_operators.hZEND_SIGNED_ADD_OVERFLOW, ZEND_LONG_MUL_OVERFLOW
  • Zend/zend_operators.cadd_function / mul_function

Verification

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_aot_int_overflow.php'
# float(9.223372036854776E+18)
# float(1.8446744073709552E+19)

./script/docker-exec.sh -- bash -lc 'php bin/compile.php -o /tmp/int_overflow test/repro/maintainer_gap_aot_int_overflow.php && /tmp/int_overflow'
# float(9.2233720368548e+18)  — same value, AOT var_dump formatting differs slightly
# float(1.844674407371e+19)

./script/phpunit.sh --filter IntArithOverflowPromote31964JITTest
# OK (1 test)

./script/phpunit.sh --filter IntArithOverflowPromote31964AotTest
# OK (1 test)

Not covered

Made with Cursor

Zend promotes out-of-range long arithmetic to double; LLVM nsw add/mul
was wrapping silently. Add JitLongArithOverflow shared by native-long and
boxed numeric paths, with compile-time fold and compliance guards.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AOT: integer overflow wraps instead of promoting to float — silent wrong arithmetic

1 participant