Skip to content

Fix strlen() value-box AOT lowering — dangling blocks silently terminated binaries (#15632) - #15640

Merged
PurHur merged 1 commit into
masterfrom
fix/15632-strlen-aot-valuebox
Jul 3, 2026
Merged

PurHur merged 1 commit into
masterfrom
fix/15632-strlen-aot-valuebox

Conversation

@PurHur

@PurHur PurHur commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Fixes #15632. First layer of #15624.

Root cause

df16f37d4 (#11263) added the non-strict null-coercion branch to JitStrlen::lowerLengthFromValueBox() with an early return while the builder was positioned in the null block. okBlock (the real-string path) was never populated — a dangling basic block with no terminator — so every AOT binary fell through undefined behavior at its first non-constant-folded strlen() and exited 0 silently. The same early-return pattern also orphaned coerceBlock via the object branch. MCJIT (bin/jit.php) masked the bug because typed locals don't take the value-box path there.

Fix

All live non-strict paths (null → deprecation + 0, Stringable object → coerced length, plain value → coerced length) now branch to a shared strlen_value_len_done block and merge via phi, mirroring the existing JitLongArg::lowerValueBoxToLong idiom. Strict-mode behavior unchanged.

Verification (php-compiler:22.04-dev, LLVM 9)

Case Before After VM
$x="abc"; echo strlen($x); echo "after"; (silent exit 0) 3 + after 3 + after
null operand, non-strict (silent exit) 0 + continues 0 + continues
strict_types=1, string (silent exit) 6 6
bin/jit.php repro 3 3 —
examples/000 AOT Hello World Hello World —

phpunit --filter Strlen: failure set identical to master (9 pre-existing, 0 introduced — verified by diffing failing data-set names against a pristine master tree). Known remaining gap (pre-existing): Stringable object strlen returns 0 in AOT vs 4 on VM — landed inside the broken window (#13480), tracked separately.

🤖 Generated with Claude Code

…y terminated AOT binaries (#15632)

df16f37 (#11263) added a non-strict null-coercion branch to
JitStrlen::lowerLengthFromValueBox that returned const 0 with the
builder still positioned in the null block, leaving okBlock (the
real-string path) and coerceBlock dangling with no terminator. Any
non-constant-folded strlen() in an AOT binary fell off the empty
block: process exited 0 mid-output. MCJIT masked it (boxed locals
lower differently under bin/jit.php), so only phpc build binaries died.

Restructure the non-strict path so all live paths (null -> 0 with
deprecation, Stringable object -> coerced length, plain -> coerced
length) branch to a shared done block and merge via phi, mirroring
JitLongArg::lowerValueBoxToLong.

Verified in php-compiler:22.04-dev (LLVM 9), AOT vs VM parity:
  $x="abc"; echo strlen($x)  -> 3 + continues (was: silent exit 0)
  null operand (non-strict)      -> 0 + continues
  strict_types=1 string          -> 6 + continues
  examples/000 AOT               -> Hello World
  phpunit --filter Strlen        -> identical failure set to master
  (9 pre-existing failures, none introduced; Stringable AOT length
  mismatch pre-exists and is tracked separately)

Root cause of #15624 first layer; multipart $_FILES needs the
remaining broken builtins (preg_match capture assign, explode CRLF,
str_contains, substr negative length) tracked in the follow-up issue.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@PurHur
PurHur force-pushed the fix/15632-strlen-aot-valuebox branch from 0c4c3f2 to 8aafc61 Compare July 3, 2026 21:19
@PurHur

PurHur commented Jul 3, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto master after #15641 landed. #15641's null-path phi kept the non-strict objectBlock early return, so plain-string strlen still silently killed binaries (verified at 8250d40: repro prints nothing, exit 0). This PR now completes it on top of master: object path merges via phi, merge block only appended in non-strict mode (was a new dangling block on strict scripts), phi incomings use getInsertBlock() instead of block labels.

Re-verified after rebase (Docker LLVM 9): plain 3+after · null 0+after · strict 6+after · Stringable continues (length parity tracked in #15642) · examples/000 Hello World · phpunit --filter Strlen: same 9 pre-existing failures as master, #15641's new tests pass.

@PurHur
PurHur merged commit b2d68d6 into master Jul 3, 2026
@PurHur
PurHur deleted the fix/15632-strlen-aot-valuebox branch July 3, 2026 21:20
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.

Regression: strlen() on non-constant operand silently terminates AOT binaries — exit 0, output truncated; VM/JIT fine (root cause of #15624)

2 participants