From patchwork Fri Jan 25 12:12:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1031039 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-494725-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="DyvoEEce"; 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 43mHvp610fz9s7T for ; Fri, 25 Jan 2019 23:12:21 +1100 (AEDT) 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=I4A8dee+3mgHrktMagtN0U0bvgF5Eqr1jm4zVWsovyZAkQdDFFd5T VA2WJnaZ72l6HziJc49ZmJ1Ol3QNNzqzw3vvXQjIEHd0jEweyLdXH9IIlamR+2e/ 3k55U9a1nSdcORvvO3ltbMUGIN/zPVVMo91tQWkLiLmF4DlyA1YDQ4= 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=AnUavH4QFv6JIfNsRAjONSEX8+w=; b=DyvoEEceDzLIH9WLoEHW 2xy+u3Ei7YPdink5XeBbrEm1ntan72gXSxhBwQWcyKEINB5H1SZ80rZ6YRoKo3y5 7tTNIBrkTUvsHNIZr9tolU9e818SPPDh44NFU1u8xkefq+FzE2eq5Gj7AFrzTJwA OwpPlyedcStBwndrS9fsHCQ= Received: (qmail 100331 invoked by alias); 25 Jan 2019 12:12:13 -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 100322 invoked by uid 89); 25 Jan 2019 12:12:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 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; Fri, 25 Jan 2019 12:12:11 +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 F1D4EEBD for ; Fri, 25 Jan 2019 04:12:09 -0800 (PST) Received: from localhost (unknown [10.32.99.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 77B0B3F589 for ; Fri, 25 Jan 2019 04:12:09 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Fix output_constructor_bitfield handling of wide bitfields (PR89037) Date: Fri, 25 Jan 2019 12:12:07 +0000 Message-ID: <87ftthueaw.fsf@arm.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 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. Tested on aarch64-linux-gnu, aarch64_be-elf and x86_64-linux-gnu. OK to install? Richard 2019-01-25 Richard Sandiford gcc/ PR middle-end/89037 * varasm.c (output_constructor_bitfield): Use wi::extract_uhwi instead of accessing TREE_INT_CST_ELT directly. gcc/testsuite/ PR middle-end/89037 * gcc.dg/pr89037.c: New test. Index: gcc/varasm.c =================================================================== --- gcc/varasm.c 2019-01-04 11:39:27.182246717 +0000 +++ gcc/varasm.c 2019-01-25 12:10:23.969006336 +0000 @@ -5349,7 +5349,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; @@ -5381,15 +5381,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 { @@ -5406,15 +5404,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-01-24 08:42:49.147091464 +0000 +++ gcc/testsuite/gcc.dg/pr89037.c 2019-01-25 12:10:23.965006370 +0000 @@ -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; +}