From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailrelay.tugraz.at (mailrelay.tugraz.at [129.27.2.202]) by sourceware.org (Postfix) with ESMTPS id CFF433858410 for ; Tue, 21 Feb 2023 14:38:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CFF433858410 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=tugraz.at Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tugraz.at Received: from [192.168.0.221] (84-115-221-110.cable.dynamic.surfer.at [84.115.221.110]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4PLhhy121hz1LMYQ; Tue, 21 Feb 2023 15:37:53 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 mailrelay.tugraz.at 4PLhhy121hz1LMYQ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at; s=mailrelay; t=1676990282; bh=ojMBaOoBgJ+r5yVriOiy6y6y0tGgvTy6Cv9vnbWA3Wk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=TN4QJG9boNGYqRGR9rPyjWbF3DbHZ4OWGqot+6sljYcQj3IgfCb8eGvGb0zBvofh4 BgprMr2hn5TTAsnGUQyg7uy0KiLFgGNrQKk7LKw+pyFweOY8C02TjV1UEOud/4EYAB pZYHBagq61K/2KodN3LCc6glygCvHVoZuXW9hraI= Message-ID: <96d1a65a2356c2a3c11382caac960e51a2b5d9d3.camel@tugraz.at> Subject: Re: [PATCH] gimplify size expressions in parameters for all types [PR107557] [PR108423] From: Martin Uecker To: Richard Biener Cc: gcc-patches@gcc.gnu.org Date: Tue, 21 Feb 2023 15:37:53 +0100 In-Reply-To: References: <932c3fcb674894cbf933fdb679d966487150d81c.camel@tugraz.at> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.3-1+deb11u1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUG-Backscatter-control: G/VXY7/6zeyuAY/PU2/0qw X-Spam-Scanner: SpamAssassin 3.003001 X-Spam-Score-relay: -1.9 X-Scanned-By: MIMEDefang 2.74 on 129.27.10.117 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Am Dienstag, dem 21.02.2023 um 14:21 +0000 schrieb Richard Biener: > 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? > I just want to point out that without the patch gimplify_parm_sizes already does the recursion into pointers  types. But other types are also not reached. But maybe there was never a good reason for this split? I will try merging this all into gimplify_type_sizes. Martin > 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); > > > +} > > > + > > > > > > > > > > > > >