Unified · Split
| @@ -4291,14 +4291,28 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 4290 unmodified lines | |||
| 4291 | next(); | 4291 | next(); |
| 4292 | skip(';'); | 4292 | skip(';'); |
| 4293 | } else if (tok == TOK_FOR) { | 4293 | } else if (tok == TOK_FOR) { |
| 4294 | int e; | 4294 | int e, c99_for_decl = 0; |
| 4295 | next(); | 4295 | next(); |
| 4296 | skip('('); | 4296 | skip('('); |
| 4297 | if (tok != ';') { | 4297 | if (tok != ';') { |
| 4298 | gexpr(); | 4298 | if (tok < TOK_UIDENT) { |
| 4299 | vpop(); | 4299 | // handle C99 for loop construct |
| 4300 | c99_for_decl = 1; | ||
| 4301 | |||
| 4302 | /* record local declaration stack position */ | ||
| 4303 | s = local_stack; | ||
| 4304 | |||
| 4305 | decl(VT_LOCAL); | ||
| 4306 | if (is_expr) | ||
| 4307 | vpop(); | ||
| 4308 | } else { | ||
| 4309 | gexpr(); | ||
| 4310 | vpop(); | ||
| 4311 | skip(';'); | ||
| 4312 | } | ||
| 4313 | } else { | ||
| 4314 | skip(';'); | ||
| 4300 | } | 4315 | } |
| 4301 | skip(';'); | ||
| 4302 | d = ind; | 4316 | d = ind; |
| 4303 | c = ind; | 4317 | c = ind; |
| 4304 | a = 0; | 4318 | a = 0; |
| @@ -4321,6 +4335,25 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 16 unmodified lines | |||
| 4321 | gjmp_addr(c); | 4335 | gjmp_addr(c); |
| 4322 | gsym(a); | 4336 | gsym(a); |
| 4323 | gsym_addr(b, c); | 4337 | gsym_addr(b, c); |
| 4338 | |||
| 4339 | if (c99_for_decl) { | ||
| 4340 | /* pop locally defined symbols */ | ||
| 4341 | if(is_expr) { | ||
| 4342 | /* XXX: this solution makes only valgrind happy... | ||
| 4343 | triggered by gcc.c-torture/execute/20000917-1.c */ | ||
| 4344 | Sym *p; | ||
| 4345 | switch(vtop->type.t & VT_BTYPE) { | ||
| 4346 | case VT_PTR: | ||
| 4347 | case VT_STRUCT: | ||
| 4348 | case VT_ENUM: | ||
| 4349 | case VT_FUNC: | ||
| 4350 | for(p=vtop->type.ref;p;p=p->prev) | ||
| 4351 | if(p->prev==s) | ||
| 4352 | error("unsupported expression type"); | ||
| 4353 | } | ||
| 4354 | } | ||
| 4355 | sym_pop(&local_stack, s); | ||
| 4356 | } | ||
| 4324 | } else | 4357 | } else |
| 4325 | if (tok == TOK_DO) { | 4358 | if (tok == TOK_DO) { |
| 4326 | next(); | 4359 | next(); |