mirror of
https://github.com/mirror/tinycc.git
synced 2024-12-28 04:00:06 +08:00
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.
This commit is contained in:
parent
92efee6e52
commit
5c9dde7255
1
libtcc.c
1
libtcc.c
@ -1478,6 +1478,7 @@ static const FlagDef flag_defs[] = {
|
|||||||
{ offsetof(TCCState, nocommon), FD_INVERT, "common" },
|
{ offsetof(TCCState, nocommon), FD_INVERT, "common" },
|
||||||
{ offsetof(TCCState, leading_underscore), 0, "leading-underscore" },
|
{ offsetof(TCCState, leading_underscore), 0, "leading-underscore" },
|
||||||
{ offsetof(TCCState, ms_extensions), 0, "ms-extensions" },
|
{ offsetof(TCCState, ms_extensions), 0, "ms-extensions" },
|
||||||
|
{ offsetof(TCCState, old_struct_init_code), 0, "old-struct-init-code" },
|
||||||
};
|
};
|
||||||
|
|
||||||
/* set/reset a flag */
|
/* set/reset a flag */
|
||||||
|
2
tcc.h
2
tcc.h
@ -603,6 +603,8 @@ struct TCCState {
|
|||||||
int char_is_unsigned;
|
int char_is_unsigned;
|
||||||
int leading_underscore;
|
int leading_underscore;
|
||||||
int ms_extensions; /* allow nested named struct w/o identifier behave like unnamed */
|
int ms_extensions; /* allow nested named struct w/o identifier behave like unnamed */
|
||||||
|
int old_struct_init_code; /* use old algorithm to init array in struct when there is no '{' used.
|
||||||
|
Liuux 2.4.26 can't find initrd when compiled with a new algorithm */
|
||||||
|
|
||||||
/* warning switches */
|
/* warning switches */
|
||||||
int warn_write_strings;
|
int warn_write_strings;
|
||||||
|
35
tccgen.c
35
tccgen.c
@ -5575,22 +5575,45 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
|
|||||||
struct/union init */
|
struct/union init */
|
||||||
/* XXX: union needs only one init */
|
/* XXX: union needs only one init */
|
||||||
|
|
||||||
|
int par_count = 0;
|
||||||
if (tok == '(') {
|
if (tok == '(') {
|
||||||
AttributeDef ad1;
|
AttributeDef ad1;
|
||||||
CType type1;
|
CType type1;
|
||||||
next();
|
next();
|
||||||
if (tok != '(') {
|
if (tcc_state->old_struct_init_code) {
|
||||||
|
/* an old version of struct initialization.
|
||||||
|
It have a problems. But with a new version
|
||||||
|
linux 2.4.26 can't load ramdisk.
|
||||||
|
*/
|
||||||
|
while (tok == '(') {
|
||||||
|
par_count++;
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
if (!parse_btype(&type1, &ad1))
|
||||||
|
expect("cast");
|
||||||
|
type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);
|
||||||
|
#if 0
|
||||||
|
if (!is_assignable_types(type, &type1))
|
||||||
|
tcc_error("invalid type for cast");
|
||||||
|
#endif
|
||||||
|
skip(')');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (tok != '(') {
|
||||||
if (!parse_btype(&type1, &ad1))
|
if (!parse_btype(&type1, &ad1))
|
||||||
expect("cast");
|
expect("cast");
|
||||||
type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);
|
type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);
|
||||||
#if 0
|
#if 0
|
||||||
if (!is_assignable_types(type, &type1))
|
if (!is_assignable_types(type, &type1))
|
||||||
tcc_error("invalid type for cast");
|
tcc_error("invalid type for cast");
|
||||||
#endif
|
#endif
|
||||||
skip(')');
|
skip(')');
|
||||||
} else
|
} else
|
||||||
unget_tok(tok);
|
unget_tok(tok);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
no_oblock = 1;
|
no_oblock = 1;
|
||||||
if (first || tok == '{') {
|
if (first || tok == '{') {
|
||||||
skip('{');
|
skip('{');
|
||||||
@ -5663,6 +5686,10 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
|
|||||||
}
|
}
|
||||||
if (!no_oblock)
|
if (!no_oblock)
|
||||||
skip('}');
|
skip('}');
|
||||||
|
while (par_count) {
|
||||||
|
skip(')');
|
||||||
|
par_count--;
|
||||||
|
}
|
||||||
} else if (tok == '{') {
|
} else if (tok == '{') {
|
||||||
next();
|
next();
|
||||||
decl_initializer(type, sec, c, first, size_only);
|
decl_initializer(type, sec, c, first, size_only);
|
||||||
|
Loading…
Reference in New Issue
Block a user