History

option to use an old algorithm of the array in struct initialization

This is for a case when no '{' is used in the initialization code. An option name is -fold-struct-init-code. A linux 2.4.26 can't find initrd when compiled with a new algorithm.

seyko committed 11 years ago

Commit 5c9dde71 parent 92efee63 files · +34 −4Browse files

Unified · Split

3 files
  1. libtcc.c +1 −0
  2. tcc.h +2 −0
  3. tccgen.c +31 −4
libtcc.c+1−0
@@ -1478,6 +1478,7 @@ static const FlagDef flag_defs[] = { · 1477 unmodified lines
1478 { offsetof(TCCState, nocommon), FD_INVERT, "common" },1478 { offsetof(TCCState, nocommon), FD_INVERT, "common" },
1479 { offsetof(TCCState, leading_underscore), 0, "leading-underscore" },1479 { offsetof(TCCState, leading_underscore), 0, "leading-underscore" },
1480 { offsetof(TCCState, ms_extensions), 0, "ms-extensions" },1480 { offsetof(TCCState, ms_extensions), 0, "ms-extensions" },
1481 { offsetof(TCCState, old_struct_init_code), 0, "old-struct-init-code" },
1481};1482};
1482 1483
1483/* set/reset a flag */1484/* set/reset a flag */
tcc.h+2−0
@@ -603,6 +603,8 @@ struct TCCState { · 602 unmodified lines
603 int char_is_unsigned;603 int char_is_unsigned;
604 int leading_underscore;604 int leading_underscore;
605 int ms_extensions; /* allow nested named struct w/o identifier behave like unnamed */605 int ms_extensions; /* allow nested named struct w/o identifier behave like unnamed */
606 int old_struct_init_code; /* use old algorithm to init array in struct when there is no '{' used.
607 Liuux 2.4.26 can't find initrd when compiled with a new algorithm */
606 608
607 /* warning switches */609 /* warning switches */
608 int warn_write_strings;610 int warn_write_strings;
tccgen.c+31−4
@@ -5575,22 +5575,45 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 5574 unmodified lines
5575 struct/union init */5575 struct/union init */
5576 /* XXX: union needs only one init */5576 /* XXX: union needs only one init */
5577 5577
5578 int par_count = 0;
5578 if (tok == '(') {5579 if (tok == '(') {
5579 AttributeDef ad1;5580 AttributeDef ad1;
5580 CType type1;5581 CType type1;
5581 next();5582 next();
5582 if (tok != '(') {5583 if (tcc_state->old_struct_init_code) {
5584 /* an old version of struct initialization.
5585 It have a problems. But with a new version
5586 linux 2.4.26 can't load ramdisk.
5587 */
5588 while (tok == '(') {
5589 par_count++;
5590 next();
5591 }
5592 if (!parse_btype(&type1, &ad1))
5593 expect("cast");
5594 type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);
5595 #if 0
5596 if (!is_assignable_types(type, &type1))
5597 tcc_error("invalid type for cast");
5598 #endif
5599 skip(')');
5600 }
5601 else
5602 {
5603 if (tok != '(') {
5583 if (!parse_btype(&type1, &ad1))5604 if (!parse_btype(&type1, &ad1))
5584 expect("cast");5605 expect("cast");
5585 type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);5606 type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);
5586#if 05607 #if 0
5587 if (!is_assignable_types(type, &type1))5608 if (!is_assignable_types(type, &type1))
5588 tcc_error("invalid type for cast");5609 tcc_error("invalid type for cast");
5589#endif5610 #endif
5590 skip(')');5611 skip(')');
5591 } else5612 } else
5592 unget_tok(tok);5613 unget_tok(tok);
5614 }
5593 }5615 }
5616
5594 no_oblock = 1;5617 no_oblock = 1;
5595 if (first || tok == '{') {5618 if (first || tok == '{') {
5596 skip('{');5619 skip('{');
@@ -5663,6 +5686,10 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 66 unmodified lines
5663 }5686 }
5664 if (!no_oblock)5687 if (!no_oblock)
5665 skip('}');5688 skip('}');
5689 while (par_count) {
5690 skip(')');
5691 par_count--;
5692 }
5666 } else if (tok == '{') {5693 } else if (tok == '{') {
5667 next();5694 next();
5668 decl_initializer(type, sec, c, first, size_only);5695 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