From patchwork Fri Mar 27 14:38:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 455424 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 B18B31400A0 for ; Sat, 28 Mar 2015 01:38:38 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=dPLIMJDn; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=i6Ru53pIF+aZJ66LCKHfggKmln/g7gStLKN/OqX0Eq7C4Klx8W3zi WlAiwxLRoOQEaAgLYZoushTet/WbbObW8UFQ6RITCm3g0nm7cuPOv9faVc7C6wnL jz5802+ymYFGpz9QQ2wCnSvlhaO3vq72fj0YJLNBdkT4OKyH3tFixY= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=z+xisPL5fntdvAhAnFdlGL2OX38=; b=dPLIMJDnbqHWkajUHmsy x/m8yxI99mat0+Bc83G75ipblxqv12rHlOfwv86Y5dIxApBjSEnoXxA1G1Am98Nb BIbrejoMyif+rXrkW7D+D7Pkd9/Ikb892L2B3ILHWoX89iIptQkgngFuG60gfv2p zwTyVQgqIOZXjblDnL1tzZk= Received: (qmail 94217 invoked by alias); 27 Mar 2015 14:38:27 -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 94136 invoked by uid 89); 27 Mar 2015 14:38:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham 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; Fri, 27 Mar 2015 14:38:16 +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 (8.14.4/8.14.4) with ESMTP id t2REcEbP010343 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 27 Mar 2015 10:38:15 -0400 Received: from redhat.com (ovpn-204-20.brq.redhat.com [10.40.204.20]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2REcANk009607 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Fri, 27 Mar 2015 10:38:13 -0400 Date: Fri, 27 Mar 2015 15:38:10 +0100 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH for c++/65556 (ICE with switch and bit-fields) Message-ID: <20150327143810.GC25731@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) In this testcase we were crashing while trying to gimplify a switch, because the types of the switch condition and case constants didn't match. This ICE started with my -Wswitch-with-enum-bit-fields fix where I used the unlowered type so that we're able to get hold of the enum type. The problem with that is with ordinary bit-fields: we'll get the underlying type (e.g. long int), but subsequent perform_integral_promotions promotes that to int, see cp_perform_integral_promotions. Fixed by using the type of the condition in case we're not dealing with an enum bit-field, i.e. do what we've been doing before the -Wswitch fix, which ought to make this fix very safe. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2015-03-27 Marek Polacek PR c++/65556 * semantics.c (finish_switch_cond): If the unlowered type is not an enum, use the type of the condition. * c-c++-common/pr65556.c: New test. Marek diff --git gcc/cp/semantics.c gcc/cp/semantics.c index f325e41..74af7e8 100644 --- gcc/cp/semantics.c +++ gcc/cp/semantics.c @@ -1165,6 +1165,8 @@ finish_switch_cond (tree cond, tree switch_stmt) } /* We want unlowered type here to handle enum bit-fields. */ orig_type = unlowered_expr_type (cond); + if (TREE_CODE (orig_type) != ENUMERAL_TYPE) + orig_type = TREE_TYPE (cond); if (cond != error_mark_node) { /* Warn if the condition has boolean value. */ diff --git gcc/testsuite/c-c++-common/pr65556.c gcc/testsuite/c-c++-common/pr65556.c index e69de29..c6729a1 100644 --- gcc/testsuite/c-c++-common/pr65556.c +++ gcc/testsuite/c-c++-common/pr65556.c @@ -0,0 +1,23 @@ +/* PR c++/65556 */ +/* { dg-do compile } */ + +struct S +{ + long l: 1; + long l2: 41; + unsigned long ul: 1; + unsigned long ul2: 41; +} s; + +void +fn () +{ + switch (s.l) + case 0:; + switch (s.ul) + case 0:; + switch (s.l2) + case 0:; + switch (s.ul2) + case 0:; +}