History

A right fix for the array in struct initialization w/o '{' Parse a type if there is only one '(' before a type token. Otherwise a recursion will perform a job.

seyko committed 11 years ago

Commit bd531ec1 parent 367bb6f4 files · +116 −21Browse files

Showing the changes to tccgen.c (1 of 4 files). Show all

Unified · Split

tccgen.c+9−20
@@ -5546,33 +5546,26 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 5545 unmodified lines
5546 s->c = array_length;5546 s->c = array_length;
5547 } else if ((type->t & VT_BTYPE) == VT_STRUCT &&5547 } else if ((type->t & VT_BTYPE) == VT_STRUCT &&
5548 (sec || !first || tok == '{')) {5548 (sec || !first || tok == '{')) {
5549 int par_count;
5550 5549
5551 /* NOTE: the previous test is a specific case for automatic5550 /* NOTE: the previous test is a specific case for automatic
5552 struct/union init */5551 struct/union init */
5553 /* XXX: union needs only one init */5552 /* XXX: union needs only one init */
5554 5553
5555 /* XXX: this test is incorrect for local initializers
5556 beginning with ( without {. It would be much more difficult
5557 to do it correctly (ideally, the expression parser should
5558 be used in all cases) */
5559 par_count = 0;
5560 if (tok == '(') {5554 if (tok == '(') {
5561 AttributeDef ad1;5555 AttributeDef ad1;
5562 CType type1;5556 CType type1;
5563 next();5557 next();
5564 while (tok == '(') {5558 if (tok != '(') {
5565 par_count++;5559 if (!parse_btype(&type1, &ad1))
5566 next();5560 expect("cast");
5567 }5561 type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);
5568 if (!parse_btype(&type1, &ad1))
5569 expect("cast");
5570 type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);
5571#if 05562#if 0
5572 if (!is_assignable_types(type, &type1))5563 if (!is_assignable_types(type, &type1))
5573 tcc_error("invalid type for cast");5564 tcc_error("invalid type for cast");
5574#endif5565#endif
5575 skip(')');5566 skip(')');
5567 } else
5568 unget_tok(tok);
5576 }5569 }
5577 no_oblock = 1;5570 no_oblock = 1;
5578 if (first || tok == '{') {5571 if (first || tok == '{') {
@@ -5646,10 +5639,6 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 67 unmodified lines
5646 }5639 }
5647 if (!no_oblock)5640 if (!no_oblock)
5648 skip('}');5641 skip('}');
5649 while (par_count) {
5650 skip(')');
5651 par_count--;
5652 }
5653 } else if (tok == '{') {5642 } else if (tok == '{') {
5654 next();5643 next();
5655 decl_initializer(type, sec, c, first, size_only);5644 decl_initializer(type, sec, c, first, size_only);

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