Skip to content

Commit a12f43e

Browse files
committed
Reorder the oplines
1. we should only do the return type checking when it is really about to return 2. for 029.php, actually, the exception threw should be discard while it jmp into finally(it could be observed by change the return to return an array) 3. after this fix, the test 029.phpt behavior consistently with 7.0 4. good for optimizer too
1 parent 8ba7878 commit a12f43e

File tree

3 files changed

+7
-17
lines changed

3 files changed

+7
-17
lines changed

Zend/tests/return_types/029.phpt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,8 @@ function foo() : array {
1616
foo();
1717
?>
1818
--EXPECTF--
19-
Fatal error: Uncaught Exception: xxxx in %s:%d
19+
Fatal error: Uncaught TypeError: Return value of foo() must be of the type array, null returned in %s029.php:%d
2020
Stack trace:
21-
#0 %s(%d): foo()
21+
#0 %s: foo()
2222
#1 {main}
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
23+
thrown in %s 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+
42124214
/* Generator return types are handled separately */
42134215
if (!is_generator && CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
42144216
zend_emit_return_type_check(
42154217
expr_ast ? &expr_node : NULL, CG(active_op_array)->arg_info - 1, 0);
42164218
}
42174219

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: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ 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);
509510
if (ret_info->class_name
510511
|| ret_info->type_hint == IS_CALLABLE
511512
|| !ZEND_SAME_FAKE_TYPE(ret_info->type_hint, Z_TYPE_P(val))
@@ -514,13 +515,7 @@ int zend_optimizer_replace_by_const(zend_op_array *op_array,
514515
return 0;
515516
}
516517
MAKE_NOP(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-
518+
++opline;
524519
break;
525520
}
526521
default:

0 commit comments

Comments
 (0)