On Tue, 21 Feb 2023, Martin Uecker wrote: > > > Hi Richard, > > can you look at this middle-end patch? It fixes two regressions.
But gimplify_type_sizes recurses itself, but in particular _not_ for pointer types. Iff recursing in parameter context is necessary and safe I'd rather have gimplify_type_sizes know that (bool for_param_p?) and do the recursion? Richard. > Martin > > > PS: I happy to do something about at variably_modified_type_p > in the middle-end, if you have a recommendation. > > > > > Am Mittwoch, dem 08.02.2023 um 13:02 +0100 schrieb Martin Uecker: > > > > Here is a fix for PR107557 and PR108423. > > > > > > Bootstrapped and regression tested on x86-64. > > > > > > > > Gimplify more size expression in parameters [PR107557] and [PR108234] > > > > > > gimplify_parm_type only recursives into pointer type and > > size expressions in other types (e.g. function types) were > > not reached. > > > > > > PR c/107557 > > PR c/108234 > > > > > > gcc/Changelog > > * gcc/function.cc (gimplify_parm_type): Also recursive into > > non-pointer types. > > > > > > gcc/testsuite/ChangeLog: > > * gcc.dg/pr107557-1.c: New test. > > * gcc.dg/pr107557-2.c: New test. > > * gcc.dg/pr108423-1.c: New test. > > * gcc.dg/pr108423-2.c: New test. > > * gcc.dg/pr108423-3.c: New test. > > * gcc.dg/pr108423-4.c: New test. > > * gcc.dg/pr108423-5.c: New test. > > > > > > > > > > diff --git a/gcc/function.cc b/gcc/function.cc > > index cfc4d2f74af..d777348aeb4 100644 > > --- a/gcc/function.cc > > +++ b/gcc/function.cc > > @@ -3880,20 +3880,15 @@ static tree > > gimplify_parm_type (tree *tp, int *walk_subtrees, void *data) > > { > > tree t = *tp; > > - > > *walk_subtrees = 0; > > if (TYPE_P (t)) > > { > > - if (POINTER_TYPE_P (t)) > > - *walk_subtrees = 1; > > - else if (TYPE_SIZE (t) && !TREE_CONSTANT (TYPE_SIZE (t)) > > + if (TYPE_SIZE (t) && !TREE_CONSTANT (TYPE_SIZE (t)) > > && !TYPE_SIZES_GIMPLIFIED (t)) > > - { > > - gimplify_type_sizes (t, (gimple_seq *) data); > > - *walk_subtrees = 1; > > - } > > - } > > + gimplify_type_sizes (t, (gimple_seq *) data); > > > > > > + *walk_subtrees = 1; > > + } > > return NULL; > > } > > > > > > diff --git a/gcc/testsuite/gcc.dg/pr107557-1.c > > b/gcc/testsuite/gcc.dg/pr107557-1.c > > new file mode 100644 > > index 00000000000..88c248b6564 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.dg/pr107557-1.c > > @@ -0,0 +1,24 @@ > > +/* PR107557 > > + * { dg-do compile } > > + * { dg-options "-flto -fsanitize=undefined -fexceptions > > -Wno-incompatible-pointer-types" } > > + */ > > + > > + > > +int c[1][3*2]; > > +int f(int * const m, int (**v)[*m * 2]) > > +{ > > + return &(c[0][*m]) == &((*v)[0][*m]); > > +} > > +int test(int n, int (*(*fn)(void))[n]) > > +{ > > + return (*fn())[0]; > > +} > > +int main() > > +{ > > + int m = 3; > > + int (*d)[3*2] = c; > > + int (*fn[m])(void); > > + return f(&m, &d) + test(m, &fn); > > +} > > + > > + > > diff --git a/gcc/testsuite/gcc.dg/pr107557-2.c > > b/gcc/testsuite/gcc.dg/pr107557-2.c > > new file mode 100644 > > index 00000000000..2d26bb0b16a > > --- /dev/null > > +++ b/gcc/testsuite/gcc.dg/pr107557-2.c > > @@ -0,0 +1,23 @@ > > +/* PR107557 > > + * { dg-do compile } > > + * { dg-options "-flto -fsanitize=undefined -fexceptions > > -Wno-incompatible-pointer-types" } > > + */ > > + > > + > > +int c[1][3*2]; > > +int f(int * const m, int (**(*v))[*m * 2]) > > +{ > > + return &(c[0][*m]) == &((*v)[0][*m]); /* { dg-warning "lacks a cast" > > } */ > > +} > > +int test(int n, int (*(*(*fn))(void))[n]) > > +{ > > + return (*(*fn)())[0]; > > +} > > +int main() > > +{ > > + int m = 3; > > + int (*d)[3*2] = c; > > + int (*fn[m])(void); > > + return f(&m, &d) + test(m, &fn); > > +} > > + > > diff --git a/gcc/testsuite/gcc.dg/pr108423-1.c > > b/gcc/testsuite/gcc.dg/pr108423-1.c > > new file mode 100644 > > index 00000000000..0c98d1d46b9 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.dg/pr108423-1.c > > @@ -0,0 +1,16 @@ > > +/* PR108423 > > + * { dg-do compile } > > + * { dg-options "-O2 -Wno-int-conversion -Wno-incompatible-pointer-types" } > > + */ > > +int f (int n, int (**(*a)(void))[n]) > > +{ > > + return (*a())[0]; > > +} > > +int g () > > +{ > > + int m = 3; > > + int (*a[m])(void); > > + return f(m, &a); > > +} > > + > > + > > diff --git a/gcc/testsuite/gcc.dg/pr108423-2.c > > b/gcc/testsuite/gcc.dg/pr108423-2.c > > new file mode 100644 > > index 00000000000..006e45a9629 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.dg/pr108423-2.c > > @@ -0,0 +1,16 @@ > > +/* PR108423 > > + * { dg-do compile } > > + * { dg-options "-O2" } > > + */ > > + > > +void f(int n, int (*a(void))[n]) > > +{ > > + (a())[0]; > > +} > > + > > +void g(void) > > +{ > > + int (*a(void))[1]; > > + f(1, a); > > +} > > + > > diff --git a/gcc/testsuite/gcc.dg/pr108423-3.c > > b/gcc/testsuite/gcc.dg/pr108423-3.c > > new file mode 100644 > > index 00000000000..c1987c42b40 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.dg/pr108423-3.c > > @@ -0,0 +1,17 @@ > > +/* PR108423 > > + * { dg-do compile } > > + * { dg-options "-O2" } > > + */ > > + > > +void f(int n, int (*(*b)(void))[n]) > > +{ > > + sizeof (*(*b)()); > > +} > > + > > +int (*a(void))[1]; > > + > > +void g(void) > > +{ > > + f(1, &a); > > +} > > + > > diff --git a/gcc/testsuite/gcc.dg/pr108423-4.c > > b/gcc/testsuite/gcc.dg/pr108423-4.c > > new file mode 100644 > > index 00000000000..91336f3f283 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.dg/pr108423-4.c > > @@ -0,0 +1,17 @@ > > +/* PR108423 > > + * { dg-do compile } > > + * { dg-options "-O2" } > > + */ > > + > > +void f(int n, int (*a(void))[n]) > > +{ > > + sizeof (*a()); > > +} > > + > > +int (*a(void))[1]; > > + > > +void g(void) > > +{ > > + f(1, a); > > +} > > + > > diff --git a/gcc/testsuite/gcc.dg/pr108423-5.c > > b/gcc/testsuite/gcc.dg/pr108423-5.c > > new file mode 100644 > > index 00000000000..7e4fffb2870 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.dg/pr108423-5.c > > @@ -0,0 +1,17 @@ > > +/* PR108423 > > + * { dg-do compile } > > + * { dg-options "-O2" } > > + */ > > + > > +void f(int n, int (*(*a)(void))[n]) > > +{ > > + sizeof ((*a)()); > > +} > > + > > +int (*a(void))[1]; > > + > > +void g(void) > > +{ > > + f(1, a); > > +} > > + > > > > > > > -- Richard Biener <rguent...@suse.de> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)