On Thu, 18 May 2023, Martin Uecker via Gcc-patches wrote: > + /* we still have to evaluate size expressions */
Comments should start with a capital letter and end with ". ". > diff --git a/gcc/testsuite/gcc.dg/nested-vla-1.c > b/gcc/testsuite/gcc.dg/nested-vla-1.c > new file mode 100644 > index 00000000000..408a68524d8 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/nested-vla-1.c > @@ -0,0 +1,37 @@ > +/* { dg-do run } */ > +/* { dg-options "-std=gnu99" } */ I'm concerned with various undefined behavior in this and other tests; they look very fragile, relying on some optimizations and not others taking place. I think they should be adjusted to avoid undefined behavior if all the evaluations from the abstract machine (in particular, of sizeof operands with variable size) take place, and other undefined behavior from calling functions through function pointers with incompatible type. > + struct bar { char x[++n]; } (*bar2)(void) = bar; /* { dg-warning > "incompatible pointer type" } */ > + > + if (2 != n) > + __builtin_abort(); > + > + if (2 != sizeof((*bar2)())) > + __builtin_abort(); You're relying on the compiler not noticing that a function is being called through an incompatible type and thus not turning the call (which should be evaluated, because the operand of sizeof has a type with variable size) into a call to abort. > diff --git a/gcc/testsuite/gcc.dg/nested-vla-2.c > b/gcc/testsuite/gcc.dg/nested-vla-2.c > new file mode 100644 > index 00000000000..504eec48c80 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/nested-vla-2.c > @@ -0,0 +1,33 @@ > +/* { dg-do run } */ > +/* { dg-options "-std=gnu99" } */ > + > + > +int main() > +{ > + int n = 1; > + > + typeof(char (*)[++n]) bar(void) { } > + > + if (2 != n) > + __builtin_abort(); > + > + if (2 != sizeof(*bar())) > + __builtin_abort(); In this test, *bar() is evaluated, i.e. an undefined pointer is dereferenced; it would be better to return a valid pointer to a sufficiently large array to avoid that undefined behavior. > diff --git a/gcc/testsuite/gcc.dg/pr106465.c b/gcc/testsuite/gcc.dg/pr106465.c > new file mode 100644 > index 00000000000..b03e2442f12 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr106465.c > @@ -0,0 +1,86 @@ > +/* PR c/106465 > + * { dg-do run } > + * { dg-options "-std=gnu99" } > + * */ > + > +int main() > +{ > + int n = 3; > + > + void g1(int m, struct { char p[++m]; }* b) /* { dg-warning > "anonymous struct" } */ > + { > + if (3 != m) > + __builtin_abort(); > + > + if (3 != sizeof(b->p)) > + __builtin_abort(); > + } > + g1(2, (void*)0); Similarly, this is dereferencing a null pointer in the evaluated operand of sizeof. -- Joseph S. Myers jos...@codesourcery.com