From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 0DF503858C83 for ; Wed, 11 Jan 2023 21:02:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0DF503858C83 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [10.0.0.11] (unknown [217.28.27.60]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id BC6861E110; Wed, 11 Jan 2023 16:02:55 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1673470975; bh=1SMNrWIILmZlPka6ihZoPDG0QNKbmJ897nWmIg3RmQ0=; h=Date:Subject:To:References:From:In-Reply-To:From; b=otnMPF/WCqyRvzPN9qH0PMNQV4caWH/4Mpps6dIdBMNKWiAZV5kMejznCq3XimJxA nNU45BIdjrZQn8uec/XwLNg/A/BhEoveBSCN+Hz66PbqlZlvRQrvlXtwsXqnhCOpvE FZ1dOn+lJh2ajAOLMwQE9bjX1YEq/rBKGDSRJaAY= Message-ID: <061d47f1-fbe7-4d2f-6919-811061d0be9b@simark.ca> Date: Wed, 11 Jan 2023 16:02:55 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH] Increase size of main_type::nfields Content-Language: en-US To: Tom Tromey , gdb-patches@sourceware.org References: <20230111204418.376620-1-tromey@adacore.com> From: Simon Marchi In-Reply-To: <20230111204418.376620-1-tromey@adacore.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 1/11/23 15:44, Tom Tromey via Gdb-patches wrote: > main_type::nfields is a 'short', and has been for many years. PR > c++/29985 points out that 'short' is too narrow for an enum that > contains more than 2^15 constants. > > This patch bumps the size of 'nfields'. To verify that the field > isn't directly used, it is also renamed. Note that this does not > affect the size of main_type on x86-64 Fedora 36. And, if it does > have a negative effect somewhere, it's worth considering that types > could be shrunk more drastically by using subclasses for the different > codes. > > I wasn't sure whether a test case for this would be desirable. It > would be a bit large. We could make a test case that generates a source file on the fly in standard_output_directory and compiles it. > --- > gdb/gdb-gdb.py.in | 4 ++-- > gdb/gdbtypes.h | 6 +++--- > 2 files changed, 5 insertions(+), 5 deletions(-) > > diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in > index dbc4d773e0b..95b7d84966f 100644 > --- a/gdb/gdb-gdb.py.in > +++ b/gdb/gdb-gdb.py.in > @@ -261,8 +261,8 @@ class StructMainTypePrettyPrinter: > fields.append("flags = [%s]" % self.flags_to_string()) > fields.append("owner = %s" % self.owner_to_string()) > fields.append("target_type = %s" % self.val["m_target_type"]) > - if self.val["nfields"] > 0: > - for fieldno in range(self.val["nfields"]): > + if self.val["m_nfields"] > 0: > + for fieldno in range(self.val["m_nfields"]): > fields.append(self.struct_field_img(fieldno)) > if self.val["code"] == gdb.TYPE_CODE_RANGE: > fields.append(self.bounds_img()) > diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h > index a9abb0d8071..da1d0f79d1f 100644 > --- a/gdb/gdbtypes.h > +++ b/gdb/gdbtypes.h > @@ -836,7 +836,7 @@ struct main_type > /* * Number of fields described for this type. This field appears > at this location because it packs nicely here. */ > > - short nfields; > + int m_nfields; Should it be unsigned? I don't recall this field needing to be negative. Otherwise, LGTM. Simon