History

C23: Implement declaration after label

Only allow declaration after label if it is inside '{...}'

herman ten brugge committed 2 years ago

Commit 7f0a28f1 parent 7d1bbc81 file · +12 −9Browse files

Unified · Split

tccgen.c+12−9
@@ -139,7 +139,7 @@ static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td); · 138 unmodified lines
139static void parse_expr_type(CType *type);139static void parse_expr_type(CType *type);
140static void init_putv(init_params *p, CType *type, unsigned long c);140static void init_putv(init_params *p, CType *type, unsigned long c);
141static void decl_initializer(init_params *p, CType *type, unsigned long c, int flags);141static void decl_initializer(init_params *p, CType *type, unsigned long c, int flags);
142static void block(int is_expr);142static void block(int is_expr, int allow_decl);
143static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, int scope);143static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, int scope);
144static int decl(int l);144static int decl(int l);
145static void expr_eq(void);145static void expr_eq(void);
@@ -5566,7 +5566,7 @@ ST_FUNC void unary(void) · 5420 unmodified lines
5566 as statement expressions can't ever be entered from the5566 as statement expressions can't ever be entered from the
5567 outside, so any reactivation of code emission (from labels5567 outside, so any reactivation of code emission (from labels
5568 or loop heads) can be disabled again after the end of it. */5568 or loop heads) can be disabled again after the end of it. */
5569 block(1);5569 block(1, 0);
5570 /* If the statement expr can be entered, then we retain the current5570 /* If the statement expr can be entered, then we retain the current
5571 nocode_wanted state (from e.g. a 'return 0;' in the stmt-expr).5571 nocode_wanted state (from e.g. a 'return 0;' in the stmt-expr).
5572 If it can't be entered then the state is that from before the5572 If it can't be entered then the state is that from before the
@@ -6908,7 +6908,7 @@ static void lblock(int *bsym, int *csym) · 1335 unmodified lines
6908 loop_scope = co;6908 loop_scope = co;
6909 }6909 }
6910 co->bsym = bsym;6910 co->bsym = bsym;
6911 block(0);6911 block(0, 0);
6912 co->bsym = b;6912 co->bsym = b;
6913 if (csym) {6913 if (csym) {
6914 co->csym = c;6914 co->csym = c;
@@ -6916,7 +6916,7 @@ static void lblock(int *bsym, int *csym) · 1 unmodified line
6916 }6916 }
6917}6917}
6918 6918
6919static void block(int is_expr)6919static void block(int is_expr, int allow_decl)
6920{6920{
6921 int a, b, c, d, e, t;6921 int a, b, c, d, e, t;
6922 struct scope o;6922 struct scope o;
@@ -6945,12 +6945,12 @@ again: · 22 unmodified lines
6945 gexpr();6945 gexpr();
6946 skip(')');6946 skip(')');
6947 a = gvtst(1, 0);6947 a = gvtst(1, 0);
6948 block(0);6948 block(0, 0);
6949 if (tok == TOK_ELSE) {6949 if (tok == TOK_ELSE) {
6950 d = gjmp(0);6950 d = gjmp(0);
6951 gsym(a);6951 gsym(a);
6952 next();6952 next();
6953 block(0);6953 block(0, 0);
6954 gsym(d); /* patch else jmp */6954 gsym(d); /* patch else jmp */
6955 } else {6955 } else {
6956 gsym(a);6956 gsym(a);
@@ -6993,7 +6993,7 @@ again: · 36 unmodified lines
6993 if (tok != '}') {6993 if (tok != '}') {
6994 if (is_expr)6994 if (is_expr)
6995 vpop();6995 vpop();
6996 block(is_expr);6996 block(is_expr, 1);
6997 }6997 }
6998 }6998 }
6999 6999
@@ -7253,6 +7253,9 @@ again: · 253 unmodified lines
7253 if (debug_modes)7253 if (debug_modes)
7254 tcc_tcov_reset_ind(tcc_state);7254 tcc_tcov_reset_ind(tcc_state);
7255 vla_restore(cur_scope->vla.loc);7255 vla_restore(cur_scope->vla.loc);
7256 /* c23 declaration after label */
7257 if (allow_decl && tok != ';')
7258 decl(VT_LOCAL);
7256 if (tok != '}')7259 if (tok != '}')
7257 goto again;7260 goto again;
7258 /* we accept this, but it is a mistake */7261 /* we accept this, but it is a mistake */
@@ -7266,7 +7269,7 @@ again: · 7 unmodified lines
7266 if (is_expr) {7269 if (is_expr) {
7267 vpop();7270 vpop();
7268 gexpr();7271 gexpr();
7269 } else if (!decl(VT_JMP)) {7272 } else {
7270 gexpr();7273 gexpr();
7271 vpop();7274 vpop();
7272 }7275 }
@@ -8313,7 +8316,7 @@ static void gen_function(Sym *sym) · 1040 unmodified lines
8313 rsym = 0;8316 rsym = 0;
8314 clear_temp_local_var_list();8317 clear_temp_local_var_list();
8315 func_vla_arg(sym);8318 func_vla_arg(sym);
8316 block(0);8319 block(0, 0);
8317 gsym(rsym);8320 gsym(rsym);
8318 8321
8319 nocode_wanted = 0;8322 nocode_wanted = 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t