From fa25630ce4e60ea2a91ca7612ff5f91f8709cecb Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Mon, 19 Sep 2022 15:32:07 +0200 Subject: [PATCH] vla: Fix check for vla used by autoconf 1) recursive types have no storage anymore, so a static int (*p)[x]; declaration is just fine 2) since somewhen VT_VLA doesn't imply VT_ARRAY anymore, so we now need to check VLA in at least one place before checking test_lvalue. ((2) should probably be cleaned up again so that VLA does again imply ARRAY) --- tccgen.c | 5 +++-- tests/tcctest.c | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tccgen.c b/tccgen.c index 5b510cb2..2525a3c6 100644 --- a/tccgen.c +++ b/tccgen.c @@ -5018,7 +5018,8 @@ static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td) expect("identifier"); *v = 0; } - post_type(post, ad, storage, td & ~(TYPE_DIRECT|TYPE_ABSTRACT)); + post_type(post, ad, post != ret ? 0 : storage, + td & ~(TYPE_DIRECT|TYPE_ABSTRACT)); parse_attribute(ad); type->t |= storage; return ret; @@ -5437,7 +5438,7 @@ ST_FUNC void unary(void) there and in function calls. */ /* arrays can also be used although they are not lvalues */ if ((vtop->type.t & VT_BTYPE) != VT_FUNC && - !(vtop->type.t & VT_ARRAY)) + !(vtop->type.t & (VT_ARRAY | VT_VLA))) test_lvalue(); if (vtop->sym) vtop->sym->a.addrtaken = 1; diff --git a/tests/tcctest.c b/tests/tcctest.c index 32fefdea..90e4de72 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -2979,6 +2979,7 @@ void c99_vla_test_2(int d, int h, int w) int x, y, z; int (*arr)[h][w] = malloc(sizeof(int) * d*h*w); int c = 1; + static int (*starr)[h][w]; printf("Test C99 VLA 6 (pointer)\n"); @@ -2998,13 +2999,15 @@ void c99_vla_test_2(int d, int h, int w) } puts(""); } + starr = &arr[1]; printf(" sizes : %d %d %d\n" " pdiff : %d %d\n" - " tests : %d %d\n", + " tests : %d %d %d\n", sizeof (*arr), sizeof (*arr)[0], sizeof (*arr)[0][0], arr + 2 - arr, *arr + 3 - *arr, 0 == sizeof (*arr + 1) - sizeof arr, - 0 == sizeof sizeof *arr - sizeof arr + 0 == sizeof sizeof *arr - sizeof arr, + starr[0][2][3] == arr[1][2][3] ); free (arr); }