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: 87291 Delivered-To: patch@linaro.org Received: by 10.182.112.6 with SMTP id im6csp962274obb; Thu, 8 Dec 2016 08:39:06 -0800 (PST) X-Received: by 10.98.85.198 with SMTP id j189mr73800028pfb.182.1481215146726; Thu, 08 Dec 2016 08:39:06 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id q71si29557284pfj.175.2016.12.08.08.39.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Dec 2016 08:39:06 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-443799-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; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-443799-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-443799-patch=linaro.org@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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=jxtnySarrj1iHCqtL/dZIOSTPjfnxdPmQucnAxDUEYWB+8CuxT bT8cOpb3ZGZ4t5tOG67B7NL/o97y1DT6+NTpvTwWvMhNiqJtEk1hka+VXFMWBbgv zeWgmUZH4/5rXYBYhJDoryTrF62jcFEm77O1BZ2rIB3IyTOBIejn1abuc= 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=UfuSYHJv2Iwgw2zHZPCa VwxE8YU3Jalwq4Ez/xCe8b7343aiw+A38diydld7Qxd927AWLzT3vYQp1qx9nPuY GC1mmrqjMEkZ3uYCN8lWQn6oo4ntjnaW8FIKCnFwpIOOAEzKwjG0iOYxzlbMNv6l 54L3Z0DZxvRQjPqf1NIWqoo= 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 -- Nathan Sidwell 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}};