From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 108730 invoked by alias); 18 Aug 2015 19:49:27 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 108720 invoked by uid 89); 18 Aug 2015 19:49:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 18 Aug 2015 19:49:25 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 471B18E226; Tue, 18 Aug 2015 19:49:24 +0000 (UTC) Received: from redhat.com (ovpn-204-61.brq.redhat.com [10.40.204.61]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7IJnJku020299 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Tue, 18 Aug 2015 15:49:22 -0400 Date: Tue, 18 Aug 2015 20:09:00 -0000 From: Marek Polacek To: Richard Biener Cc: Jeff Law , GCC Patches Subject: Re: [PATCH] Fix middle-end/67133, part 1 Message-ID: <20150818194918.GB2729@redhat.com> References: <20150814132945.GS3335@redhat.com> <55CE002E.6000108@redhat.com> <20150814153224.GU3335@redhat.com> <55CE0A5A.4070802@redhat.com> <20150814195836.GB2093@redhat.com> <55CE5054.5080400@redhat.com> <20150814204649.GC2093@redhat.com> <55D21A8D.50004@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2015-08/txt/msg01027.txt.bz2 On Tue, Aug 18, 2015 at 10:45:21AM +0200, Richard Biener wrote: > On Mon, Aug 17, 2015 at 7:31 PM, Jeff Law 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 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 struct I : B {}; +class C { +public: + C(char *); + int size(); +}; +template struct D; +template > class F { + class G { + template 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 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