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
139139 static void parse_expr_type(CType *type);
140140 static void init_putv(init_params *p, CType *type, unsigned long c);
141141 static void decl_initializer(init_params *p, CType *type, unsigned long c, int flags);
142−static void block(int is_expr);
142+static void block(int is_expr, int allow_decl);
143143 static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, int scope);
144144 static int decl(int l);
145145 static void expr_eq(void);
@@ -5566,7 +5566,7 @@ ST_FUNC void unary(void) · 5420 unmodified lines
55665566 as statement expressions can't ever be entered from the
55675567 outside, so any reactivation of code emission (from labels
55685568 or loop heads) can be disabled again after the end of it. */
5569− block(1);
5569+ block(1, 0);
55705570 /* If the statement expr can be entered, then we retain the current
55715571 nocode_wanted state (from e.g. a 'return 0;' in the stmt-expr).
55725572 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
69086908 loop_scope = co;
69096909 }
69106910 co->bsym = bsym;
6911− block(0);
6911+ block(0, 0);
69126912 co->bsym = b;
69136913 if (csym) {
69146914 co->csym = c;
@@ -6916,7 +6916,7 @@ static void lblock(int *bsym, int *csym) · 1 unmodified line
69166916 }
69176917 }
69186918
6919−static void block(int is_expr)
6919+static void block(int is_expr, int allow_decl)
69206920 {
69216921 int a, b, c, d, e, t;
69226922 struct scope o;
@@ -6945,12 +6945,12 @@ again: · 22 unmodified lines
69456945 gexpr();
69466946 skip(')');
69476947 a = gvtst(1, 0);
6948− block(0);
6948+ block(0, 0);
69496949 if (tok == TOK_ELSE) {
69506950 d = gjmp(0);
69516951 gsym(a);
69526952 next();
6953− block(0);
6953+ block(0, 0);
69546954 gsym(d); /* patch else jmp */
69556955 } else {
69566956 gsym(a);
@@ -6993,7 +6993,7 @@ again: · 36 unmodified lines
69936993 if (tok != '}') {
69946994 if (is_expr)
69956995 vpop();
6996− block(is_expr);
6996+ block(is_expr, 1);
69976997 }
69986998 }
69996999
@@ -7253,6 +7253,9 @@ again: · 253 unmodified lines
72537253 if (debug_modes)
72547254 tcc_tcov_reset_ind(tcc_state);
72557255 vla_restore(cur_scope->vla.loc);
7256+ /* c23 declaration after label */
7257+ if (allow_decl && tok != ';')
7258+ decl(VT_LOCAL);
72567259 if (tok != '}')
72577260 goto again;
72587261 /* we accept this, but it is a mistake */
@@ -7266,7 +7269,7 @@ again: · 7 unmodified lines
72667269 if (is_expr) {
72677270 vpop();
72687271 gexpr();
7269− } else if (!decl(VT_JMP)) {
7272+ } else {
72707273 gexpr();
72717274 vpop();
72727275 }
@@ -8313,7 +8316,7 @@ static void gen_function(Sym *sym) · 1040 unmodified lines
83138316 rsym = 0;
83148317 clear_temp_local_var_list();
83158318 func_vla_arg(sym);
8316− block(0);
8319+ block(0, 0);
83178320 gsym(rsym);
83188321
83198322 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