[C++] Avoid appending a useless __builtin_unreachable in functions which do return (PR c++/83897)

Message ID 20180117201040.GY2063@tucnak
State New
Headers show
Series
  • [C++] Avoid appending a useless __builtin_unreachable in functions which do return (PR c++/83897)
Related show

Commit Message

Jakub Jelinek Jan. 17, 2018, 8:10 p.m.
Hi!

I've noticed several testcases recently that have a dead
__builtin_unreachable call in functions right after return stmt.
They are optimized away after a while (typically in the cfg pass), but we
don't really need to generate them when there is the return.
The reason we don't find it is because it is wrapped in some cases in
CLEANUP_POINT_EXPR.  That doesn't change anything on the function actually
ending with a return.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2018-01-17  Jakub Jelinek  <jakub@redhat.com>

	PR c++/83897
	* cp-gimplify.c (cp_maybe_instrument_return): Handle
	CLEANUP_POINT_EXPR.

	* g++.dg/cpp0x/pr83897.C: New test.


	Jakub

Comments

Jason Merrill Jan. 17, 2018, 8:11 p.m. | #1
OK.

On Wed, Jan 17, 2018 at 3:10 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!

>

> I've noticed several testcases recently that have a dead

> __builtin_unreachable call in functions right after return stmt.

> They are optimized away after a while (typically in the cfg pass), but we

> don't really need to generate them when there is the return.

> The reason we don't find it is because it is wrapped in some cases in

> CLEANUP_POINT_EXPR.  That doesn't change anything on the function actually

> ending with a return.

>

> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

>

> 2018-01-17  Jakub Jelinek  <jakub@redhat.com>

>

>         PR c++/83897

>         * cp-gimplify.c (cp_maybe_instrument_return): Handle

>         CLEANUP_POINT_EXPR.

>

>         * g++.dg/cpp0x/pr83897.C: New test.

>

> --- gcc/cp/cp-gimplify.c.jj     2018-01-11 18:58:48.348391787 +0100

> +++ gcc/cp/cp-gimplify.c        2018-01-16 17:24:41.087336680 +0100

> @@ -1581,6 +1581,7 @@ cp_maybe_instrument_return (tree fndecl)

>           t = BIND_EXPR_BODY (t);

>           continue;

>         case TRY_FINALLY_EXPR:

> +       case CLEANUP_POINT_EXPR:

>           t = TREE_OPERAND (t, 0);

>           continue;

>         case STATEMENT_LIST:

> --- gcc/testsuite/g++.dg/cpp0x/pr83897.C.jj     2018-01-16 17:41:54.723256147 +0100

> +++ gcc/testsuite/g++.dg/cpp0x/pr83897.C        2018-01-16 17:41:34.274257947 +0100

> @@ -0,0 +1,13 @@

> +// PR c++/83897

> +// { dg-do compile { target c++11 } }

> +// { dg-options "-O2 -fdump-tree-gimple" }

> +// { dg-final { scan-tree-dump-not "__builtin_unreachable" "gimple" } }

> +

> +struct A {};

> +struct B { int a; int b = 5; };

> +

> +A

> +bar (B)

> +{

> +  return {};

> +}

>

>         Jakub

Patch

--- gcc/cp/cp-gimplify.c.jj	2018-01-11 18:58:48.348391787 +0100
+++ gcc/cp/cp-gimplify.c	2018-01-16 17:24:41.087336680 +0100
@@ -1581,6 +1581,7 @@  cp_maybe_instrument_return (tree fndecl)
 	  t = BIND_EXPR_BODY (t);
 	  continue;
 	case TRY_FINALLY_EXPR:
+	case CLEANUP_POINT_EXPR:
 	  t = TREE_OPERAND (t, 0);
 	  continue;
 	case STATEMENT_LIST:
--- gcc/testsuite/g++.dg/cpp0x/pr83897.C.jj	2018-01-16 17:41:54.723256147 +0100
+++ gcc/testsuite/g++.dg/cpp0x/pr83897.C	2018-01-16 17:41:34.274257947 +0100
@@ -0,0 +1,13 @@ 
+// PR c++/83897
+// { dg-do compile { target c++11 } }
+// { dg-options "-O2 -fdump-tree-gimple" }
+// { dg-final { scan-tree-dump-not "__builtin_unreachable" "gimple" } }
+
+struct A {};
+struct B { int a; int b = 5; };
+
+A
+bar (B)
+{
+  return {};
+}