From patchwork Mon Apr 29 07:51:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1092458 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-499808-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="yxqMDqW1"; 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 44sxgM1FbLz9sCJ for ; Mon, 29 Apr 2019 17:51:24 +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:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=FZCez4kxnQgkrCx8TdL5ubsRe3ECUl5kqwAqxFP/s90xVLux7gCVG trnrwT1NeCFO+Cyojec7jjc2+CCBpSVmwgRGU6HMRGsHbU2EhfAJc/hx5A3jkeDt dg7ILotnTizJihrby7se7AZpXG/LVrJ1AWQ1YvuNiQ2Su3nBZ2NBNQ= 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:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=3sj/Qwn3IuNEgs1FN/NyW0mMorc=; b=yxqMDqW1l9nvaxhjr1kG wqyHPcEvubp39xx86X3DMlLPbU4QC3m7ZeOcxHOa46e7rDvrA+SoocSTt8iPxkhj slC2RPbNoAjOjlIz/4v3/VhrmUoOMC8+21+mxhL90vXSe4IiaqxS0KKq6cWIxBKj UnY3SwzvTfwnlyhzpPpryPI= Received: (qmail 15088 invoked by alias); 29 Apr 2019 07:51:17 -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 14492 invoked by uid 89); 29 Apr 2019 07:51:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-6.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT autolearn=ham version=3.3.1 spammy= X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 29 Apr 2019 07:51:15 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8EEF6EBD for ; Mon, 29 Apr 2019 00:51:13 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.39]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 10D283F71A for ; Mon, 29 Apr 2019 00:51:12 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Backport fix for PR89037 Date: Mon, 29 Apr 2019 08:51:11 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 It's not obvious from the PR whether this is a regression, so I'm not sure whether it deserves to be backported or not. Just in case... Tested on aarch64-linux-gnu, aarch64_be-elf and x86_64-linux-gnu. OK for gcc-8-branch and gcc-7-branch? If not, should I close the PR? Thanks, Richard The testcase was failing because we were trying to access TREE_INT_CST_ELT (x, 1) of a 128-bit integer that was small enough to need only a single element. 2019-04-29 Richard Sandiford gcc/ Backport from mainline: 2019-01-25 Richard Sandiford PR middle-end/89037 * varasm.c (output_constructor_bitfield): Use wi::extract_uhwi instead of accessing TREE_INT_CST_ELT directly. gcc/testsuite/ Backport from mainline: 2019-01-25 Richard Sandiford PR middle-end/89037 * gcc.dg/pr89037.c: New test. Index: gcc/varasm.c =================================================================== --- gcc/varasm.c 2019-04-29 08:40:40.141347619 +0100 +++ gcc/varasm.c 2019-04-29 08:44:12.736632535 +0100 @@ -5292,7 +5292,7 @@ output_constructor_bitfield (oc_local_st { int this_time; int shift; - HOST_WIDE_INT value; + unsigned HOST_WIDE_INT value; HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT; HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT; @@ -5324,15 +5324,13 @@ output_constructor_bitfield (oc_local_st this_time = end - shift + 1; } - /* Now get the bits from the appropriate constant word. */ - value = TREE_INT_CST_ELT (local->val, shift / HOST_BITS_PER_WIDE_INT); - shift = shift & (HOST_BITS_PER_WIDE_INT - 1); + /* Now get the bits we want to insert. */ + value = wi::extract_uhwi (wi::to_widest (local->val), + shift, this_time); /* Get the result. This works only when: 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */ - local->byte |= (((value >> shift) - & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1)) - << (BITS_PER_UNIT - this_time - next_bit)); + local->byte |= value << (BITS_PER_UNIT - this_time - next_bit); } else { @@ -5349,15 +5347,13 @@ output_constructor_bitfield (oc_local_st this_time = HOST_BITS_PER_WIDE_INT - (shift & (HOST_BITS_PER_WIDE_INT - 1)); - /* Now get the bits from the appropriate constant word. */ - value = TREE_INT_CST_ELT (local->val, shift / HOST_BITS_PER_WIDE_INT); - shift = shift & (HOST_BITS_PER_WIDE_INT - 1); + /* Now get the bits we want to insert. */ + value = wi::extract_uhwi (wi::to_widest (local->val), + shift, this_time); /* Get the result. This works only when: 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */ - local->byte |= (((value >> shift) - & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1)) - << next_bit); + local->byte |= value << next_bit; } next_offset += this_time; Index: gcc/testsuite/gcc.dg/pr89037.c =================================================================== --- /dev/null 2019-03-08 11:40:14.606883727 +0000 +++ gcc/testsuite/gcc.dg/pr89037.c 2019-04-29 08:44:12.732632549 +0100 @@ -0,0 +1,24 @@ +/* { dg-do run { target int128 } } */ +/* { dg-options "" } */ + +struct s +{ + __int128 y : 66; +}; +typedef struct s T; +T a[] = { 1, 10000, 0x12345, 0xff000001, 1ULL << 63, (__int128) 1 << 64, + ((__int128) 1 << 64) | 1 }; + +int +main (void) +{ + if (a[0].y != 1 + || a[1].y != 10000 + || a[2].y != 0x12345 + || a[3].y != 0xff000001 + || a[4].y != (1ULL << 63) + || a[5].y != ((__int128) 1 << 64) + || a[6].y != (((__int128) 1 << 64) | 1)) + __builtin_abort (); + return 0; +}