Skip to content

Fix GH-20838: JIT compiler produces wrong arithmetic results#21383

Open
iliaal wants to merge 1 commit intophp:masterfrom
iliaal:fix/gh-20838-jit-wrong-arithmetic
Open

Fix GH-20838: JIT compiler produces wrong arithmetic results#21383
iliaal wants to merge 1 commit intophp:masterfrom
iliaal:fix/gh-20838-jit-wrong-arithmetic

Conversation

@iliaal
Copy link
Contributor

@iliaal iliaal commented Mar 8, 2026

Summary

  • When an opcode falls through to the handler path in JIT trace compilation and an operand has MAY_BE_GUARD, the guard is widened to MAY_BE_ANY but never emitted as a runtime type check
  • The handler can produce a result type different from the TSSA prediction (e.g. IS_LONG instead of IS_DOUBLE for MUL with mixed string/numeric operands), but SET_STACK_TYPE unconditionally records the predicted concrete type as mem_type
  • Side traces entering via the exit point then load the slot from memory assuming the predicted type, interpreting raw IS_LONG bytes as IEEE 754 double (producing values like 3.7054923438093E-322 instead of 75)
  • Fix: don't trust the TSSA concrete result type when the handler path is taken and any operand had MAY_BE_GUARD

Fixes #20838

When an opcode falls through to the handler path and an operand has
MAY_BE_GUARD, the guard is widened to MAY_BE_ANY but not emitted.
The handler can then produce a result type different from the TSSA
prediction (e.g. IS_LONG instead of IS_DOUBLE for MUL with mixed
types), but SET_STACK_TYPE unconditionally records the predicted
type as mem_type. Side traces reading this slot from memory then
interpret the raw bytes as the wrong type.

Don't trust the TSSA concrete result type when the handler path is
taken and any operand had MAY_BE_GUARD.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT compiler in 1255 mode produces wrong result of arithmetical operations

1 participant