public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Don't optimize away lhs from calls with addressable zero sized return type (PR c++/82159)
@ 2017-09-27 13:24 Jakub Jelinek
  2017-09-27 13:35 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2017-09-27 13:24 UTC (permalink / raw)
  To: Richard Biener, Jason Merrill; +Cc: gcc-patches

Hi!

The expansion relies on lhs being kept for calls that return addressable
types.  On the following testcase (which is a GNU extension, pedantically
we error out on zero sized arrays) we return TREE_ADDRESSABLE
zero_sized_type and optimize away the lhs which we need later on.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
during the bootstrap+regtests it only made a difference on the newly added
testcase.  Ok for trunk?

2017-09-27  Jakub Jelinek  <jakub@redhat.com>

	PR c++/82159
	* gimplify.c (gimplify_modify_expr): Don't optimize away zero sized
	lhs from calls if the lhs has addressable type.

	* g++.dg/opt/pr82159.C: New test.

--- gcc/gimplify.c.jj	2017-09-01 09:25:34.000000000 +0200
+++ gcc/gimplify.c	2017-09-26 13:03:11.614726601 +0200
@@ -5479,7 +5479,12 @@ gimplify_modify_expr (tree *expr_p, gimp
      side as statements and throw away the assignment.  Do this after
      gimplify_modify_expr_rhs so we handle TARGET_EXPRs of addressable
      types properly.  */
-  if (zero_sized_type (TREE_TYPE (*from_p)) && !want_value)
+  if (zero_sized_type (TREE_TYPE (*from_p))
+      && !want_value
+      /* Don't do this for calls that return addressable types, expand_call
+	 relies on those having a lhs.  */
+      && !(TREE_ADDRESSABLE (TREE_TYPE (*from_p))
+	   && TREE_CODE (*from_p) == CALL_EXPR))
     {
       gimplify_stmt (from_p, pre_p);
       gimplify_stmt (to_p, pre_p);
--- gcc/testsuite/g++.dg/opt/pr82159.C.jj	2017-09-26 13:04:08.711027279 +0200
+++ gcc/testsuite/g++.dg/opt/pr82159.C	2017-09-26 14:20:01.519361945 +0200
@@ -0,0 +1,18 @@
+// PR c++/82159
+// { dg-do compile }
+// { dg-options "" }
+
+template<int N>
+struct S
+{
+  ~S () {}
+  template<int M> S<M> foo () { return S<M> (); }
+  unsigned char data[N];
+};
+
+int
+main ()
+{
+  S<16> d;
+  S<0> t = d.foo<0> ();
+}

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Don't optimize away lhs from calls with addressable zero sized return type (PR c++/82159)
  2017-09-27 13:24 [PATCH] Don't optimize away lhs from calls with addressable zero sized return type (PR c++/82159) Jakub Jelinek
@ 2017-09-27 13:35 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-09-27 13:35 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jason Merrill, gcc-patches

On Wed, 27 Sep 2017, Jakub Jelinek wrote:

> Hi!
> 
> The expansion relies on lhs being kept for calls that return addressable
> types.  On the following testcase (which is a GNU extension, pedantically
> we error out on zero sized arrays) we return TREE_ADDRESSABLE
> zero_sized_type and optimize away the lhs which we need later on.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
> during the bootstrap+regtests it only made a difference on the newly added
> testcase.  Ok for trunk?

Ok.

Thanks,
Richard.

> 2017-09-27  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/82159
> 	* gimplify.c (gimplify_modify_expr): Don't optimize away zero sized
> 	lhs from calls if the lhs has addressable type.
> 
> 	* g++.dg/opt/pr82159.C: New test.
> 
> --- gcc/gimplify.c.jj	2017-09-01 09:25:34.000000000 +0200
> +++ gcc/gimplify.c	2017-09-26 13:03:11.614726601 +0200
> @@ -5479,7 +5479,12 @@ gimplify_modify_expr (tree *expr_p, gimp
>       side as statements and throw away the assignment.  Do this after
>       gimplify_modify_expr_rhs so we handle TARGET_EXPRs of addressable
>       types properly.  */
> -  if (zero_sized_type (TREE_TYPE (*from_p)) && !want_value)
> +  if (zero_sized_type (TREE_TYPE (*from_p))
> +      && !want_value
> +      /* Don't do this for calls that return addressable types, expand_call
> +	 relies on those having a lhs.  */
> +      && !(TREE_ADDRESSABLE (TREE_TYPE (*from_p))
> +	   && TREE_CODE (*from_p) == CALL_EXPR))
>      {
>        gimplify_stmt (from_p, pre_p);
>        gimplify_stmt (to_p, pre_p);
> --- gcc/testsuite/g++.dg/opt/pr82159.C.jj	2017-09-26 13:04:08.711027279 +0200
> +++ gcc/testsuite/g++.dg/opt/pr82159.C	2017-09-26 14:20:01.519361945 +0200
> @@ -0,0 +1,18 @@
> +// PR c++/82159
> +// { dg-do compile }
> +// { dg-options "" }
> +
> +template<int N>
> +struct S
> +{
> +  ~S () {}
> +  template<int M> S<M> foo () { return S<M> (); }
> +  unsigned char data[N];
> +};
> +
> +int
> +main ()
> +{
> +  S<16> d;
> +  S<0> t = d.foo<0> ();
> +}
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-27 13:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-27 13:24 [PATCH] Don't optimize away lhs from calls with addressable zero sized return type (PR c++/82159) Jakub Jelinek
2017-09-27 13:35 ` Richard Biener

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).