@@ -649,7 +649,8 @@ static void zend_end_live_range(zend_op_array *op_array, uint32_t offset, uint32
649
649
}
650
650
/* }}} */
651
651
652
- static inline void zend_begin_loop (zend_uchar free_opcode , const znode * loop_var ) /* {{{ */
652
+ static inline void zend_begin_loop (
653
+ zend_uchar free_opcode , const znode * loop_var , zend_bool is_switch ) /* {{{ */
653
654
{
654
655
zend_brk_cont_element * brk_cont_element ;
655
656
int parent = CG (context ).current_brk_cont ;
@@ -658,6 +659,7 @@ static inline void zend_begin_loop(zend_uchar free_opcode, const znode *loop_var
658
659
CG (context ).current_brk_cont = CG (context ).last_brk_cont ;
659
660
brk_cont_element = get_next_brk_cont_element ();
660
661
brk_cont_element -> parent = parent ;
662
+ brk_cont_element -> is_switch = is_switch ;
661
663
662
664
if (loop_var && (loop_var -> op_type & (IS_VAR |IS_TMP_VAR ))) {
663
665
uint32_t start = get_next_op_number (CG (active_op_array ));
@@ -4585,6 +4587,29 @@ void zend_compile_break_continue(zend_ast *ast) /* {{{ */
4585
4587
depth , depth == 1 ? "" : "s" );
4586
4588
}
4587
4589
}
4590
+
4591
+ if (ast -> kind == ZEND_AST_CONTINUE ) {
4592
+ int d , cur = CG (context ).current_brk_cont ;
4593
+ for (d = depth - 1 ; d > 0 ; d -- ) {
4594
+ cur = CG (context ).brk_cont_array [cur ].parent ;
4595
+ ZEND_ASSERT (cur != -1 );
4596
+ }
4597
+
4598
+ if (CG (context ).brk_cont_array [cur ].is_switch ) {
4599
+ if (depth == 1 ) {
4600
+ zend_error (E_WARNING ,
4601
+ "\"continue\" targeting switch is equivalent to \"break\". " \
4602
+ "Did you mean to use \"continue %d\"?" ,
4603
+ depth + 1 );
4604
+ } else {
4605
+ zend_error (E_WARNING ,
4606
+ "\"continue %d\" targeting switch is equivalent to \"break %d\". " \
4607
+ "Did you mean to use \"continue %d\"?" ,
4608
+ depth , depth , depth + 1 );
4609
+ }
4610
+ }
4611
+ }
4612
+
4588
4613
opline = zend_emit_op (NULL , ast -> kind == ZEND_AST_BREAK ? ZEND_BRK : ZEND_CONT , NULL , NULL );
4589
4614
opline -> op1 .num = CG (context ).current_brk_cont ;
4590
4615
opline -> op2 .num = depth ;
@@ -4697,7 +4722,7 @@ void zend_compile_while(zend_ast *ast) /* {{{ */
4697
4722
4698
4723
opnum_jmp = zend_emit_jump (0 );
4699
4724
4700
- zend_begin_loop (ZEND_NOP , NULL );
4725
+ zend_begin_loop (ZEND_NOP , NULL , 0 );
4701
4726
4702
4727
opnum_start = get_next_op_number (CG (active_op_array ));
4703
4728
zend_compile_stmt (stmt_ast );
@@ -4720,7 +4745,7 @@ void zend_compile_do_while(zend_ast *ast) /* {{{ */
4720
4745
znode cond_node ;
4721
4746
uint32_t opnum_start , opnum_cond ;
4722
4747
4723
- zend_begin_loop (ZEND_NOP , NULL );
4748
+ zend_begin_loop (ZEND_NOP , NULL , 0 );
4724
4749
4725
4750
opnum_start = get_next_op_number (CG (active_op_array ));
4726
4751
zend_compile_stmt (stmt_ast );
@@ -4771,7 +4796,7 @@ void zend_compile_for(zend_ast *ast) /* {{{ */
4771
4796
4772
4797
opnum_jmp = zend_emit_jump (0 );
4773
4798
4774
- zend_begin_loop (ZEND_NOP , NULL );
4799
+ zend_begin_loop (ZEND_NOP , NULL , 0 );
4775
4800
4776
4801
opnum_start = get_next_op_number (CG (active_op_array ));
4777
4802
zend_compile_stmt (stmt_ast );
@@ -4834,7 +4859,7 @@ void zend_compile_foreach(zend_ast *ast) /* {{{ */
4834
4859
opnum_reset = get_next_op_number (CG (active_op_array ));
4835
4860
opline = zend_emit_op (& reset_node , by_ref ? ZEND_FE_RESET_RW : ZEND_FE_RESET_R , & expr_node , NULL );
4836
4861
4837
- zend_begin_loop (ZEND_FE_FREE , & reset_node );
4862
+ zend_begin_loop (ZEND_FE_FREE , & reset_node , 0 );
4838
4863
4839
4864
opnum_fetch = get_next_op_number (CG (active_op_array ));
4840
4865
opline = zend_emit_op (NULL , by_ref ? ZEND_FE_FETCH_RW : ZEND_FE_FETCH_R , & reset_node , NULL );
@@ -4989,7 +5014,7 @@ void zend_compile_switch(zend_ast *ast) /* {{{ */
4989
5014
4990
5015
zend_compile_expr (& expr_node , expr_ast );
4991
5016
4992
- zend_begin_loop (ZEND_FREE , & expr_node );
5017
+ zend_begin_loop (ZEND_FREE , & expr_node , 1 );
4993
5018
4994
5019
case_node .op_type = IS_TMP_VAR ;
4995
5020
case_node .u .op .var = get_temporary_variable (CG (active_op_array ));
0 commit comments