mirror of
https://github.com/mirror/tinycc.git
synced 2025-02-26 08:00:09 +08:00
Disable C99 VLA when alloca is unavailable.
* Disable C99 VLA detection when alloca is unavailable and protect the new reference to TOK_alloca in decl_initializer in order to compile and run for architecture without working alloca. Not all code of C99 VLA is commented as it would required many ifdef stanza. Just the detection is commented so that VT_VLA is never set any type and the C99 VLA code is compiled but never called. However vpush_global_sym(&func_old_type, TOK_alloca) in decl_initializer needs to be protected by an ifdef stanza as well because it uses TOK_alloca. * include alloca and C99 VLA tests according to availability of TOK_alloca instead of relying on the current architecture
This commit is contained in:
parent
af26ac56bf
commit
e3e5d4ad7a
8
tccgen.c
8
tccgen.c
@ -3162,17 +3162,21 @@ static void post_type(CType *type, AttributeDef *ad)
|
||||
n = -1;
|
||||
if (tok != ']') {
|
||||
gexpr();
|
||||
#ifdef TOK_alloca
|
||||
if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
|
||||
#endif
|
||||
n = vtop->c.i;
|
||||
last_vtop = vtop;
|
||||
if (n < 0)
|
||||
error("invalid array size");
|
||||
#ifdef TOK_alloca
|
||||
} else {
|
||||
if (!is_integer_btype(vtop->type.t & VT_BTYPE))
|
||||
error("size of variable length array should be an integer");
|
||||
type->t |= VT_VLA;
|
||||
last_vtop = vtop;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
skip(']');
|
||||
/* parse next post type */
|
||||
@ -4864,7 +4868,11 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
|
||||
int a;
|
||||
CValue retcval;
|
||||
|
||||
/* No need to coment all the block as it will never be called without
|
||||
TOK_alloca defined (See ifdef TOK_alloca stanza in post_type */
|
||||
#ifdef TOK_alloca
|
||||
vpush_global_sym(&func_old_type, TOK_alloca);
|
||||
#endif
|
||||
vla_runtime_type_size(type, &a);
|
||||
gfunc_call(1);
|
||||
|
||||
|
@ -2010,7 +2010,7 @@ void old_style_function(void)
|
||||
|
||||
void alloca_test()
|
||||
{
|
||||
#if defined __i386__ || defined __x86_64__
|
||||
#ifdef TOK_alloca
|
||||
char *p = alloca(16);
|
||||
strcpy(p,"123456789012345");
|
||||
printf("alloca: p is %s\n", p);
|
||||
@ -2022,7 +2022,7 @@ void alloca_test()
|
||||
|
||||
void c99_vla_test(int size1, int size2)
|
||||
{
|
||||
#if defined __i386__ || defined __x86_64__
|
||||
#ifdef TOK_alloca
|
||||
int tab1[size1 * size2][2], tab2[10][2];
|
||||
void *tab1_ptr, *tab2_ptr;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user