Skip to content

ext/opcache: Do not drop QM_ASSIGN of IS_VAR before ZEND_RETURN - #478

Closed
iliaal wants to merge 1 commit into
PHP-8.6from
fix/gh-25756-return-assign-ref-opcache
Closed

iliaal wants to merge 1 commit into
PHP-8.6from
fix/gh-25756-return-assign-ref-opcache

Conversation

@iliaal

@iliaal iliaal commented Nov 25, 2026

Copy link
Copy Markdown
Owner

In Zend/Optimizer/block_pass.c, zend_optimize_block() eliminates a ZEND_QM_ASSIGN feeding ZEND_RETURN by copying src->op1 into ZEND_RETURN without checking src->op1_type.

Since phpGH-20628 (6173a9a1098), ZEND_RETURN (opcode 62) only has CONST|TMP|CV handlers and no VAR handler. By-reference assignments ($a = &$b, $obj->p = &$b, $arr[0] = &$b, C::$p = &$b) and by-reference list destructuring ([&$a] = $arr) in a read context emit a ZEND_QM_ASSIGN dereference wrapper to convert IS_VAR to IS_TMP_VAR. Dropping that ZEND_QM_ASSIGN leaves ZEND_RETURN with IS_VAR (type 4) and fails at runtime with Fatal error: Invalid opcode 62/4/0..

Guard the ZEND_RETURN substitution with src->op1_type != IS_VAR, as done for ZEND_JMPZ/ZEND_JMPNZ and ZEND_JMPZ_EX/ZEND_JMPNZ_EX in 6441f89857b (phpGH-21691).

Fixes phpGH-25756

Keep the dereferencing QM_ASSIGN when its source is IS_VAR. ZEND_RETURN
only accepts CONST, TMP, and CV, so folding the assignment into the
return can produce an invalid opcode for by-reference assignments or
list destructuring.

Fixes phpGH-25756
@iliaal
iliaal force-pushed the fix/gh-25756-return-assign-ref-opcache branch from aea9580 to 85a561c Compare November 26, 2026 23:27
@iliaal

iliaal commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as php#25814.

@iliaal iliaal closed this Nov 27, 2026
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.

1 participant