Evaluate arguments of sizeof for all types of variable size
and not just for VLAs. This fixes some issues related to
[PR29970] where statement expressions need to be evaluated
so that the size is well defined.
2021-08-10 Martin Uecker <muecker@gwdg.de>
gcc/c/
PR c/29970
* c-typeck.c (c_expr_sizeof_expr): Evaluate
size expressions for structs of variable size.
gcc/testsuite/
PR c/29970
* gcc.dg/vla-stexp-1.c: New test.
c_last_sizeof_loc = loc;
ret.original_code = SIZEOF_EXPR;
ret.original_type = NULL;
- if (c_vla_type_p (TREE_TYPE (folded_expr)))
+ if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)))
{
/* sizeof is evaluated when given a vla (C99 6.5.3.4p2). */
ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
--- /dev/null
+/* PR29970*/
+/* { dg-do run } */
+/* { dg-options "-Wall -O0" } */
+
+int foo(void)
+{
+ int n = 0;
+ return sizeof(*({ n = 10; struct foo { int x[n]; } x; &x; }));
+}
+
+
+int main()
+{
+ if (sizeof(struct foo { int x[10]; }) != foo())
+ __builtin_abort();
+
+ return 0;
+}