Unified · Split
| @@ -76,6 +76,7 @@ static void parse_expr_type(CType *type); · 75 unmodified lines | ||
| 76 | 76 | static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only); |
| 77 | 77 | static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg, int is_expr); |
| 78 | 78 | static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, char *asm_label, int scope); |
| 79 | +static int decl0(int l, int is_for_loop_init); | |
| 79 | 80 | static void expr_eq(void); |
| 80 | 81 | static void unary_type(CType *type); |
| 81 | 82 | static int is_compatible_parameter_types(CType *type1, CType *type2); |
| @@ -4379,8 +4380,12 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 4297 unmodified lines | ||
| 4379 | 4380 | next(); |
| 4380 | 4381 | skip('('); |
| 4381 | 4382 | if (tok != ';') { |
| 4382 | − gexpr(); | |
| 4383 | − vpop(); | |
| 4383 | + /* c99 for-loop init decl? */ | |
| 4384 | + if (!decl0(VT_LOCAL, 1)) { | |
| 4385 | + /* no, regular for-loop init expr */ | |
| 4386 | + gexpr(); | |
| 4387 | + vpop(); | |
| 4388 | + } | |
| 4384 | 4389 | } |
| 4385 | 4390 | skip(';'); |
| 4386 | 4391 | d = ind; |
| @@ -5406,7 +5411,7 @@ ST_FUNC void gen_inline_functions(void) · 1019 unmodified lines | ||
| 5406 | 5411 | } |
| 5407 | 5412 | |
| 5408 | 5413 | /* 'l' is VT_LOCAL or VT_CONST to define default storage type */ |
| 5409 | −ST_FUNC void decl(int l) | |
| 5414 | +static int decl0(int l, int is_for_loop_init) | |
| 5410 | 5415 | { |
| 5411 | 5416 | int v, has_init, r; |
| 5412 | 5417 | CType type, btype; |
| @@ -5415,6 +5420,8 @@ ST_FUNC void decl(int l) · 2 unmodified lines | ||
| 5415 | 5420 | |
| 5416 | 5421 | while (1) { |
| 5417 | 5422 | if (!parse_btype(&btype, &ad)) { |
| 5423 | + if (is_for_loop_init) | |
| 5424 | + return 0; | |
| 5418 | 5425 | /* skip redundant ';' */ |
| 5419 | 5426 | /* XXX: find more elegant solution */ |
| 5420 | 5427 | if (tok == ';') { |
| @@ -5629,6 +5636,8 @@ ST_FUNC void decl(int l) · 208 unmodified lines | ||
| 5629 | 5636 | } |
| 5630 | 5637 | } |
| 5631 | 5638 | if (tok != ',') { |
| 5639 | + if (is_for_loop_init) | |
| 5640 | + return 1; | |
| 5632 | 5641 | skip(';'); |
| 5633 | 5642 | break; |
| 5634 | 5643 | } |
| @@ -5636,4 +5645,10 @@ ST_FUNC void decl(int l) · 1 unmodified line | ||
| 5636 | 5645 | } |
| 5637 | 5646 | } |
| 5638 | 5647 | } |
| 5648 | + return 0; | |
| 5649 | +} | |
| 5650 | + | |
| 5651 | +ST_FUNC void decl(int l) | |
| 5652 | +{ | |
| 5653 | + decl0(l, 0); | |
| 5639 | 5654 | } |