summaryrefslogtreecommitdiff
path: root/Zend/zend_compile.c
diff options
context:
space:
mode:
Diffstat (limited to 'Zend/zend_compile.c')
-rw-r--r--Zend/zend_compile.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 593c19e015..3af1fb3861 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -4035,16 +4035,32 @@ void zend_compile_switch(zend_ast *ast) /* {{{ */
znode expr_node, case_node;
zend_op *opline;
- uint32_t *jmpnz_opnums = safe_emalloc(sizeof(uint32_t), cases->children, 0);
- uint32_t opnum_default_jmp;
+ uint32_t *jmpnz_opnums, opnum_default_jmp;
zend_compile_expr(&expr_node, expr_ast);
+ if (cases->children == 1 && cases->child[0]->child[0] == NULL) {
+ /* we have to take care about the case that only have one default branch,
+ * expr result will not be unrefed in this case, but it should be like in ZEND_CASE */
+ zend_ast *stmt_ast = cases->child[0]->child[1];
+ if (expr_node.op_type == IS_VAR || expr_node.op_type == IS_TMP_VAR) {
+ zend_emit_op(NULL, ZEND_FREE, &expr_node, NULL);
+ } else if (expr_node.op_type == IS_CONST) {
+ zval_dtor(&expr_node.u.constant);
+ }
+
+ zend_begin_loop(ZEND_NOP, NULL);
+ zend_compile_stmt(stmt_ast);
+ zend_end_loop(get_next_op_number(CG(active_op_array)));
+ return;
+ }
+
zend_begin_loop(ZEND_FREE, &expr_node);
case_node.op_type = IS_TMP_VAR;
case_node.u.op.var = get_temporary_variable(CG(active_op_array));
+ jmpnz_opnums = safe_emalloc(sizeof(uint32_t), cases->children, 0);
for (i = 0; i < cases->children; ++i) {
zend_ast *case_ast = cases->child[i];
zend_ast *cond_ast = case_ast->child[0];