com php-src: a: try { ... } ≠ try { a: . .. }: Zend/tests/try/finally_goto_005.p hpt Zend/zend_compile.c
| From: | Bob Weinand | Date: | Fri, 10 Jul 2015 21:29:07 +0000 |
| Subject: | com php-src: a: try { ... } ≠ try { a: . .. }: Zend/tests/try/finally_goto_005.p hpt Zend/zend_compile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-87915@lists.php.net to get a copy of this message | ||
Commit: 56800e470bc591cd8718f7b5d245c105bbffb698
Author: Bob Weinand <bobwei9@hotmail.com> Fri, 10 Jul 2015 23:29:07 +0200
Parents: ed62db9abc5f4d399c4f20e82cd717e331389b6e
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=56800e470bc591cd8718f7b5d245c105bbffb698
Log:
a: try { ... } ≠ try { a: ... }
Changed paths:
A Zend/tests/try/finally_goto_005.phpt
M Zend/zend_compile.c
Diff:
diff --git a/Zend/tests/try/finally_goto_005.phpt b/Zend/tests/try/finally_goto_005.phpt
new file mode 100644
index 0000000..36b4155
--- /dev/null
+++ b/Zend/tests/try/finally_goto_005.phpt
@@ -0,0 +1,15 @@
+--TEST--
+There must be a difference between label: try { ... } and try { label: ... }
+--FILE--
+<?php
+
+label: try {
+ goto label;
+} finally {
+ print "success";
+ return; // don't loop
+}
+
+?>
+--EXPECT--
+success
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index ce5d748..3f77350 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -4060,14 +4060,29 @@ void zend_compile_try(zend_ast *ast) /* {{{ */
uint32_t i;
zend_op *opline;
- uint32_t try_catch_offset = zend_add_try_element(
- get_next_op_number(CG(active_op_array)));
+ uint32_t try_catch_offset;
uint32_t *jmp_opnums = safe_emalloc(sizeof(uint32_t), catches->children, 0);
+ HashPosition hpos;
if (catches->children == 0 && !finally_ast) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use try without catch or finally");
}
+ /* label: try { } must not be equal to try { label: } */
+ if (CG(context).labels) {
+ zval *labelzv;
+ zend_hash_internal_pointer_end_ex(CG(context).labels, &hpos);
+ if ((labelzv = zend_hash_get_current_data_ex(CG(context).labels, &hpos))) {
+ zend_label *label = Z_PTR_P(labelzv);
+ if (label->opline_num == get_next_op_number(CG(active_op_array))) {
+ /* using a NOP doesn't work here, it would be removed by opcache */
+ zend_emit_jump(get_next_op_number(CG(active_op_array)) + 1);
+ }
+ }
+ }
+
+ try_catch_offset = zend_add_try_element(get_next_op_number(CG(active_op_array)));
+
zend_compile_stmt(try_ast);
if (catches->children != 0) {