From patchwork Wed Jul 26 19:35:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Bergner X-Patchwork-Id: 794107 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-459073-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="TTzMub6L"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xHlhC6HFDz9s5L for ; Thu, 27 Jul 2017 05:35:39 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:cc:date:mime-version:content-type :content-transfer-encoding:message-id; q=dns; s=default; b=Tizcd Fuk9hrUQIXhuFzOEF+CRKZZknUKzz80oh/dWoeMrATywH2wMsbdi+lo86Itbo26p +p4P8LvGgAIfNP0uqykg/WPdPg15RKGQ5DCVaAUYAWdlJ7R65DL/HLQfqfaMJInl mgax8gHkkt8gAcqYPFFU53jKq5k/DK5u35Il1M= 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:to :from:subject:cc:date:mime-version:content-type :content-transfer-encoding:message-id; s=default; bh=OBA5fJBxs2z gCJvzJppJHitaSjc=; b=TTzMub6LB10Vbfioui5EU+3lPJQyx+taw3qlf/Z2uqx Y7l0RGsLvIgJHnpRMeRZSsrfKT3u7EIDDVi5hkMeiNPEOt/lVU0adR2dy5rA+bP0 /E4Vw718AfA3juPjMl3zmXUkETuk4nXqc8kIUmtH+woE7bHwMItToUqSc3QMqoRQ = Received: (qmail 26214 invoked by alias); 26 Jul 2017 19:35:29 -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 26081 invoked by uid 89); 26 Jul 2017 19:35:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 26 Jul 2017 19:35:27 +0000 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v6QJYR9i019135 for ; Wed, 26 Jul 2017 15:35:25 -0400 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0a-001b2d01.pphosted.com with ESMTP id 2bxubdksx9-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 26 Jul 2017 15:35:25 -0400 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 26 Jul 2017 15:35:24 -0400 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 26 Jul 2017 15:35:23 -0400 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v6QJZN9H31195242; Wed, 26 Jul 2017 19:35:23 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C9F1D2803A; Wed, 26 Jul 2017 15:35:16 -0400 (EDT) Received: from otta.local (unknown [9.85.142.203]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP id 8D50F2803D; Wed, 26 Jul 2017 15:35:16 -0400 (EDT) To: GCC Patches From: Peter Bergner Subject: [PATCH] Fix PR middle-end/81564: ICE in group_case_labels_stmt() Cc: Richard Biener Date: Wed, 26 Jul 2017 14:35:22 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17072619-0040-0000-0000-00000386055E X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007430; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00893289; UDB=6.00446572; IPR=6.00673453; BA=6.00005492; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00016393; XFM=3.00000015; UTC=2017-07-26 19:35:24 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17072619-0041-0000-0000-0000077A2497 Message-Id: <07274faa-1ee9-fa6c-57a6-e77ed47a3f7f@vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-07-26_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1706020000 definitions=main-1707260285 X-IsSubscribed: yes The test case for PR81564 exposes an issue where the case labels for a switch statement point to blocks that have already been removed by an earlier call to cleanup_tree_cfg(). In that case, the code in group_case_labels_stmt() that does: base_bb = label_to_block (CASE_LABEL (base_case)); ...returns a NULL base_bb and we SEGV later on when we dereference it: if (EDGE_COUNT (base_bb->succs) == 0 ... The fix here is to just treat case labels that point to blocks that have already been deleted similarly to case labels that point to the default case statement, by removing them. This passed bootstrap and regtesting on powerpc64le-linux with no regressions. Ok for trunk? Peter gcc/ PR middle-end/81564 * tree-cfg.c (group_case_labels_stmt): Handle already deleted blocks. gcc/testsuite/ PR middle-end/81564 * gcc.dg/pr81564.c: New test. Index: gcc/tree-cfg.c =================================================================== --- gcc/tree-cfg.c (revision 250581) +++ gcc/tree-cfg.c (working copy) @@ -1701,8 +1701,9 @@ group_case_labels_stmt (gswitch *stmt) gcc_assert (base_case); base_bb = label_to_block (CASE_LABEL (base_case)); - /* Discard cases that have the same destination as the default case. */ - if (base_bb == default_bb) + /* Discard cases that have the same destination as the default case or + whose destination blocks have already been removed as unreachable. */ + if (base_bb == NULL || base_bb == default_bb) { i++; continue; Index: gcc/testsuite/gcc.dg/pr81564.c =================================================================== --- gcc/testsuite/gcc.dg/pr81564.c (nonexistent) +++ gcc/testsuite/gcc.dg/pr81564.c (working copy) @@ -0,0 +1,21 @@ +/* PR middle-end/81564 ICE in group_case_labels_stmt(). */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +struct a { + int b; + int c; +}; + +void +foo (void) +{ + struct a *e; + switch (e->c) + { + case 7: + case 3: + if (__builtin_expect(!0, 0)) + __builtin_unreachable(); + } +}