public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Uecker <uecker@tugraz.at>
To: Richard Biener <rguenther@suse.de>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] gimplify size expressions in parameters for all types [PR107557] [PR108423]
Date: Tue, 21 Feb 2023 15:37:53 +0100	[thread overview]
Message-ID: <96d1a65a2356c2a3c11382caac960e51a2b5d9d3.camel@tugraz.at> (raw)
In-Reply-To: <nycvar.YFH.7.77.849.2302211418240.27913@jbgna.fhfr.qr>

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);
> > > +}
> > > +
> > > 
> > > 
> > 
> > 
> > 
> 



      reply	other threads:[~2023-02-21 14:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-08 12:02 Martin Uecker
2023-02-21 14:13 ` Martin Uecker
2023-02-21 14:21   ` Richard Biener
2023-02-21 14:37     ` Martin Uecker [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=96d1a65a2356c2a3c11382caac960e51a2b5d9d3.camel@tugraz.at \
    --to=uecker@tugraz.at \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).