Skip to content

Fix GH-25449: Keep by-ref containers out of converted FUNC_ARG fetches - #25458

Closed
iliaal wants to merge 1 commit into
php:PHP-8.6from
iliaal:fix/gh-25449-func-arg-ref-call
Closed

iliaal wants to merge 1 commit into
php:PHP-8.6from
iliaal:fix/gh-25449-func-arg-ref-call

Conversation

@iliaal

@iliaal iliaal commented Nov 14, 2026

Copy link
Copy Markdown
Member

When g() returns by reference and the callee of f(g()['k']) is not known at compile time, OPcache passes null to f() and debug builds assert in FETCH_DIM_R. Since GH-20628, FETCH_DIM_R and FETCH_OBJ_R expect a VAR container to be unwrapped already, but pass 4 converts the FUNC_ARG fetch to its _R form while the container is still the VAR result of the by-ref call; an assignment by reference such as f(($y = &$x)['k']) hits the same assertion. Retype the call result to TMP, as the compiler emits for a known callee, and keep the FUNC_ARG fetch for any other producer except an already converted read fetch.

Fixes #25449

@jorgsowa jorgsowa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one comment. Everything else looks good to me.

Comment thread ext/opcache/tests/opt/gh25449.phpt Outdated
function closureDim(Closure $c): string { return consume($c()['k']); }
function assignRefDim(): string { $x = ['k' => 'assign-ref']; return consume(($y = &$x)['k']); }
function assignRefObj(): string { $x = new K; return consume(($y = &$x)->p['k']); }
function listRefDim(): string { $a = [['k' => 'list-ref']]; return consume(([&$z] = $a)[0]['k']); }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function listRefDim(): string { $a = [['k' => 'list-ref']]; return consume(([&$z] = $a)[0]['k']); }
function listRefDim(): string { $a = ['x' => ['k' => 'list-ref']]; return consume((['x' => &$z] = $a)['x']['k']); }

Integer key doesn't assert anything without fix. You can change it to string key so it's proper regression test

Since phpGH-20628, FETCH_DIM_R and FETCH_OBJ_R expect a VAR container to be
unwrapped already. Pass 4 turned FETCH_DIM_FUNC_ARG and FETCH_OBJ_FUNC_ARG
into their _R forms once the argument was known to be by-value, without
checking where the VAR came from, so a reference returned by a by-reference
call or produced by an assignment by reference reached the _R handler.
Retype a defining DO_*CALL result and the fetch operand to TMP, so the callee
unwraps its return value as it does when the callee is known at compile time.
Keep the FUNC_ARG fetch for any other producer that is not an already
converted read fetch.

Fixes phpGH-25449
@iliaal
iliaal force-pushed the fix/gh-25449-func-arg-ref-call branch from 3cc18be to 95cacec Compare November 22, 2026 16:49
@iliaal iliaal closed this in 12d9e40 Nov 22, 2026
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