Skip to content

Commit 82988d3

Browse files
committed
Revert "Reorder the oplines" (Break Zend/tests/return_types/bug71092.phpt)
This reverts commit a12f43e.
1 parent 7e21462 commit 82988d3

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

Zend/tests/return_types/029.phpt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ function foo() : array {
1616
foo();
1717
?>
1818
--EXPECTF--
19-
Fatal error: Uncaught TypeError: Return value of foo() must be of the type array, null returned in %s029.php:%d
19+
Fatal error: Uncaught Exception: xxxx in %s:%d
2020
Stack trace:
21-
#0 %s: foo()
21+
#0 %s(%d): foo()
2222
#1 {main}
23-
thrown in %s on line %d
23+
24+
Next TypeError: Return value of foo() must be of the type array, null returned in %s29.php:%d
25+
Stack trace:
26+
#0 %s(%d): foo()
27+
#1 {main}
28+
thrown in %s029.php on line %d

Zend/zend_compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4209,14 +4209,14 @@ void zend_compile_return(zend_ast *ast) /* {{{ */
42094209
}
42104210
}
42114211

4212-
zend_handle_loops_and_finally((expr_node.op_type & (IS_TMP_VAR | IS_VAR)) ? &expr_node : NULL);
4213-
42144212
/* Generator return types are handled separately */
42154213
if (!is_generator && CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
42164214
zend_emit_return_type_check(
42174215
expr_ast ? &expr_node : NULL, CG(active_op_array)->arg_info - 1, 0);
42184216
}
42194217

4218+
zend_handle_loops_and_finally((expr_node.op_type & (IS_TMP_VAR | IS_VAR)) ? &expr_node : NULL);
4219+
42204220
opline = zend_emit_op(NULL, by_ref ? ZEND_RETURN_BY_REF : ZEND_RETURN,
42214221
&expr_node, NULL);
42224222

ext/opcache/Optimizer/zend_optimizer.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ int zend_optimizer_replace_by_const(zend_op_array *op_array,
506506
}
507507
case ZEND_VERIFY_RETURN_TYPE: {
508508
zend_arg_info *ret_info = op_array->arg_info - 1;
509-
ZEND_ASSERT((opline + 1)->opcode == ZEND_RETURN || (opline + 1)->opcode == ZEND_RETURN_BY_REF);
510509
if (ret_info->class_name
511510
|| ret_info->type_hint == IS_CALLABLE
512511
|| !ZEND_SAME_FAKE_TYPE(ret_info->type_hint, Z_TYPE_P(val))
@@ -515,7 +514,13 @@ int zend_optimizer_replace_by_const(zend_op_array *op_array,
515514
return 0;
516515
}
517516
MAKE_NOP(opline);
518-
++opline;
517+
518+
/* zend_handle_loops_and_finally may inserts other oplines */
519+
do {
520+
++opline;
521+
} while (opline->opcode != ZEND_RETURN && opline->opcode != ZEND_RETURN_BY_REF);
522+
ZEND_ASSERT(ZEND_OP1(opline).var == var);
523+
519524
break;
520525
}
521526
default:

0 commit comments

Comments
 (0)