Skip to content

Commit 6a8fb0d

Browse files
committed
Fix
1 parent 8c9016d commit 6a8fb0d

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

Zend/Optimizer/dfa_pass.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,12 +1126,13 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
11261126

11271127
// TODO: move me to other function?
11281128
for (v = 0; v < ssa->vars_count; v++) {
1129-
if (ssa->vars[v].var >= op_array->last_var) {
1129+
int var = ssa->vars[v].var;
1130+
if (var >= op_array->last_var) {
11301131
continue;
11311132
}
11321133

11331134
uint32_t type = ssa->var_info[v].type;
1134-
if (!(type & (MAY_BE_ANY-(MAY_BE_RC1|MAY_BE_ARRAY|MAY_BE_ARRAY_OF_ANY|MAY_BE_STRING)))) {
1135+
if (!(type & (MAY_BE_ANY-(MAY_BE_RC1|MAY_BE_ARRAY|MAY_BE_ARRAY_OF_ANY|MAY_BE_STRING|MAY_BE_NULL)))) {
11351136
continue;
11361137
}
11371138

@@ -1147,17 +1148,21 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
11471148
&& op_array->opcodes[use].opcode == ZEND_SEND_VAR
11481149
&& op_array->opcodes[use].op2_type == IS_UNUSED) {
11491150
int next_use = zend_ssa_next_use(ssa->ops, v, use);
1150-
1151+
#if 0
11511152
if (next_use >= 0 && op_array->opcodes[next_use].opcode == ZEND_ASSIGN) {
1152-
fprintf(stderr, "v=%d next_use %d (%d, %d, %d)\n", v, next_use, ssa->ops[next_use].result_def, ssa->ops[next_use].result_use, ssa->ops[next_use].op1_use);
1153+
fprintf(stderr, "v=%d next_use %d (%d, %d, %d, %d)\n", v, next_use, ssa->ops[next_use].result_def, ssa->ops[next_use].result_use, ssa->ops[next_use].op1_use, ssa->ops[next_use].op2_use);
1154+
fprintf(stderr, "next_use var: %d (var=%d)\n", ssa->vars[next_use].var, var);
1155+
fprintf(stderr, "OP1: %d (var=%d)\n", ssa->vars[ssa->ops[next_use].op1_def].var, var);
11531156
}
1154-
1157+
#endif
11551158
/* Either there is no next use which is okay, or the next use is an assignment
11561159
* which overrides the previous value, which is also okay. */
11571160
if (next_use < 0
11581161
|| (op_array->opcodes[next_use].opcode == ZEND_ASSIGN
11591162
&& ssa->ops[next_use].op1_use == v
1163+
&& ssa->vars[v].var == var
11601164
&& zend_ssa_next_use(ssa->ops, v, next_use) < 0)) {
1165+
//fprintf(stderr, "HELLO\n");
11611166
ZEND_ASSERT(op_array->opcodes[use].extended_value == 0);
11621167
op_array->opcodes[use].extended_value = 1;
11631168
}

Zend/zend_vm_def.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9900,6 +9900,7 @@ ZEND_VM_HOT_TYPE_SPEC_HANDLER(ZEND_SEND_VAR, op->op2_type == IS_UNUSED && op->ex
99009900
arg = ZEND_CALL_VAR(EX(call), opline->result.var);
99019901

99029902
ZVAL_COPY_VALUE(arg, varptr);
9903+
ZVAL_NULL(varptr);
99039904
//fprintf(stderr, "Hello world, %d\n", Z_REFCOUNTED_P(arg));
99049905

99059906
ZEND_VM_NEXT_OPCODE();

Zend/zend_vm_execute.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/standard/array.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3923,14 +3923,17 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET
39233923
}
39243924
}
39253925

3926+
bool in_place = false;
39263927
arg = args;
39273928
src = Z_ARRVAL_P(arg);
39283929
/* copy first array if necessary */
39293930
if (HT_IS_PACKED(src)) {
39303931
/* Note: If it has holes, it might get sequentialized */
39313932
if (HT_IS_WITHOUT_HOLES(src) && !(GC_FLAGS(Z_ARRVAL_P(arg)) & (IS_ARRAY_IMMUTABLE | IS_ARRAY_PERSISTENT)) && Z_REFCOUNT_P(arg) == 1) {
39323933
dest = src;
3934+
in_place = true;
39333935
ZVAL_ARR(return_value, dest);
3936+
//fprintf(stderr, "in-place %d\n", GC_REFCOUNT(Z_ARRVAL_P(return_value)));
39343937
} else {
39353938
array_init_size(return_value, count);
39363939
dest = Z_ARRVAL_P(return_value);
@@ -3977,6 +3980,11 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET
39773980
php_array_merge(dest, Z_ARRVAL_P(arg));
39783981
}
39793982
}
3983+
3984+
if (in_place) {
3985+
GC_ADDREF(Z_ARRVAL_P(return_value));
3986+
}
3987+
//fprintf(stderr, "after, in-place %d %d\n", in_place, GC_REFCOUNT(Z_ARRVAL_P(return_value)));
39803988
}
39813989
/* }}} */
39823990

0 commit comments

Comments
 (0)