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
54425442 }
54435443 if (tok != ']') {
54445444 nocode_wanted = 1;
5445− gexpr(), vpop();
5445+ gexpr();
5446+ goto check;
54465447 }
54475448 break;
54485449
@@ -5457,6 +5458,7 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) · 8 unmodified lines
54575458 nocode_wanted = 0;
54585459 gexpr();
54595460 }
5461+check:
54605462 if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
54615463 n = vtop->c.i;
54625464 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
29972997 free (arr);
29982998 }
29992999
3000+void c99_vla_test_3a (int arr[2][3][4])
3001+{
3002+ printf ("%d\n", arr[1][2][3]);
3003+}
3004+
3005+void c99_vla_test_3b(int s, int arr[s][3][4])
3006+{
3007+ printf ("%d\n", arr[1][2][3]);
3008+}
3009+
3010+void c99_vla_test_3c(int s, int arr[2][s][4])
3011+{
3012+ printf ("%d\n", arr[1][2][3]);
3013+}
3014+
3015+void c99_vla_test_3d(int s, int arr[2][3][s])
3016+{
3017+ printf ("%d\n", arr[1][2][3]);
3018+}
3019+
3020+void 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+
30003034 void c99_vla_test(void)
30013035 {
30023036 c99_vla_test_1(5, 2);
30033037 c99_vla_test_2(3, 4, 5);
3038+ c99_vla_test_3();
30043039 }
30053040
30063041

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