From patchwork Mon Mar 21 21:12:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 600358 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 3qTT7T27DBz9s3T for ; Tue, 22 Mar 2016 08:12:52 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=VXNacnNh; 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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=q9WKc51EO3t0SBNo2GsL0G0tacFZUObLhOZ2ToFF9kNVfnhrBe WWeYR28rF6yHT5gDWrCXY2eBa/89zWHttxlXcvY4e3tTTM6lQmxY9hDBbgv/NtSS nvBNQoQ6LhxMo245gTxNgZttBdU7iyfnuFT0oyyvy0/bmtdxsADaUDuJA= 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:message-id:date:mime-version:content-type; s= default; bh=L3BaDP4tDlvJOtPtrWLxgLym1JM=; b=VXNacnNhtYC7yfiD/NV4 +eQbmHPBPC4oGyfhZfFk6t668WTqWlnY8hdLliGsHRj5by8tR2bGRdQ/UK65BhwI yzNXwvs04UFdZj+p5Yt79mokqbXMgtOwOo2hpl8tCktqNALJz26A34x0cvuoK/OP 3QiOewVOslupgqE/Ig5LXq0= Received: (qmail 57423 invoked by alias); 21 Mar 2016 21:12:43 -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 57378 invoked by uid 89); 21 Mar 2016 21:12:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1365 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; Mon, 21 Mar 2016 21:12:41 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 40091C00B8D8 for ; Mon, 21 Mar 2016 21:12:40 +0000 (UTC) Received: from [10.3.113.58] (ovpn-113-58.phx2.redhat.com [10.3.113.58]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2LLCdNU015177 for ; Mon, 21 Mar 2016 17:12:39 -0400 To: gcc-patches List From: Jason Merrill Subject: C++ PATCH for c++/70285 (verify_gimple ICE with ?: and bit-field) Message-ID: <56F063C7.5090107@redhat.com> Date: Mon, 21 Mar 2016 17:12:39 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 The C++ front end builds COND_EXPR where the arms can have a different type from the combined expression, if they are bit-fields. cp_genericize_r already fixes this up, but now cp_fold needs to handle it too. Tested x86_64-pc-linux-gnu, applying to trunk. commit c1b91b53f85c8a00c5067dbfc15f5fb0da7da4f6 Author: Jason Merrill Date: Mon Mar 21 15:54:51 2016 -0400 PR c++/70285 * cp-gimplify.c (cp_fold) [COND_EXPR]: Handle bit-fields. diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 6a767fa..9bf2482 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -2130,6 +2130,12 @@ cp_fold (tree x) else x = fold (x); + /* A COND_EXPR might have incompatible types in branches if one or both + arms are bitfields. If folding exposed such a branch, fix it up. */ + if (TREE_CODE (x) != code) + if (tree type = is_bitfield_expr_with_lowered_type (x)) + x = fold_convert (type, x); + break; case CALL_EXPR: diff --git a/gcc/testsuite/g++.dg/other/bitfield5.C b/gcc/testsuite/g++.dg/other/bitfield5.C new file mode 100644 index 0000000..b8cd4dd --- /dev/null +++ b/gcc/testsuite/g++.dg/other/bitfield5.C @@ -0,0 +1,15 @@ +// PR c++/70285 + +int a; + +struct S +{ + int i:8; +} b; + +int +fn1 (bool x) +{ + (&fn1 ? b.i : a) = 42; + return (&fn1 ? b.i : a); +}