From patchwork Sat Jan 21 00:37:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 137130 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]) by ozlabs.org (Postfix) with SMTP id 41052B6F9A for ; Sat, 21 Jan 2012 11:37:46 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1327711067; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Subject:Message-ID: Mail-Followup-To:MIME-Version:Content-Type:Content-Disposition: User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=4zYnZAD UA88lulqc8Pb0B99rs0U=; b=vnkKzKtXCmuLpfTnkEJlhXVco65BlwT4CsRlUzk +oX97t+hcHMWtTDZ/1ZKYVpsF06Iu0mfP6rt4N1rIwkTy7wSvPYQrv5P1EMg7R/d 3gqYktuex3QJJHqgVJUzgxGTG33PAg7YmzyEXPo3F9QqsHKT30Lw6aB4R9pXdwkd Bl+A= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Subject:Message-ID:Mail-Followup-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=mnBiaNxuX39NNoHNBEs/5e0pOsd2ZaiquMLcwEl+7EQvvn1PgJyfdyscFwn3ib b1z7qpJM55mO2uI0CH4Rr+w7S/TUdm2Su+3JdXYXcTNSELM4aHRPn/phL+V9dqhU Z5nn7Jp3uprffkhuwyRXFkEbUJUk/eumrw3TRI9s/Fjdg=; Received: (qmail 10461 invoked by alias); 21 Jan 2012 00:37:43 -0000 Received: (qmail 10448 invoked by uid 22791); 21 Jan 2012 00:37:41 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-yw0-f47.google.com (HELO mail-yw0-f47.google.com) (209.85.213.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 21 Jan 2012 00:37:18 +0000 Received: by yhfq46 with SMTP id q46so571855yhf.20 for ; Fri, 20 Jan 2012 16:37:17 -0800 (PST) Received: by 10.236.145.33 with SMTP id o21mr48503321yhj.56.1327106237661; Fri, 20 Jan 2012 16:37:17 -0800 (PST) Received: from bubble.grove.modra.org ([115.187.252.19]) by mx.google.com with ESMTPS id q5sm8181675yhm.7.2012.01.20.16.37.15 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 20 Jan 2012 16:37:16 -0800 (PST) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id C14A9170C2EA; Sat, 21 Jan 2012 11:07:10 +1030 (CST) Date: Sat, 21 Jan 2012 11:07:10 +1030 From: Alan Modra To: gcc-patches@gcc.gnu.org Subject: FIX PR51926, libstdc++ iterator store bigendian bitfield related Message-ID: <20120121003710.GU3708@bubble.grove.modra.org> Mail-Followup-To: gcc-patches@gcc.gnu.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes 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 This patch fixes a wrong-code bug in store_bit_field. When storing a multi-word BLKmode value (such as from a RECORD_TYPE), the last word is trashed on big-endian targets. See the PR for the gory details. Bootstrapped and regression tested powerpc64-linux. Fixes 74 testsuite failures. OK for mainline? And earlier versions of gcc? PR middle-end/51926 * expmed.c (store_bit_field_1): Properly handle last word of BLKmode value when bigendian. Index: gcc/expmed.c =================================================================== --- gcc/expmed.c (revision 183228) +++ gcc/expmed.c (working copy) @@ -551,19 +551,27 @@ store_bit_field_1 (rtx str_rtx, unsigned /* If I is 0, use the low-order word in both field and target; if I is 1, use the next to lowest word; and so on. */ unsigned int wordnum = (backwards ? nwords - i - 1 : i); + unsigned int nbits = (i == nwords - 1 + ? bitsize - i * BITS_PER_WORD + : BITS_PER_WORD); unsigned int bit_offset = (backwards - ? MAX ((int) bitsize - ((int) i + 1) - * BITS_PER_WORD, - 0) - : (int) i * BITS_PER_WORD); + ? bitsize - i * BITS_PER_WORD - nbits + : i * BITS_PER_WORD); rtx value_word = operand_subword_force (value, wordnum, fieldmode); - if (!store_bit_field_1 (op0, MIN (BITS_PER_WORD, - bitsize - i * BITS_PER_WORD), - bitnum + bit_offset, + if (WORDS_BIG_ENDIAN && !backwards && nbits != BITS_PER_WORD) + { + /* Original fieldmode was BLKmode. The value in this + case consists of bits in memory order, so any unused + bits in the last word are in the least significant + position. */ + value_word = expand_shift (RSHIFT_EXPR, word_mode, value_word, + BITS_PER_WORD - nbits, + value_word, 1); + } + if (!store_bit_field_1 (op0, nbits, bitnum + bit_offset, bitregion_start, bitregion_end, - word_mode, - value_word, fallback_p)) + word_mode, value_word, fallback_p)) { delete_insns_since (last); return false;