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
3162 n = -1;3162 n = -1;
3163 if (tok != ']') {3163 if (tok != ']') {
3164 gexpr();3164 gexpr();
3165#ifdef TOK_alloca
3165 if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {3166 if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
3167#endif
3166 n = vtop->c.i;3168 n = vtop->c.i;
3167 last_vtop = vtop;3169 last_vtop = vtop;
3168 if (n < 0)3170 if (n < 0)
3169 error("invalid array size");3171 error("invalid array size");
3172#ifdef TOK_alloca
3170 } else {3173 } else {
3171 if (!is_integer_btype(vtop->type.t & VT_BTYPE))3174 if (!is_integer_btype(vtop->type.t & VT_BTYPE))
3172 error("size of variable length array should be an integer");3175 error("size of variable length array should be an integer");
3173 type->t |= VT_VLA;3176 type->t |= VT_VLA;
3174 last_vtop = vtop;3177 last_vtop = vtop;
3175 }3178 }
3179#endif
3176 }3180 }
3177 skip(']');3181 skip(']');
3178 /* parse next post type */3182 /* parse next post type */
@@ -4864,7 +4868,11 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 1685 unmodified lines
4864 int a;4868 int a;
4865 CValue retcval;4869 CValue retcval;
4866 4870
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
4867 vpush_global_sym(&func_old_type, TOK_alloca);4874 vpush_global_sym(&func_old_type, TOK_alloca);
4875#endif
4868 vla_runtime_type_size(type, &a);4876 vla_runtime_type_size(type, &a);
4869 gfunc_call(1);4877 gfunc_call(1);
4870 4878
tests/tcctest.c+2−2
@@ -2010,7 +2010,7 @@ void old_style_function(void) · 2009 unmodified lines
2010 2010
2011void alloca_test()2011void alloca_test()
2012{2012{
2013#if defined __i386__ || defined __x86_64__2013#ifdef TOK_alloca
2014 char *p = alloca(16);2014 char *p = alloca(16);
2015 strcpy(p,"123456789012345");2015 strcpy(p,"123456789012345");
2016 printf("alloca: p is %s\n", p);2016 printf("alloca: p is %s\n", p);
@@ -2022,7 +2022,7 @@ void alloca_test() · 5 unmodified lines
2022 2022
2023void c99_vla_test(int size1, int size2)2023void c99_vla_test(int size1, int size2)
2024{2024{
2025#if defined __i386__ || defined __x86_64__2025#ifdef TOK_alloca
2026 int tab1[size1 * size2][2], tab2[10][2];2026 int tab1[size1 * size2][2], tab2[10][2];
2027 void *tab1_ptr, *tab2_ptr;2027 void *tab1_ptr, *tab2_ptr;
2028 2028

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