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)
This commit is contained in:
Michael Matz 2022-09-19 15:32:07 +02:00
parent 76b88e22a4
commit fa25630ce4
2 changed files with 8 additions and 4 deletions

View File

@ -5018,7 +5018,8 @@ static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td)
expect("identifier"); expect("identifier");
*v = 0; *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); parse_attribute(ad);
type->t |= storage; type->t |= storage;
return ret; return ret;
@ -5437,7 +5438,7 @@ ST_FUNC void unary(void)
there and in function calls. */ there and in function calls. */
/* arrays can also be used although they are not lvalues */ /* arrays can also be used although they are not lvalues */
if ((vtop->type.t & VT_BTYPE) != VT_FUNC && if ((vtop->type.t & VT_BTYPE) != VT_FUNC &&
!(vtop->type.t & VT_ARRAY)) !(vtop->type.t & (VT_ARRAY | VT_VLA)))
test_lvalue(); test_lvalue();
if (vtop->sym) if (vtop->sym)
vtop->sym->a.addrtaken = 1; vtop->sym->a.addrtaken = 1;

View File

@ -2979,6 +2979,7 @@ void c99_vla_test_2(int d, int h, int w)
int x, y, z; int x, y, z;
int (*arr)[h][w] = malloc(sizeof(int) * d*h*w); int (*arr)[h][w] = malloc(sizeof(int) * d*h*w);
int c = 1; int c = 1;
static int (*starr)[h][w];
printf("Test C99 VLA 6 (pointer)\n"); printf("Test C99 VLA 6 (pointer)\n");
@ -2998,13 +2999,15 @@ void c99_vla_test_2(int d, int h, int w)
} }
puts(""); puts("");
} }
starr = &arr[1];
printf(" sizes : %d %d %d\n" printf(" sizes : %d %d %d\n"
" pdiff : %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], sizeof (*arr), sizeof (*arr)[0], sizeof (*arr)[0][0],
arr + 2 - arr, *arr + 3 - *arr, arr + 2 - arr, *arr + 3 - *arr,
0 == sizeof (*arr + 1) - sizeof 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); free (arr);
} }