Skip to content

Commit 02e1448

Browse files
committed
Treat throw inside block as non-terminator
1 parent 5cbea46 commit 02e1448

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

Zend/zend_compile.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ void zend_oparray_context_begin(zend_oparray_context *prev_context) /* {{{ */
317317
CG(context).brk_cont_array = NULL;
318318
CG(context).labels = NULL;
319319
CG(context).has_unfinished_calls = false;
320+
CG(context).in_block_expr = false;
320321
}
321322
/* }}} */
322323

@@ -5350,11 +5351,13 @@ static void zend_compile_throw(znode *result, zend_ast *ast) /* {{{ */
53505351
zend_compile_expr(&expr_node, expr_ast);
53515352

53525353
zend_op *opline = zend_emit_op(NULL, ZEND_THROW, &expr_node, NULL);
5353-
if (result) {
5354+
if (result || CG(context).in_block_expr) {
53545355
/* Mark this as an "expression throw" for opcache. */
53555356
opline->extended_value = ZEND_THROW_IS_EXPR;
5356-
result->op_type = IS_CONST;
5357-
ZVAL_TRUE(&result->u.constant);
5357+
if (result) {
5358+
result->op_type = IS_CONST;
5359+
ZVAL_TRUE(&result->u.constant);
5360+
}
53585361
}
53595362
}
53605363
/* }}} */
@@ -6139,7 +6142,7 @@ static void zend_compile_match(znode *result, zend_ast *ast)
61396142
if (opline->op1_type == IS_CONST) {
61406143
Z_TRY_ADDREF_P(CT_CONSTANT(opline->op1));
61416144
}
6142-
if (arms->children == 0) {
6145+
if (arms->children == 0 || CG(context).in_block_expr) {
61436146
/* Mark this as an "expression throw" for opcache. */
61446147
opline->extended_value = ZEND_THROW_IS_EXPR;
61456148
}
@@ -6188,8 +6191,11 @@ static void zend_compile_match(znode *result, zend_ast *ast)
61886191

61896192
znode body_node;
61906193
if (body_ast->kind == ZEND_AST_MATCH_ARM_BLOCK) {
6194+
bool prev_in_block_expr = CG(context).in_block_expr;
6195+
CG(context).in_block_expr = true;
61916196
zend_compile_stmt_list(body_ast->child[0]);
61926197
zend_compile_expr(&body_node, body_ast->child[1]);
6198+
CG(context).in_block_expr = prev_in_block_expr;
61936199
} else {
61946200
zend_compile_expr(&body_node, body_ast);
61956201
}
@@ -9633,11 +9639,13 @@ static void zend_compile_exit(znode *result, zend_ast *ast) /* {{{ */
96339639
}
96349640

96359641
zend_op *opline = zend_emit_op(NULL, ZEND_EXIT, &expr_node, NULL);
9636-
if (result) {
9642+
if (result || CG(context).in_block_expr) {
96379643
/* Mark this as an "expression throw" for opcache. */
96389644
opline->extended_value = ZEND_THROW_IS_EXPR;
9639-
result->op_type = IS_CONST;
9640-
ZVAL_TRUE(&result->u.constant);
9645+
if (result) {
9646+
result->op_type = IS_CONST;
9647+
ZVAL_TRUE(&result->u.constant);
9648+
}
96419649
}
96429650
}
96439651
/* }}} */

Zend/zend_compile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ typedef struct _zend_oparray_context {
191191
HashTable *labels;
192192
/* Whether we're currently evaluating function arguments. */
193193
bool has_unfinished_calls;
194+
bool in_block_expr;
194195
} zend_oparray_context;
195196

196197
/* Class, property and method flags class|meth.|prop.|const*/

0 commit comments

Comments
 (0)