From patchwork Tue Nov 24 10:39:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 57220 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp1998277lbb; Tue, 24 Nov 2015 02:39:43 -0800 (PST) X-Received: by 10.98.67.68 with SMTP id q65mr21470393pfa.63.1448361583254; Tue, 24 Nov 2015 02:39:43 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id pu2si25663823pac.80.2015.11.24.02.39.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Nov 2015 02:39:43 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-415148-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-return-415148-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-415148-patch=linaro.org@gcc.gnu.org; dkim=pass header.i=@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=XIl5EpPBXiZv2Zt6FYCaWoAmNCUEDvLU7Zb73daVnNJ HJPc+V70Dxz/2W1wep+qBXawwNSeQpd+h9ODv0uDHAFXvy6QyHUEaflTsuVtYxWt HdCSRNDdvumqoKluC4nAygXAf6PNUJtmU91G76GmtMTo5tdk+F+ao7L5yS9YoPHE = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=Hs0Qzh51A44GXrFRo+zGvpWu0VE=; b=JzT82dYvbMOVPJhf+ SOl/D/2/LzHu6rQBj72lmCDlzN1zFTwBz5+LL2gQQ6fQ1eLANrFYUIClhfI+Ez8I fZocJp0yfMmXABD+QH79iteXA/ewz8BkqJ8U1Q2rrW+5b7x5WhgovgDkmnrNrP/i th3AnUAXCiUzLzeslKtG2EJWGM= Received: (qmail 68562 invoked by alias); 24 Nov 2015 10:39:31 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 68547 invoked by uid 89); 24 Nov 2015 10:39:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 24 Nov 2015 10:39:24 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-20-JDuCGsqLTTO-DwV3fAEthA-1; Tue, 24 Nov 2015 10:39:18 +0000 Received: from [10.2.206.200] ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 24 Nov 2015 10:39:17 +0000 Message-ID: <56543E55.7040907@arm.com> Date: Tue, 24 Nov 2015 10:39:17 +0000 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: GCC Patches CC: Richard Biener Subject: [PATCH][cfgloop] PR middle-end/68375: Restructure get_loop_body_in_bfs_order to handle loops with only a header X-MC-Unique: JDuCGsqLTTO-DwV3fAEthA-1 X-IsSubscribed: yes Hi all, The ICE in this PR occurs when trying to dump the CFG to a .dot file. The i > vc assert at the bottom of the loop in get_loop_body_in_bfs_order gets triggered when i == 1 and vc == 1. This is not a problem for that loop because it contains only a header and it's not going to go around the loop again to access uninitialized memory in the blocks array. Richi suggested restructuring the loop to initialise the blocks array with the header early on and moving the assert to the beginning of the loop. This fix works as far as I can test. Bootstrapped and tested on arm, aarch64, x86_64. Ok for trunk? Thanks, Kyrill 2015-11-24 Richard Biener Kyrylo Tkachov PR middle-end/68375 * cfgloop.c (get_loop_body_in_bfs_order): Restructure loop to avoid bogus assertion. 2015-11-24 Kyrylo Tkachov PR middle-end/68375 * gcc.dg/pr68375.c: New test. commit 0e5c74a36e7368e0f55196f5e0cf5d640a051e63 Author: Kyrylo Tkachov Date: Wed Nov 18 16:49:21 2015 +0000 PR middle-end/68375: Restructure get_loop_body_in_bfs_order to handle loops with only a header diff --git a/gcc/cfgloop.c b/gcc/cfgloop.c index bf00e0e..83a5262 100644 --- a/gcc/cfgloop.c +++ b/gcc/cfgloop.c @@ -913,37 +913,32 @@ get_loop_body_in_bfs_order (const struct loop *loop) basic_block *blocks; basic_block bb; bitmap visited; - unsigned int i = 0; - unsigned int vc = 1; + unsigned int i = 1; + unsigned int vc = 0; gcc_assert (loop->num_nodes); gcc_assert (loop->latch != EXIT_BLOCK_PTR_FOR_FN (cfun)); blocks = XNEWVEC (basic_block, loop->num_nodes); visited = BITMAP_ALLOC (NULL); - - bb = loop->header; + blocks[0] = loop->header; + bitmap_set_bit (visited, loop->header->index); while (i < loop->num_nodes) { edge e; edge_iterator ei; - - if (bitmap_set_bit (visited, bb->index)) - /* This basic block is now visited */ - blocks[i++] = bb; + gcc_assert (i > vc); + bb = blocks[vc++]; FOR_EACH_EDGE (e, ei, bb->succs) { if (flow_bb_inside_loop_p (loop, e->dest)) { + /* This bb is now visited. */ if (bitmap_set_bit (visited, e->dest->index)) blocks[i++] = e->dest; } } - - gcc_assert (i > vc); - - bb = blocks[vc++]; } BITMAP_FREE (visited); diff --git a/gcc/testsuite/gcc.dg/pr68375.c b/gcc/testsuite/gcc.dg/pr68375.c new file mode 100644 index 0000000..bbbdd91 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr68375.c @@ -0,0 +1,39 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized-graph" } */ + +int a, c, d, e, g, h; +short f; + +int +foo () +{ +} + +short +fn1 (void) +{ + int j[2]; + for (; e; e++) + if (j[0]) + for (;;) + ; + if (!g) + return f; +} + +int +main (void) +{ + for (; a < 1; a++) + { + for (c = 0; c < 2; c++) + { + d && (f = 0); + h = fn1 (); + } + __builtin_printf ("%d\n", (char) f); + } + + return 0; +} +