History

Fix multidimensional arrays on stack

herman ten brugge committed 4 years ago

Commit 8a3d0a01 parent 4efcada2 files · +38 −1Browse files

Unified · Split

2 files
  1. tccgen.c +3 −1
  2. tests/tcctest.c +35 −0
tccgen.c+3−1
@@ -5442,7 +5442,8 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) · 5441 unmodified lines
5442 }5442 }
5443 if (tok != ']') {5443 if (tok != ']') {
5444 nocode_wanted = 1;5444 nocode_wanted = 1;
5445 gexpr(), vpop();5445 gexpr();
5446 goto check;
5446 }5447 }
5447 break;5448 break;
5448 5449
@@ -5457,6 +5458,7 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) · 8 unmodified lines
5457 nocode_wanted = 0;5458 nocode_wanted = 0;
5458 gexpr();5459 gexpr();
5459 }5460 }
5461check:
5460 if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {5462 if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
5461 n = vtop->c.i;5463 n = vtop->c.i;
5462 if (n < 0)5464 if (n < 0)
tests/tcctest.c+35−0
@@ -2997,10 +2997,45 @@ void c99_vla_test_2(int d, int h, int w) · 2996 unmodified lines
2997 free (arr);2997 free (arr);
2998}2998}
2999 2999
3000void c99_vla_test_3a (int arr[2][3][4])
3001{
3002 printf ("%d\n", arr[1][2][3]);
3003}
3004
3005void c99_vla_test_3b(int s, int arr[s][3][4])
3006{
3007 printf ("%d\n", arr[1][2][3]);
3008}
3009
3010void c99_vla_test_3c(int s, int arr[2][s][4])
3011{
3012 printf ("%d\n", arr[1][2][3]);
3013}
3014
3015void c99_vla_test_3d(int s, int arr[2][3][s])
3016{
3017 printf ("%d\n", arr[1][2][3]);
3018}
3019
3020void c99_vla_test_3(void)
3021{
3022 int a[2][3][4];
3023
3024 memset (a, 0, sizeof(a));
3025 a[1][2][3] = 2;
3026 c99_vla_test_3a(a);
3027 c99_vla_test_3b(2, a);
3028#if 0 // FIXME
3029 c99_vla_test_3c(3, a);
3030 c99_vla_test_3d(4, a);
3031#endif
3032}
3033
3000void c99_vla_test(void)3034void c99_vla_test(void)
3001{3035{
3002 c99_vla_test_1(5, 2);3036 c99_vla_test_1(5, 2);
3003 c99_vla_test_2(3, 4, 5);3037 c99_vla_test_2(3, 4, 5);
3038 c99_vla_test_3();
3004}3039}
3005 3040
3006 3041

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