From patchwork Wed Jan 11 20:44:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 62962 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 628B53857B98 for ; Wed, 11 Jan 2023 20:44:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 628B53857B98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673469896; bh=usZL3vebiBD9lVhStOCDXSmGPvWPnMR2t9ODc6EYRS8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=HVcI64oTXWamwaFkv26e6mfJD/OvWj91SqyI+D9kj2Ltxip7IqbdrUQKybwLi3d/c aSTqz/Co7pg7VZNLrpxD4loh4nASfQMVZzraSGmS2Wf0XyWEGi2iFkLzXuyxtgoKas hVfJ/auQBn+pSZd1hOjEBC+B/oiY6LBzUztald8k= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id 80A573858C83 for ; Wed, 11 Jan 2023 20:44:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80A573858C83 Received: by mail-il1-x133.google.com with SMTP id d10so8458538ilc.12 for ; Wed, 11 Jan 2023 12:44:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=usZL3vebiBD9lVhStOCDXSmGPvWPnMR2t9ODc6EYRS8=; b=69vPJ7fxstE5pyWFIIkZ25s4ADlVHf+QWqZ1x6YKYp1qZzG751a6mNWKEtfgbOCLp3 QZcUusecOji7NvMwik6oXWNCKqduR1lH7grLZp1sJ6fvWQaqZmanbd+TPrcbhmxKACxw GehW2LEXHtL2sXbky2ZqLHtW+1CXk/K6iQz+RDgJuvhB846p/vFRPuv1UK+7MKzXyN44 stz05KyD/OU5t01qobETn2VQVvX71wx2bKWRvK7RicqUxBO2wWT+VgntZuPCIoygwixT B2UVsgv0bJbVA56UhYWDGrapUdcyTLvDnQQJCSlFcpXfwtniTdwPgQXI5FYBYSgcdZ6Z vgOg== X-Gm-Message-State: AFqh2kodUXxjsG2hBo1SgQ2tXY4kvWsDPGSbjTQmXBSQ4ENyNN7ez3dP cLBD1gRThnG7mmHbp8HkDoE0y1FCVDQvqiN1 X-Google-Smtp-Source: AMrXdXs+pBCM3VUHb4UsyHar8i9DyB24kaz6MMQsBj2qM6u96r5br5uZatKbi2CY62FTEEfcFyP9cw== X-Received: by 2002:a92:d809:0:b0:30c:1b0:fcf6 with SMTP id y9-20020a92d809000000b0030c01b0fcf6mr2561300ilm.7.1673469871761; Wed, 11 Jan 2023 12:44:31 -0800 (PST) Received: from localhost.localdomain (97-122-76-186.hlrn.qwest.net. [97.122.76.186]) by smtp.gmail.com with ESMTPSA id q12-20020a02b04c000000b0039e800fb2a1sm3340657jah.81.2023.01.11.12.44.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jan 2023 12:44:30 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Increase size of main_type::nfields Date: Wed, 11 Jan 2023 13:44:18 -0700 Message-Id: <20230111204418.376620-1-tromey@adacore.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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 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: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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. --- 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; /* * Name of this type, or NULL if none. @@ -964,13 +964,13 @@ struct type /* Get the number of fields of this type. */ int num_fields () const { - return this->main_type->nfields; + return this->main_type->m_nfields; } /* Set the number of fields of this type. */ void set_num_fields (int num_fields) { - this->main_type->nfields = num_fields; + this->main_type->m_nfields = num_fields; } /* Get the fields array of this type. */