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
14781478 { offsetof(TCCState, nocommon), FD_INVERT, "common" },
14791479 { offsetof(TCCState, leading_underscore), 0, "leading-underscore" },
14801480 { offsetof(TCCState, ms_extensions), 0, "ms-extensions" },
1481+ { offsetof(TCCState, old_struct_init_code), 0, "old-struct-init-code" },
14811482 };
14821483
14831484 /* set/reset a flag */
tcc.h+2−0
@@ -603,6 +603,8 @@ struct TCCState { · 602 unmodified lines
603603 int char_is_unsigned;
604604 int leading_underscore;
605605 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 */
606608
607609 /* warning switches */
608610 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
55755575 struct/union init */
55765576 /* XXX: union needs only one init */
55775577
5578+ int par_count = 0;
55785579 if (tok == '(') {
55795580 AttributeDef ad1;
55805581 CType type1;
55815582 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 != '(') {
55835604 if (!parse_btype(&type1, &ad1))
55845605 expect("cast");
55855606 type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);
5586−#if 0
5607+ #if 0
55875608 if (!is_assignable_types(type, &type1))
55885609 tcc_error("invalid type for cast");
5589−#endif
5610+ #endif
55905611 skip(')');
5591− } else
5612+ } else
55925613 unget_tok(tok);
5614+ }
55935615 }
5616+
55945617 no_oblock = 1;
55955618 if (first || tok == '{') {
55965619 skip('{');
@@ -5663,6 +5686,10 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 66 unmodified lines
56635686 }
56645687 if (!no_oblock)
56655688 skip('}');
5689+ while (par_count) {
5690+ skip(')');
5691+ par_count--;
5692+ }
56665693 } else if (tok == '{') {
56675694 next();
56685695 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