History

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

Thomas Preud'homme committed 15 years ago

Commit e3e5d4a1 parent af26ac52 files · +10 −2Browse files

Unified · Split

2 files
  1. tccgen.c +8 −0
  2. tests/tcctest.c +2 −2
tccgen.c+8−0
@@ -3162,17 +3162,21 @@ static void post_type(CType *type, AttributeDef *ad) · 3161 unmodified lines
31623162 n = -1;
31633163 if (tok != ']') {
31643164 gexpr();
3165+#ifdef TOK_alloca
31653166 if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
3167+#endif
31663168 n = vtop->c.i;
31673169 last_vtop = vtop;
31683170 if (n < 0)
31693171 error("invalid array size");
3172+#ifdef TOK_alloca
31703173 } else {
31713174 if (!is_integer_btype(vtop->type.t & VT_BTYPE))
31723175 error("size of variable length array should be an integer");
31733176 type->t |= VT_VLA;
31743177 last_vtop = vtop;
31753178 }
3179+#endif
31763180 }
31773181 skip(']');
31783182 /* parse next post type */
@@ -4864,7 +4868,11 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 1685 unmodified lines
48644868 int a;
48654869 CValue retcval;
48664870
4871+/* No need to coment all the block as it will never be called without
4872+ TOK_alloca defined (See ifdef TOK_alloca stanza in post_type */
4873+#ifdef TOK_alloca
48674874 vpush_global_sym(&func_old_type, TOK_alloca);
4875+#endif
48684876 vla_runtime_type_size(type, &a);
48694877 gfunc_call(1);
48704878
tests/tcctest.c+2−2
@@ -2010,7 +2010,7 @@ void old_style_function(void) · 2009 unmodified lines
20102010
20112011 void alloca_test()
20122012 {
2013−#if defined __i386__ || defined __x86_64__
2013+#ifdef TOK_alloca
20142014 char *p = alloca(16);
20152015 strcpy(p,"123456789012345");
20162016 printf("alloca: p is %s\n", p);
@@ -2022,7 +2022,7 @@ void alloca_test() · 5 unmodified lines
20222022
20232023 void c99_vla_test(int size1, int size2)
20242024 {
2025−#if defined __i386__ || defined __x86_64__
2025+#ifdef TOK_alloca
20262026 int tab1[size1 * size2][2], tab2[10][2];
20272027 void *tab1_ptr, *tab2_ptr;
20282028

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