Skip to content

Commit 23c5a6f

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: JIT: Fix exception handling when next array element is already occupied
2 parents 60717fc + aff1155 commit 23c5a6f

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

Zend/Optimizer/dce.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,10 @@ static inline bool may_break_varargs(const zend_op_array *op_array, const zend_s
519519
return 0;
520520
}
521521

522+
static inline bool may_throw_dce_exception(const zend_op *opline) {
523+
return opline->opcode == ZEND_ADD_ARRAY_ELEMENT && opline->op2_type == IS_UNUSED;
524+
}
525+
522526
int dce_optimize_op_array(zend_op_array *op_array, zend_ssa *ssa, bool reorder_dtor_effects) {
523527
int i;
524528
zend_ssa_phi *phi;
@@ -585,7 +589,8 @@ int dce_optimize_op_array(zend_op_array *op_array, zend_ssa *ssa, bool reorder_d
585589
add_operands_to_worklists(&ctx, &op_array->opcodes[op_data], &ssa->ops[op_data], ssa, 0);
586590
}
587591
} else if (may_have_side_effects(op_array, ssa, &op_array->opcodes[i], &ssa->ops[i], ctx.reorder_dtor_effects)
588-
|| zend_may_throw(&op_array->opcodes[i], &ssa->ops[i], op_array, ssa)
592+
|| (zend_may_throw(&op_array->opcodes[i], &ssa->ops[i], op_array, ssa)
593+
&& !may_throw_dce_exception(&op_array->opcodes[i]))
589594
|| (has_varargs && may_break_varargs(op_array, ssa, &ssa->ops[i]))) {
590595
if (op_array->opcodes[i].opcode == ZEND_NEW
591596
&& op_array->opcodes[i+1].opcode == ZEND_DO_FCALL

Zend/Optimizer/sccp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,12 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
23002300
return 0;
23012301
}
23022302
break;
2303+
case ZEND_INIT_ARRAY:
2304+
case ZEND_ADD_ARRAY_ELEMENT:
2305+
if (opline->op2_type == IS_UNUSED) {
2306+
return 0;
2307+
}
2308+
/* break missing intentionally */
23032309
default:
23042310
if (zend_may_throw(opline, ssa_op, op_array, ssa)) {
23052311
return 0;

Zend/Optimizer/zend_inference.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4823,8 +4823,9 @@ ZEND_API int zend_may_throw_ex(const zend_op *opline, const zend_ssa_op *ssa_op,
48234823
case ZEND_ROPE_END:
48244824
return t2 & (MAY_BE_ARRAY|MAY_BE_OBJECT);
48254825
case ZEND_INIT_ARRAY:
4826-
case ZEND_ADD_ARRAY_ELEMENT:
48274826
return (opline->op2_type != IS_UNUSED) && (t2 & (MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE));
4827+
case ZEND_ADD_ARRAY_ELEMENT:
4828+
return (opline->op2_type == IS_UNUSED) || (t2 & (MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE));
48284829
case ZEND_STRLEN:
48294830
return (t1 & MAY_BE_ANY) != MAY_BE_STRING;
48304831
case ZEND_COUNT:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Occupied next element
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
--FILE--
9+
<?php
10+
$float = 100000000000000000000000000000000000000;
11+
$string_float= PHP_INT_MAX;
12+
$a = [$float => 'a', $string_float => 'b', 'c', 'd'];
13+
?>
14+
--EXPECTF--
15+
Deprecated: Implicit conversion from float 1.0E+38 to int loses precision in %sarray_elem_002.php on line 4
16+
17+
Fatal error: Uncaught Error: Cannot add element to the array as the next element is already occupied in %sarray_elem_002.php:4
18+
Stack trace:
19+
#0 {main}
20+
thrown in %sarray_elem_002.php on line 4

0 commit comments

Comments
 (0)