Skip to content

JIT: Fix JIT ASSIGN_DIM undefined OP_DATA and dim reporting on non-array containers - #24665

Open
jorgsowa wants to merge 2 commits into
php:PHP-8.4from
jorgsowa:fix-jit-assign-dim-undef-op-data
Open

jorgsowa wants to merge 2 commits into
php:PHP-8.4from
jorgsowa:fix-jit-assign-dim-undef-op-data

Conversation

@jorgsowa

Copy link
Copy Markdown
Contributor

In function JIT, zend_jit_assign_dim_helper() read an undefined OP_DATA before checking the container type. The VM reads it only when it actually assigns, so the JIT reported warnings in a different order, or where the VM reports none:

Code VM Function JIT
$x = 1.5; $x[0] = $undef; Error: Cannot use a scalar value as an array extra Undefined variable warning before the Error
$x = 'ab'; $x[] = $undef; Error: [] operator not supported for strings extra Undefined variable warning before the Error
$x = false; $x[0] = $undef; Deprecated (false to array), then Undefined variable Undefined variable, then Deprecated
$x = 1.5; $x[$undef] = 1; Error: Cannot use a scalar value as an array extra Undefined variable warning before the Error

The helper now checks for an undefined value only on the false path, after the deprecation, and no longer reports an undefined key on the scalar path. The generated JIT code is unchanged, and the helper is slightly smaller at -O2 (183 instructions instead of 207 on arm64).

…ontainers

Report an undefined OP_DATA only when the value is assigned, after the
false to array deprecation, and never report an undefined dim before
"Cannot use a scalar value as an array", matching the VM.
@jorgsowa jorgsowa self-assigned this Oct 24, 2026
@jorgsowa
jorgsowa requested a review from dstogov as a code owner October 24, 2026 22:25
Comment thread ext/opcache/jit/zend_jit_helpers.c Outdated
ZEND_ASSERT(op_data->opcode == ZEND_OP_DATA && op_data->op1_type == IS_CV);
if (!zend_jit_undefined_op_helper_write(arr, op_data->op1.var)) {
if (result) {
ZVAL_UNDEF(result);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't this be ZVAL_NULL? That would match some of the other code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I fixed it and added regression test for this path.

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