Skip to content

Fix GH-25756: Do not fold IS_VAR QM_ASSIGN into ZEND_RETURN - #25781

Closed
prateekbhujel wants to merge 1 commit into
php:PHP-8.6from
prateekbhujel:fix/gh25756-block-pass-return-var
Closed

prateekbhujel wants to merge 1 commit into
php:PHP-8.6from
prateekbhujel:fix/gh25756-block-pass-return-var

Conversation

@prateekbhujel

Copy link
Copy Markdown
Contributor

Since the VAR|TMP overhaul (GH-20628, 6173a9a1098), ZEND_RETURN only handles CONST|TMP|CV operands, and by-reference assignments (e.g. return $a = &$b;, arrow functions, match arms) emit ZEND_QM_ASSIGN to unwrap the IS_VAR reference into an IS_TMP_VAR.

In Zend/Optimizer/block_pass.c, the ZEND_RETURN optimization folded T = QM_ASSIGN(X); RETURN(T) into RETURN(X) without checking src->op1_type != IS_VAR (unlike the ZEND_JMPZ/ZEND_JMPNZ and ZEND_JMPZ_EX/ZEND_JMPNZ_EX folds in the same pass), producing ZEND_RETURN with an IS_VAR operand (Fatal error: Invalid opcode 62/4/0).

Audited all other COPY_NODE / ZEND_QM_ASSIGN folds in Zend/Optimizer/block_pass.c against the handlers changed in GH-20628; ZEND_RETURN is the only missing src->op1_type != IS_VAR guard.

Closes GH-25756.

Since the VAR|TMP overhaul (phpGH-20628, 6173a9a), ZEND_RETURN only handles CONST|TMP|CV operands, and by-reference assignments (such as `return $a = &$b`) rely on ZEND_QM_ASSIGN to unwrap the IS_VAR reference into an IS_TMP_VAR.

The block pass folded `T = QM_ASSIGN(X); RETURN(T)` into `RETURN(X)` without checking `src->op1_type != IS_VAR` (unlike the ZEND_JMPZ/ZEND_JMPZ_EX folds in the same pass), emitting an invalid `ZEND_RETURN` with an `IS_VAR` operand ("Invalid opcode 62/4/0").

Closes phpGH-25756
@jorgsowa

Copy link
Copy Markdown
Contributor

The same solution as in https://github.com/iliaal/php-src/pull/478/files CC: @iliaal

@prateekbhujel

Copy link
Copy Markdown
Contributor Author

My bad, missed the cross-referenced PR on iliaal#478. Closing in favor of @iliaal's fix.

@jorgsowa

Copy link
Copy Markdown
Contributor

No problem, if you see that someone is already assigned to the issue, then the person likely already started work on it.

@prateekbhujel
prateekbhujel deleted the fix/gh25756-block-pass-return-var branch November 26, 2026 13:49
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.

2 participants