]> granicus.if.org Git - php/commitdiff
Reorder the oplines
authorXinchen Hui <laruence@gmail.com>
Sat, 17 Dec 2016 12:06:18 +0000 (20:06 +0800)
committerXinchen Hui <laruence@gmail.com>
Sat, 17 Dec 2016 12:06:18 +0000 (20:06 +0800)
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

Zend/tests/return_types/029.phpt
Zend/zend_compile.c
ext/opcache/Optimizer/zend_optimizer.c

index adc07cde7f4dd64a57b37b7dcdfd0c705cf94e0f..af13e6a69918c535828101e7eddf50482deed852 100644 (file)
@@ -16,13 +16,8 @@ function foo() : array {
 foo();
 ?>
 --EXPECTF--
-Fatal error: Uncaught Exception: xxxx in %s:%d
+Fatal error: Uncaught TypeError: Return value of foo() must be of the type array, null returned in %s029.php:%d
 Stack trace:
-#0 %s(%d): foo()
+#0 %s: foo()
 #1 {main}
-
-Next TypeError: Return value of foo() must be of the type array, null returned in %s29.php:%d
-Stack trace:
-#0 %s(%d): foo()
-#1 {main}
-  thrown in %s029.php on line %d
+  thrown in %s on line %d
index c8f2eefa7d2eca008b1bea579d257817494cdc8f..71599e0e089c587278bfcb465a5138987547852a 100644 (file)
@@ -4209,14 +4209,14 @@ void zend_compile_return(zend_ast *ast) /* {{{ */
                }
        }
 
+       zend_handle_loops_and_finally((expr_node.op_type & (IS_TMP_VAR | IS_VAR)) ? &expr_node : NULL);
+
        /* Generator return types are handled separately */
        if (!is_generator && CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
                zend_emit_return_type_check(
                        expr_ast ? &expr_node : NULL, CG(active_op_array)->arg_info - 1, 0);
        }
 
-       zend_handle_loops_and_finally((expr_node.op_type & (IS_TMP_VAR | IS_VAR)) ? &expr_node : NULL);
-
        opline = zend_emit_op(NULL, by_ref ? ZEND_RETURN_BY_REF : ZEND_RETURN,
                &expr_node, NULL);
 
index fa86b99b690a78eed901cbef14ac4e5ba9bf0b5f..5c6b690c0c2c0eb95cfe7c092aec7630defb9645 100644 (file)
@@ -506,6 +506,7 @@ int zend_optimizer_replace_by_const(zend_op_array *op_array,
                                }
                                case ZEND_VERIFY_RETURN_TYPE: {
                                        zend_arg_info *ret_info = op_array->arg_info - 1;
+                                       ZEND_ASSERT((opline + 1)->opcode == ZEND_RETURN || (opline + 1)->opcode == ZEND_RETURN_BY_REF);
                                        if (ret_info->class_name
                                                || ret_info->type_hint == IS_CALLABLE
                                                || !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,
                                                return 0;
                                        }
                                        MAKE_NOP(opline);
-
-                                       /* zend_handle_loops_and_finally may inserts other oplines */
-                                       do {
-                                               ++opline;
-                                       } while (opline->opcode != ZEND_RETURN && opline->opcode != ZEND_RETURN_BY_REF);
-                                       ZEND_ASSERT(ZEND_OP1(opline).var == var);
-
+                                       ++opline;
                                        break;
                                  }
                                default: