The C standard has required this since at least C99. A new scope should also be created for ifs, but that's currently breaking tests2/122_vla_reuse.
Unified · Split
| @@ -6832,6 +6832,7 @@ again: · 6831 unmodified lines | ||
| 6832 | 6832 | tcc_tcov_check_line (tcc_state, 0), tcc_tcov_block_begin (tcc_state); |
| 6833 | 6833 | |
| 6834 | 6834 | if (t == TOK_IF) { |
| 6835 | + //new_scope(&o); //?? breaks tests2.122 | |
| 6835 | 6836 | skip('('); |
| 6836 | 6837 | gexpr(); |
| 6837 | 6838 | skip(')'); |
| @@ -6846,8 +6847,10 @@ again: · 8 unmodified lines | ||
| 6846 | 6847 | } else { |
| 6847 | 6848 | gsym(a); |
| 6848 | 6849 | } |
| 6850 | + //prev_scope(&o,0); //?? breaks tests2.122 | |
| 6849 | 6851 | |
| 6850 | 6852 | } else if (t == TOK_WHILE) { |
| 6853 | + new_scope(&o); | |
| 6851 | 6854 | d = gind(); |
| 6852 | 6855 | skip('('); |
| 6853 | 6856 | gexpr(); |
| @@ -6858,7 +6861,7 @@ again: · 4 unmodified lines | ||
| 6858 | 6861 | gjmp_addr(d); |
| 6859 | 6862 | gsym_addr(b, d); |
| 6860 | 6863 | gsym(a); |
| 6861 | − | |
| 6864 | + prev_scope(&o,0); | |
| 6862 | 6865 | } else if (t == '{') { |
| 6863 | 6866 | new_scope(&o); |
| 6864 | 6867 | |
| @@ -6970,6 +6973,7 @@ again: · 105 unmodified lines | ||
| 6970 | 6973 | prev_scope(&o, 0); |
| 6971 | 6974 | |
| 6972 | 6975 | } else if (t == TOK_DO) { |
| 6976 | + new_scope(&o); | |
| 6973 | 6977 | a = b = 0; |
| 6974 | 6978 | d = gind(); |
| 6975 | 6979 | lblock(&a, &b); |
| @@ -6979,6 +6983,7 @@ again: · 3 unmodified lines | ||
| 6979 | 6983 | gexpr(); |
| 6980 | 6984 | skip(')'); |
| 6981 | 6985 | skip(';'); |
| 6986 | + prev_scope(&o,0); | |
| 6982 | 6987 | c = gvtst(0, 0); |
| 6983 | 6988 | gsym_addr(c, d); |
| 6984 | 6989 | gsym(a); |
| @@ -6986,6 +6991,7 @@ again: · 1 unmodified line | ||
| 6986 | 6991 | } else if (t == TOK_SWITCH) { |
| 6987 | 6992 | struct switch_t *sw; |
| 6988 | 6993 | |
| 6994 | + new_scope(&o); | |
| 6989 | 6995 | sw = tcc_mallocz(sizeof *sw); |
| 6990 | 6996 | sw->bsym = &a; |
| 6991 | 6997 | sw->scope = cur_scope; |
| @@ -7031,6 +7037,7 @@ again: · 39 unmodified lines | ||
| 7031 | 7037 | dynarray_reset(&sw->p, &sw->n); |
| 7032 | 7038 | cur_switch = sw->prev; |
| 7033 | 7039 | tcc_free(sw); |
| 7040 | + prev_scope(&o,0); | |
| 7034 | 7041 | |
| 7035 | 7042 | } else if (t == TOK_CASE) { |
| 7036 | 7043 | struct case_t *cr = tcc_malloc(sizeof(struct case_t)); |
| @@ -0,0 +1,45 @@ | ||
| 1 | +#include <stdio.h> | |
| 2 | +enum{ in = 0}; | |
| 3 | +#define myassert(X) do{ if(!X) printf("%d: assertion failed\n", __LINE__); }while(0) | |
| 4 | +int main(){ | |
| 5 | + #if 0 | |
| 6 | + { | |
| 7 | + myassert(!in); | |
| 8 | + if(sizeof(enum{in=1})) myassert(in); | |
| 9 | + myassert(!in); //OOPS | |
| 10 | + } | |
| 11 | + #endif | |
| 12 | + { | |
| 13 | + myassert(!in); | |
| 14 | + switch(sizeof(enum{in=1})) { default: myassert(in); } | |
| 15 | + myassert(!in); //OOPS | |
| 16 | + } | |
| 17 | + { | |
| 18 | + myassert(!in); | |
| 19 | + while(sizeof(enum{in=1})) { myassert(in); break; } | |
| 20 | + myassert(!in); //OOPS | |
| 21 | + } | |
| 22 | + { | |
| 23 | + myassert(!in); | |
| 24 | + do{ myassert(!in);}while(0*sizeof(enum{in=1})); | |
| 25 | + myassert(!in); //OOPS | |
| 26 | + } | |
| 27 | + | |
| 28 | + { | |
| 29 | + myassert(!in); | |
| 30 | + for(sizeof(enum{in=1});;){ myassert(in); break; } | |
| 31 | + myassert(!in); //OK | |
| 32 | + } | |
| 33 | + { | |
| 34 | + myassert(!in); | |
| 35 | + for(;;sizeof(enum{in=1})){ myassert(in); break; } | |
| 36 | + myassert(!in); //OK | |
| 37 | + } | |
| 38 | + { | |
| 39 | + myassert(!in); | |
| 40 | + for(;sizeof(enum{in=1});){ myassert(in); break; } | |
| 41 | + myassert(!in); //OK | |
| 42 | + } | |
| 43 | + | |
| 44 | +} | |
| 45 | + | |
Empty file added.