@@ -7128,6 +7128,40 @@ check_branch_block(WASMLoaderContext *loader_ctx, uint8 **p_buf, uint8 *buf_end,
7128
7128
return NULL ;
7129
7129
}
7130
7130
7131
+ #if WASM_ENABLE_EXCE_HANDLING != 0
7132
+ static BranchBlock *
7133
+ check_branch_block_for_delegate (WASMLoaderContext * loader_ctx , uint8 * * p_buf ,
7134
+ uint8 * buf_end , char * error_buf ,
7135
+ uint32 error_buf_size )
7136
+ {
7137
+ uint8 * p = * p_buf , * p_end = buf_end ;
7138
+ BranchBlock * frame_csp_tmp ;
7139
+ uint32 depth ;
7140
+
7141
+ read_leb_uint32 (p , p_end , depth );
7142
+ /*
7143
+ * Note: "delegate 0" means the surrounding block, not the
7144
+ * try-delegate block itself.
7145
+ *
7146
+ * Note: the caller hasn't popped the try-delegate frame yet.
7147
+ */
7148
+ bh_assert (loader_ctx -> csp_num > 0 );
7149
+ if (loader_ctx -> csp_num - 1 <= depth ) {
7150
+ set_error_buf (error_buf , error_buf_size , "unknown delegate label" );
7151
+ goto fail ;
7152
+ }
7153
+ frame_csp_tmp = loader_ctx -> frame_csp - depth - 2 ;
7154
+ #if WASM_ENABLE_FAST_INTERP != 0
7155
+ emit_br_info (frame_csp_tmp );
7156
+ #endif
7157
+
7158
+ * p_buf = p ;
7159
+ return frame_csp_tmp ;
7160
+ fail :
7161
+ return NULL ;
7162
+ }
7163
+ #endif
7164
+
7131
7165
static bool
7132
7166
check_block_stack (WASMLoaderContext * loader_ctx , BranchBlock * block ,
7133
7167
char * error_buf , uint32 error_buf_size )
@@ -7832,16 +7866,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
7832
7866
case WASM_OP_DELEGATE :
7833
7867
{
7834
7868
/* check target block is valid */
7835
- if (!(frame_csp_tmp = check_branch_block (
7869
+ if (!(frame_csp_tmp = check_branch_block_for_delegate (
7836
7870
loader_ctx , & p , p_end , error_buf , error_buf_size )))
7837
7871
goto fail ;
7838
7872
7839
- /* valid types */
7840
- if (LABEL_TYPE_TRY != frame_csp_tmp -> label_type ) {
7841
- snprintf (error_buf , error_buf_size , "unknown label" );
7842
- goto fail ;
7843
- }
7844
-
7845
7873
BranchBlock * cur_block = loader_ctx -> frame_csp - 1 ;
7846
7874
uint8 label_type = cur_block -> label_type ;
7847
7875
0 commit comments