public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: Jeff Law <law@redhat.com>, GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fix middle-end/67133, part 1
Date: Tue, 18 Aug 2015 20:09:00 -0000	[thread overview]
Message-ID: <20150818194918.GB2729@redhat.com> (raw)
In-Reply-To: <CAFiYyc3MQxXO_es3ZEPtcFGybHUxFmeovyb_1FPO6WWH-uaE+Q@mail.gmail.com>

On Tue, Aug 18, 2015 at 10:45:21AM +0200, Richard Biener wrote:
> On Mon, Aug 17, 2015 at 7:31 PM, Jeff Law <law@redhat.com> wrote:
> > But in walking through all that, I think I've stumbled on a simpler
> > solution.  Specifically do as a little as possible and let the standard
> > mechanisms clean things up :-)
> >
> > 1. Delete the code that removes instructions after the trap.
> >
> > 2. Split the block immediately after the trap and remove the edge
> >    from the original block (with the trap) to the new block.
> 
> cfg-cleanup will do that for you if you have a not returning stmt ending
> the previous block.

The following patch hopefully does what's oulined above.
Arguably I should have renamed the insert_trap_and_remove_trailing_statements
to something more descriptive, e.g. insert_trap_and_split_block.  Your
call.

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

2015-08-18  Marek Polacek  <polacek@redhat.com>

	PR middle-end/67133
	* gimple-ssa-isolate-paths.c
	(insert_trap_and_remove_trailing_statements): Rename to ...
	(insert_trap): ... this.  Don't remove trailing statements; split
	block instead.
	(find_explicit_erroneous_behaviour): Don't remove all outgoing edges.

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

diff --git gcc/gimple-ssa-isolate-paths.c gcc/gimple-ssa-isolate-paths.c
index 6f84f85..ca2322d 100644
--- gcc/gimple-ssa-isolate-paths.c
+++ gcc/gimple-ssa-isolate-paths.c
@@ -66,10 +66,10 @@ check_loadstore (gimple stmt, tree op, tree, void *data)
   return false;
 }
 
-/* Insert a trap after SI and remove SI and all statements after the trap.  */
+/* Insert a trap after SI and split the block after the trap.  */
 
 static void
-insert_trap_and_remove_trailing_statements (gimple_stmt_iterator *si_p, tree op)
+insert_trap (gimple_stmt_iterator *si_p, tree op)
 {
   /* We want the NULL pointer dereference to actually occur so that
      code that wishes to catch the signal can do so.
@@ -115,18 +115,8 @@ insert_trap_and_remove_trailing_statements (gimple_stmt_iterator *si_p, tree op)
   else
     gsi_insert_before (si_p, seq, GSI_NEW_STMT);
 
-  /* We must remove statements from the end of the block so that we
-     never reference a released SSA_NAME.  */
-  basic_block bb = gimple_bb (gsi_stmt (*si_p));
-  for (gimple_stmt_iterator si = gsi_last_bb (bb);
-       gsi_stmt (si) != gsi_stmt (*si_p);
-       si = gsi_last_bb (bb))
-    {
-      stmt = gsi_stmt (si);
-      unlink_stmt_vdef (stmt);
-      gsi_remove (&si, true);
-      release_defs (stmt);
-    }
+  split_block (gimple_bb (new_stmt), new_stmt);
+  *si_p = gsi_for_stmt (stmt);
 }
 
 /* BB when reached via incoming edge E will exhibit undefined behaviour
@@ -215,7 +205,7 @@ isolate_path (basic_block bb, basic_block duplicate,
 	  update_stmt (ret);
 	}
       else
-	insert_trap_and_remove_trailing_statements (&si2, op);
+	insert_trap (&si2, op);
     }
 
   return duplicate;
@@ -422,14 +412,8 @@ find_explicit_erroneous_behaviour (void)
 		    continue;
 		}
 
-	      insert_trap_and_remove_trailing_statements (&si,
-							  null_pointer_node);
-
-	      /* And finally, remove all outgoing edges from BB.  */
-	      edge e;
-	      for (edge_iterator ei = ei_start (bb->succs);
-		   (e = ei_safe_edge (ei)); )
-		remove_edge (e);
+	      insert_trap (&si, null_pointer_node);
+	      bb = gimple_bb (gsi_stmt (si));
 
 	      /* Ignore any more operands on this statement and
 		 continue the statement iterator (which should
diff --git gcc/testsuite/g++.dg/torture/pr67133.C gcc/testsuite/g++.dg/torture/pr67133.C
index e69de29..0f23572 100644
--- gcc/testsuite/g++.dg/torture/pr67133.C
+++ gcc/testsuite/g++.dg/torture/pr67133.C
@@ -0,0 +1,46 @@
+// { dg-do compile }
+// { dg-additional-options "-fisolate-erroneous-paths-attribute" }
+
+class A;
+struct B {
+  typedef A type;
+};
+template <typename> struct I : B {};
+class C {
+public:
+  C(char *);
+  int size();
+};
+template <typename> struct D;
+template <typename _Tp, typename = D<_Tp>> class F {
+  class G {
+    template <typename> static _Tp *__test();
+    typedef int _Del;
+
+  public:
+    typedef decltype(__test<_Del>()) type;
+  };
+
+public:
+  typename I<_Tp>::type operator*() {
+    typename G::type a = 0;
+    return *a;
+  }
+};
+class H {
+  F<A> Out;
+  H();
+};
+void fn1(void *, void *, int) __attribute__((__nonnull__));
+class A {
+  int OutBufEnd, OutBufCur;
+
+public:
+  void operator<<(C p1) {
+    int b, c = p1.size();
+    if (OutBufEnd)
+      fn1(&OutBufCur, &b, c);
+  }
+};
+char* a;
+H::H() { *Out << a; }

	Marek

  reply	other threads:[~2015-08-18 19:49 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-14 11:51 Marek Polacek
2015-08-14 13:19 ` Richard Biener
2015-08-14 13:36   ` Marek Polacek
2015-08-14 14:54     ` Jeff Law
2015-08-14 15:33       ` Marek Polacek
2015-08-14 15:39         ` Jeff Law
2015-08-14 20:12           ` Marek Polacek
2015-08-14 20:36             ` Jeff Law
2015-08-14 21:48               ` Marek Polacek
2015-08-17 17:47                 ` Jeff Law
2015-08-17 18:01                   ` Marek Polacek
2015-08-18  8:47                   ` Richard Biener
2015-08-18 20:09                     ` Marek Polacek [this message]
2015-08-19  9:54                       ` Richard Biener
2015-08-19 10:39                         ` Marek Polacek
2015-08-19 14:25                       ` Jeff Law
2015-08-20  9:05                       ` Andreas Schwab
2015-08-20 10:50                         ` Marek Polacek
2015-08-20 10:58                           ` Andreas Schwab
2015-08-20 16:42                           ` Jeff Law
2015-08-20 16:59                             ` Marek Polacek
2015-08-20 16:59                               ` Jeff Law
2015-08-20 17:02                               ` Marek Polacek
2015-08-20 17:11                                 ` Jeff Law
2015-08-23 10:54                         ` Jan-Benedict Glaw
2015-08-24 15:55                           ` Jeff Law
2015-08-24 16:15                             ` Marek Polacek

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=20150818194918.GB2729@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    --cc=richard.guenther@gmail.com \
    /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).