From patchwork Thu Dec 8 16:38:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 704119 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 3tZLfd5Z8Wz9vGh for ; Fri, 9 Dec 2016 03:39:02 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="my/BeOgC"; 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=BhOf/v56dcQcd9iE18H/6WF3gxw7aQ5dh3Mz0KYpfozX6E/1tV FXXdiH2p9i2fiiNeuiZ9XR0m4mki/8lE8y1hi69UWmj41UAJc/gs4G6nILp0wOKF mzVq4o9h2ZgRbPvXrEffWTz/1IGDFfJ0blRmkaI4q7AK6gqcqmEzQeOkY= 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=sbwOPz2kFM9qXMOHmFgAnYk3LUk=; b=my/BeOgCHJBqv4U6TBUX PuMwTxm3u3REcwnifZ9cfmarCuu5PbetBXNvYu8HoWyk972zGbBEoLxwetWHciKP c1taqFymJmLWp91W1X2Jvsi/u3KVd51rHmAczfw+taxtVmII9GOv171WoRrG1zYv qsXvMcx+m0z3NyNcBwq+yMg= Received: (qmail 102132 invoked by alias); 8 Dec 2016 16:38:52 -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 102123 invoked by uid 89); 8 Dec 2016 16:38:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=distribute, longs X-HELO: mail-yw0-f194.google.com Received: from mail-yw0-f194.google.com (HELO mail-yw0-f194.google.com) (209.85.161.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 08 Dec 2016 16:38:41 +0000 Received: by mail-yw0-f194.google.com with SMTP id a10so35041508ywa.1 for ; Thu, 08 Dec 2016 08:38:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version; bh=NPbGEBc3tcUWfYNUS4OHNU4UJTYQuDsNKbtDMBO15OI=; b=Pj7I5o310ofdSZldYwUg30GtSHXAum53jiaulumueXEF7CCQKB/TMF0QNu94Jc+7oL 9SXV+/WjM/kvb1cuiVHP7yp8usnqI/eBVrs4pSMQ3/zOHmKcmJQz6Z65wAbl4eMfB1K0 +6bCt0sDEXbQ6HyrWbLa+h53D4euY9nLYl7WtA1E6fMDxDRjNH9gm1WaaNxAnnhLzVeD P8drZ/qTuNxo0eUcU/AwWJlpXrruqTJcR4JCgnXiSwMDld8XiQ6HXSjenGIxN1neltES 7eKMNr/h2OSxzoQDlRoO/MQbgFiM9MImds+BBHPF7En+92hjimR/jjV7LCx0bi6raSmI mmjQ== X-Gm-Message-State: AKaTC0252emEM6IkxWJSV+v8OZq8IAkz96gZ6eZ/aWoKC2L/aCCYRC/Wz39Fh5PpUxnneQ== X-Received: by 10.37.218.11 with SMTP id n11mr8475513ybf.3.1481215119935; Thu, 08 Dec 2016 08:38:39 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::a:6eb0]) by smtp.googlemail.com with ESMTPSA id y125sm2609391ywy.53.2016.12.08.08.38.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Dec 2016 08:38:39 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: [PATCH] Fix 78550 ICE with bit-field initialization Message-ID: <470fb13a-9eae-bca1-d6a8-25bd55a35ab2@acm.org> Date: Thu, 8 Dec 2016 11:38:37 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 This patch fixes 78550, where we ICE in varasm as we discover a code-generating NOP_EXPR of an INTEGER_CST. output_constructor (varasm.c) has a STRIP_NOPs, but that leaves the NOP alone, as it is truncating a regular QI mode operand to a 1 bit type. That tree is generated in convert.c: /* If TYPE is an enumeral type or a type with a precision less than the number of bits in its mode, do the conversion to the type corresponding to its mode, then do a nop conversion to TYPE. */ .... return fold_build1_loc (dofold, loc, NOP_EXPR, type, ...); } Fixed by changing it to maybe_fold_build1_loc. Surrounding code uses that function. ok? nathan 2016-12-08 Nathan Sidwell PR c++/78550 * convert.c (convert_to_integer_1): Maybe fold conversions to integral types with fewer bits than its mode. testsuite/ PR c++/78550 * g++.dg/cpp1y/pr78550.C: New. Index: convert.c =================================================================== --- convert.c (revision 243438) +++ convert.c (working copy) @@ -646,10 +646,11 @@ convert_to_integer_1 (tree type, tree ex to TYPE. */ else if (TREE_CODE (type) == ENUMERAL_TYPE || outprec != GET_MODE_PRECISION (TYPE_MODE (type))) - return build1 (NOP_EXPR, type, - convert (lang_hooks.types.type_for_mode - (TYPE_MODE (type), TYPE_UNSIGNED (type)), - expr)); + { + expr = convert (lang_hooks.types.type_for_mode + (TYPE_MODE (type), TYPE_UNSIGNED (type)), expr); + return maybe_fold_build1_loc (dofold, loc, NOP_EXPR, type, expr); + } /* Here detect when we can distribute the truncation down past some arithmetic. For example, if adding two longs and converting to an Index: testsuite/g++.dg/cpp1y/pr78550.C =================================================================== --- testsuite/g++.dg/cpp1y/pr78550.C (revision 0) +++ testsuite/g++.dg/cpp1y/pr78550.C (working copy) @@ -0,0 +1,22 @@ +// { dg-do compile { target c++14 } } + +// PR 78550 ICE with initializer_list and bitfield member + +namespace std +{ + template + struct initializer_list + { + const T *a; + __SIZE_TYPE__ b; + constexpr initializer_list (const T *x, __SIZE_TYPE__ y) : a(x), b(y) { } + }; +} +template +struct A { + A (std::initializer_list); +}; +struct B { + int k : 1; +}; +A a{{0}};