diff mbox

Fix middle-end/71308

Message ID 20160527115234.GF3014@redhat.com
State New
Headers show

Commit Message

Marek Polacek May 27, 2016, 11:52 a.m. UTC
A stupid mistake of mine.  When I introduced the should_remove_lhs_p call,
I removed the check for LHS here, because should_remove_lhs_p checks that.
Well, in this case the LHS was NULL, but gimple_call_fntype (stmt) had void
type, so we went on and crashed on the SSA_NAME check.  Sorry.  But at least
we have a test exercising this path.

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

2016-05-27  Marek Polacek  <polacek@redhat.com>

	PR middle-end/71308
	* gimple-fold.c (gimple_fold_call): Check that LHS is not null.

	* g++.dg/torture/pr71308.C: New test.


	Marek

Comments

Richard Biener May 27, 2016, 12:01 p.m. UTC | #1
On Fri, May 27, 2016 at 1:52 PM, Marek Polacek <polacek@redhat.com> wrote:
> A stupid mistake of mine.  When I introduced the should_remove_lhs_p call,
> I removed the check for LHS here, because should_remove_lhs_p checks that.
> Well, in this case the LHS was NULL, but gimple_call_fntype (stmt) had void
> type, so we went on and crashed on the SSA_NAME check.  Sorry.  But at least
> we have a test exercising this path.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?

Yes.

Richard.

> 2016-05-27  Marek Polacek  <polacek@redhat.com>
>
>         PR middle-end/71308
>         * gimple-fold.c (gimple_fold_call): Check that LHS is not null.
>
>         * g++.dg/torture/pr71308.C: New test.
>
> diff --git gcc/gimple-fold.c gcc/gimple-fold.c
> index d6657e9..600aa72 100644
> --- gcc/gimple-fold.c
> +++ gcc/gimple-fold.c
> @@ -3053,7 +3053,8 @@ gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace)
>                           == void_type_node))
>                     gimple_call_set_fntype (stmt, TREE_TYPE (fndecl));
>                   /* If the call becomes noreturn, remove the lhs.  */
> -                 if (gimple_call_noreturn_p (stmt)
> +                 if (lhs
> +                     && gimple_call_noreturn_p (stmt)
>                       && (VOID_TYPE_P (TREE_TYPE (gimple_call_fntype (stmt)))
>                           || should_remove_lhs_p (lhs)))
>                     {
> diff --git gcc/testsuite/g++.dg/torture/pr71308.C gcc/testsuite/g++.dg/torture/pr71308.C
> index e69de29..ff5cd95 100644
> --- gcc/testsuite/g++.dg/torture/pr71308.C
> +++ gcc/testsuite/g++.dg/torture/pr71308.C
> @@ -0,0 +1,18 @@
> +// PR middle-end/71308
> +// { dg-do compile }
> +
> +class S
> +{
> +  void foo ();
> +  virtual void bar () = 0;
> +  virtual ~S ();
> +};
> +inline void
> +S::foo ()
> +{
> +  bar ();
> +};
> +S::~S ()
> +{
> +  foo ();
> +}
>
>         Marek
diff mbox

Patch

diff --git gcc/gimple-fold.c gcc/gimple-fold.c
index d6657e9..600aa72 100644
--- gcc/gimple-fold.c
+++ gcc/gimple-fold.c
@@ -3053,7 +3053,8 @@  gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace)
 			  == void_type_node))
 		    gimple_call_set_fntype (stmt, TREE_TYPE (fndecl));
 		  /* If the call becomes noreturn, remove the lhs.  */
-		  if (gimple_call_noreturn_p (stmt)
+		  if (lhs
+		      && gimple_call_noreturn_p (stmt)
 		      && (VOID_TYPE_P (TREE_TYPE (gimple_call_fntype (stmt)))
 			  || should_remove_lhs_p (lhs)))
 		    {
diff --git gcc/testsuite/g++.dg/torture/pr71308.C gcc/testsuite/g++.dg/torture/pr71308.C
index e69de29..ff5cd95 100644
--- gcc/testsuite/g++.dg/torture/pr71308.C
+++ gcc/testsuite/g++.dg/torture/pr71308.C
@@ -0,0 +1,18 @@ 
+// PR middle-end/71308
+// { dg-do compile }
+
+class S
+{
+  void foo ();
+  virtual void bar () = 0;
+  virtual ~S ();
+};
+inline void
+S::foo ()
+{
+  bar ();
+};
+S::~S ()
+{
+  foo ();
+}