From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 67o+KT7Cw18HCwAAWB0awg (envelope-from ) for ; Sun, 29 Nov 2020 10:46:06 -0500 Received: by simark.ca (Postfix, from userid 112) id 856281F0AD; Sun, 29 Nov 2020 10:46:06 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 1B30E1E552 for ; Sun, 29 Nov 2020 10:46:06 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 66DDB385EC58; Sun, 29 Nov 2020 15:46:04 +0000 (GMT) Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTP id B394E385040C for ; Sun, 29 Nov 2020 15:46:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B394E385040C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=brobecke@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 61C8D5616D; Sun, 29 Nov 2020 10:46:01 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 175ZQnGePv4u; Sun, 29 Nov 2020 10:46:01 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 5098256171; Sun, 29 Nov 2020 10:46:01 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4233) id 4DD9FAD; Sun, 29 Nov 2020 10:46:01 -0500 (EST) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [RFA 1/2] Fix TARGET_CHAR_BIT/HOST_CHAR_BIT confusion in gmp-utils.c Date: Sun, 29 Nov 2020 10:45:56 -0500 Message-Id: <1606664757-144138-2-git-send-email-brobecker@adacore.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1606664757-144138-1-git-send-email-brobecker@adacore.com> References: <20201123042711.GA967337@adacore.com> <1606664757-144138-1-git-send-email-brobecker@adacore.com> X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Simon Marchi , Joel Brobecker Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" In a couple of gdb_mpz methods, we are computing the number of bits in a gdb::array_view of gdb_byte. Since gdb_byte is defined using a host-side type (see common-types.h), the number of bits in a gdb_byte should be HOST_CHAR_BIT, not TARGET_CHAR_BIT. gdb/ChangeLog: * gmp-utils.c (gdb_mpz::read): Use HOST_CHAR_BIT instead of TARGET_CHAR_BIT. (gdb_mpz::write): Likewise. --- gdb/gmp-utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gdb/gmp-utils.c b/gdb/gmp-utils.c index 7994108..e3a3333 100644 --- a/gdb/gmp-utils.c +++ b/gdb/gmp-utils.c @@ -56,7 +56,7 @@ gdb_mpz::read (gdb::array_view buf, enum bfd_endian byte_order, was in fact negative, we need to adjust VAL accordingly. */ gdb_mpz max; - mpz_ui_pow_ui (max.val, 2, buf.size () * TARGET_CHAR_BIT - 1); + mpz_ui_pow_ui (max.val, 2, buf.size () * HOST_CHAR_BIT - 1); if (mpz_cmp (val, max.val) >= 0) mpz_submul_ui (val, max.val, 2); } @@ -77,7 +77,7 @@ gdb_mpz::write (gdb::array_view buf, enum bfd_endian byte_order, would be the same as our negative value. */ gdb_mpz neg_offset; - mpz_ui_pow_ui (neg_offset.val, 2, buf.size () * TARGET_CHAR_BIT); + mpz_ui_pow_ui (neg_offset.val, 2, buf.size () * HOST_CHAR_BIT); mpz_add (exported_val.val, exported_val.val, neg_offset.val); } -- 2.1.4