fix cleanup
Unified · Split
| @@ -94,7 +94,7 @@ static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td); · 93 unmodified lines | |||
| 94 | static void parse_expr_type(CType *type); | 94 | static void parse_expr_type(CType *type); |
| 95 | static void init_putv(CType *type, Section *sec, unsigned long c); | 95 | static void init_putv(CType *type, Section *sec, unsigned long c); |
| 96 | static void decl_initializer(CType *type, Section *sec, unsigned long c, int flags); | 96 | static void decl_initializer(CType *type, Section *sec, unsigned long c, int flags); |
| 97 | static void block(int *bsym, int *csym, int is_expr); | 97 | static void block(int *bsym, Sym *bcl, int *csym, Sym *ccl, int is_expr); |
| 98 | static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, int scope); | 98 | static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, int scope); |
| 99 | static void decl(int l); | 99 | static void decl(int l); |
| 100 | static int decl0(int l, int is_for_loop_init, Sym *); | 100 | static int decl0(int l, int is_for_loop_init, Sym *); |
| @@ -4891,7 +4891,7 @@ ST_FUNC void unary(void) · 4790 unmodified lines | |||
| 4891 | as statement expressions can't ever be entered from the | 4891 | as statement expressions can't ever be entered from the |
| 4892 | outside, so any reactivation of code emission (from labels | 4892 | outside, so any reactivation of code emission (from labels |
| 4893 | or loop heads) can be disabled again after the end of it. */ | 4893 | or loop heads) can be disabled again after the end of it. */ |
| 4894 | block(NULL, NULL, 1); | 4894 | block(NULL, NULL, NULL, NULL, 1); |
| 4895 | nocode_wanted = saved_nocode_wanted; | 4895 | nocode_wanted = saved_nocode_wanted; |
| 4896 | skip(')'); | 4896 | skip(')'); |
| 4897 | } else { | 4897 | } else { |
| @@ -6083,7 +6083,7 @@ static void gcase(struct case_t **base, int len, int *bsym) · 1185 unmodified lines | |||
| 6083 | } | 6083 | } |
| 6084 | } | 6084 | } |
| 6085 | 6085 | ||
| 6086 | static void block(int *bsym, int *csym, int is_expr) | 6086 | static void block(int *bsym, Sym *bcl, int *csym, Sym *ccl, int is_expr) |
| 6087 | { | 6087 | { |
| 6088 | int a, b, c, d, cond; | 6088 | int a, b, c, d, cond; |
| 6089 | Sym *s; | 6089 | Sym *s; |
| @@ -6112,7 +6112,7 @@ static void block(int *bsym, int *csym, int is_expr) · 22 unmodified lines | |||
| 6112 | a = gvtst(1, 0); | 6112 | a = gvtst(1, 0); |
| 6113 | if (cond == 0) | 6113 | if (cond == 0) |
| 6114 | nocode_wanted |= 0x20000000; | 6114 | nocode_wanted |= 0x20000000; |
| 6115 | block(bsym, csym, 0); | 6115 | block(bsym, bcl, csym, ccl, 0); |
| 6116 | if (cond != 1) | 6116 | if (cond != 1) |
| 6117 | nocode_wanted = saved_nocode_wanted; | 6117 | nocode_wanted = saved_nocode_wanted; |
| 6118 | if (tok == TOK_ELSE) { | 6118 | if (tok == TOK_ELSE) { |
| @@ -6121,7 +6121,7 @@ static void block(int *bsym, int *csym, int is_expr) · 2 unmodified lines | |||
| 6121 | gsym(a); | 6121 | gsym(a); |
| 6122 | if (cond == 1) | 6122 | if (cond == 1) |
| 6123 | nocode_wanted |= 0x20000000; | 6123 | nocode_wanted |= 0x20000000; |
| 6124 | block(bsym, csym, 0); | 6124 | block(bsym, bcl, csym, ccl, 0); |
| 6125 | gsym(d); /* patch else jmp */ | 6125 | gsym(d); /* patch else jmp */ |
| 6126 | if (cond != 0) | 6126 | if (cond != 0) |
| 6127 | nocode_wanted = saved_nocode_wanted; | 6127 | nocode_wanted = saved_nocode_wanted; |
| @@ -6140,7 +6140,7 @@ static void block(int *bsym, int *csym, int is_expr) · 12 unmodified lines | |||
| 6140 | b = 0; | 6140 | b = 0; |
| 6141 | ++local_scope; | 6141 | ++local_scope; |
| 6142 | saved_nocode_wanted = nocode_wanted; | 6142 | saved_nocode_wanted = nocode_wanted; |
| 6143 | block(&a, &b, 0); | 6143 | block(&a, current_cleanups, &b, current_cleanups, 0); |
| 6144 | nocode_wanted = saved_nocode_wanted; | 6144 | nocode_wanted = saved_nocode_wanted; |
| 6145 | --local_scope; | 6145 | --local_scope; |
| 6146 | gjmp_addr(d); | 6146 | gjmp_addr(d); |
| @@ -6182,7 +6182,7 @@ static void block(int *bsym, int *csym, int is_expr) · 35 unmodified lines | |||
| 6182 | if (tok != '}') { | 6182 | if (tok != '}') { |
| 6183 | if (is_expr) | 6183 | if (is_expr) |
| 6184 | vpop(); | 6184 | vpop(); |
| 6185 | block(bsym, csym, is_expr); | 6185 | block(bsym, bcl, csym, ccl, is_expr); |
| 6186 | } | 6186 | } |
| 6187 | } | 6187 | } |
| 6188 | 6188 | ||
| @@ -6258,6 +6258,7 @@ static void block(int *bsym, int *csym, int is_expr) · 69 unmodified lines | |||
| 6258 | /* compute jump */ | 6258 | /* compute jump */ |
| 6259 | if (!bsym) | 6259 | if (!bsym) |
| 6260 | tcc_error("cannot break"); | 6260 | tcc_error("cannot break"); |
| 6261 | try_call_scope_cleanup(bcl); | ||
| 6261 | *bsym = gjmp(*bsym); | 6262 | *bsym = gjmp(*bsym); |
| 6262 | next(); | 6263 | next(); |
| 6263 | skip(';'); | 6264 | skip(';'); |
| @@ -6266,6 +6267,7 @@ static void block(int *bsym, int *csym, int is_expr) · 2 unmodified lines | |||
| 6266 | /* compute jump */ | 6267 | /* compute jump */ |
| 6267 | if (!csym) | 6268 | if (!csym) |
| 6268 | tcc_error("cannot continue"); | 6269 | tcc_error("cannot continue"); |
| 6270 | try_call_scope_cleanup(ccl); | ||
| 6269 | vla_sp_restore_root(); | 6271 | vla_sp_restore_root(); |
| 6270 | *csym = gjmp(*csym); | 6272 | *csym = gjmp(*csym); |
| 6271 | next(); | 6273 | next(); |
| @@ -6309,7 +6311,7 @@ static void block(int *bsym, int *csym, int is_expr) · 37 unmodified lines | |||
| 6309 | } | 6311 | } |
| 6310 | skip(')'); | 6312 | skip(')'); |
| 6311 | saved_nocode_wanted = nocode_wanted; | 6313 | saved_nocode_wanted = nocode_wanted; |
| 6312 | block(&a, &b, 0); | 6314 | block(&a, current_cleanups, &b, current_cleanups, 0); |
| 6313 | nocode_wanted = saved_nocode_wanted; | 6315 | nocode_wanted = saved_nocode_wanted; |
| 6314 | gjmp_addr(c); | 6316 | gjmp_addr(c); |
| 6315 | gsym(a); | 6317 | gsym(a); |
| @@ -6327,7 +6329,7 @@ static void block(int *bsym, int *csym, int is_expr) · 11 unmodified lines | |||
| 6327 | d = ind; | 6329 | d = ind; |
| 6328 | vla_sp_restore(); | 6330 | vla_sp_restore(); |
| 6329 | saved_nocode_wanted = nocode_wanted; | 6331 | saved_nocode_wanted = nocode_wanted; |
| 6330 | block(&a, &b, 0); | 6332 | block(&a, current_cleanups, &b, current_cleanups, 0); |
| 6331 | skip(TOK_WHILE); | 6333 | skip(TOK_WHILE); |
| 6332 | skip('('); | 6334 | skip('('); |
| 6333 | gsym(b); | 6335 | gsym(b); |
| @@ -6355,7 +6357,7 @@ static void block(int *bsym, int *csym, int is_expr) · 21 unmodified lines | |||
| 6355 | sw.p = NULL; sw.n = 0; sw.def_sym = 0; | 6357 | sw.p = NULL; sw.n = 0; sw.def_sym = 0; |
| 6356 | saved = cur_switch; | 6358 | saved = cur_switch; |
| 6357 | cur_switch = &sw; | 6359 | cur_switch = &sw; |
| 6358 | block(&a, csym, 0); | 6360 | block(&a, current_cleanups, csym, ccl, 0); |
| 6359 | nocode_wanted = saved_nocode_wanted; | 6361 | nocode_wanted = saved_nocode_wanted; |
| 6360 | a = gjmp(a); /* add implicit break */ | 6362 | a = gjmp(a); /* add implicit break */ |
| 6361 | /* case lookup */ | 6363 | /* case lookup */ |
| @@ -6477,7 +6479,7 @@ static void block(int *bsym, int *csym, int is_expr) · 115 unmodified lines | |||
| 6477 | } else { | 6479 | } else { |
| 6478 | if (is_expr) | 6480 | if (is_expr) |
| 6479 | vpop(); | 6481 | vpop(); |
| 6480 | block(bsym, csym, is_expr); | 6482 | block(bsym, bcl, csym, ccl, is_expr); |
| 6481 | } | 6483 | } |
| 6482 | } else { | 6484 | } else { |
| 6483 | /* expression case */ | 6485 | /* expression case */ |
| @@ -7357,7 +7359,7 @@ static void gen_function(Sym *sym) · 873 unmodified lines | |||
| 7357 | reset_local_scope(); | 7359 | reset_local_scope(); |
| 7358 | rsym = 0; | 7360 | rsym = 0; |
| 7359 | clear_temp_local_var_list(); | 7361 | clear_temp_local_var_list(); |
| 7360 | block(NULL, NULL, 0); | 7362 | block(NULL, NULL, NULL, NULL, 0); |
| 7361 | if (!(nocode_wanted & 0x20000000) | 7363 | if (!(nocode_wanted & 0x20000000) |
| 7362 | && ((func_vt.t & VT_BTYPE) == VT_INT) | 7364 | && ((func_vt.t & VT_BTYPE) == VT_INT) |
| 7363 | && !strcmp (funcname, "main")) | 7365 | && !strcmp (funcname, "main")) |