Skip to content

Commit 64ec25c

Browse files
committed
Avoid nesting jmp_frameless branches
Opcodes grow exponentially for nested calls.
1 parent 8a9d933 commit 64ec25c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Zend/zend_compile.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ void zend_oparray_context_begin(zend_oparray_context *prev_context) /* {{{ */
325325
CG(context).last_brk_cont = 0;
326326
CG(context).brk_cont_array = NULL;
327327
CG(context).labels = NULL;
328+
CG(context).in_jmp_frameless_branch = false;
328329
}
329330
/* }}} */
330331

@@ -4630,7 +4631,9 @@ static void zend_compile_ns_call(znode *result, znode *name_node, zend_ast *args
46304631
/* Find frameless function with same name. */
46314632
zend_function *frameless_function = NULL;
46324633
if (args_ast->kind != ZEND_AST_CALLABLE_CONVERT
4633-
&& !zend_args_contain_unpack_or_named(zend_ast_get_list(args_ast))) {
4634+
&& !zend_args_contain_unpack_or_named(zend_ast_get_list(args_ast))
4635+
/* Avoid blowing up op count with nested frameless branches. */
4636+
&& !CG(context).in_jmp_frameless_branch) {
46344637
zend_string *lc_func_name = Z_STR_P(CT_CONSTANT_EX(CG(active_op_array), name_constants + 2));
46354638
frameless_function = zend_hash_find_ptr(CG(function_table), lc_func_name);
46364639
}
@@ -4641,6 +4644,7 @@ static void zend_compile_ns_call(znode *result, znode *name_node, zend_ast *args
46414644
if (frameless_function) {
46424645
frameless_function_info = find_frameless_function_info(zend_ast_get_list(args_ast), frameless_function, type);
46434646
if (frameless_function_info) {
4647+
CG(context).in_jmp_frameless_branch = true;
46444648
znode op1;
46454649
op1.op_type = IS_CONST;
46464650
ZVAL_COPY(&op1.u.constant, CT_CONSTANT_EX(CG(active_op_array), name_constants + 1));
@@ -4670,6 +4674,8 @@ static void zend_compile_ns_call(znode *result, znode *name_node, zend_ast *args
46704674
zend_op *flf_icall = &CG(active_op_array)->opcodes[flf_icall_opnum];
46714675
SET_NODE(flf_icall->result, result);
46724676
zend_update_jump_target_to_next(jmp_end_opnum);
4677+
4678+
CG(context).in_jmp_frameless_branch = false;
46734679
}
46744680
}
46754681
/* }}} */

Zend/zend_compile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ typedef struct _zend_oparray_context {
199199
int last_brk_cont;
200200
zend_brk_cont_element *brk_cont_array;
201201
HashTable *labels;
202+
bool in_jmp_frameless_branch;
202203
} zend_oparray_context;
203204

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

0 commit comments

Comments
 (0)