From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id WcdHIKCOd2kePhYAWB0awg (envelope-from ) for ; Mon, 26 Jan 2026 10:56:16 -0500 Received: by simark.ca (Postfix, from userid 112) id 7CE691E0AD; Mon, 26 Jan 2026 10:56:16 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 0BD401E08D for ; Mon, 26 Jan 2026 10:56:16 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 7D1914BC896C for ; Mon, 26 Jan 2026 15:56:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D1914BC896C Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 437E74BC8987 for ; Mon, 26 Jan 2026 15:55:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 437E74BC8987 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 437E74BC8987 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769442952; cv=none; b=H6JjIUq3GCfyCAHWGx8zpvZ7SeIy+ZypPMeDovdsSvYOf4lQmhR6IKL0iVmH8tF3RtcUljoDDFEc96EJzFZQ/ewE4Zw6fQz2M1foeOaUzTAMKTy+sVa1PAbxL+4ofx+99JLqycZs0MFRrjnK4TVuBJEYDiuY6km5z7B8nICNVtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769442952; c=relaxed/simple; bh=vq/C8fFScBOWIcerCaqHI1EsaNeLfO/YyRIu/pQo9FM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ji7Vs7JmRgntNoe34iY5NuBg8MoEQ9kUqtriSSRzJLRNl2+9ZbYA+3tNzW859AqtVxR/Qez1hoMEBiJiTIlZPCsuBB4/325kglASZ25A0u8EhsY2jhpdEo+tV2VMCZFZOxDd4rrBskM1blRsYpYT0MpU2MZ4jCU4EyY4EWXv5mo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 437E74BC8987 Received: by simark.ca (Postfix) id B1CAB1E08D; Mon, 26 Jan 2026 10:55:51 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb: tighten assertions in set_type_vptr_* Date: Mon, 26 Jan 2026 10:54:00 -0500 Message-ID: <20260126155550.122509-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.52.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Simon Marchi In C++, only structures and classes (represented by TYPE_CODE_STRUCT) can participate in inheritance. I therefore think it does not make sense to allow for TYPE_CODE_UNION in set_type_vptr_basetype and set_type_vptr_fieldno. Remove the possibility for the type to be a union in these functions. Also, for the same reason, add an assertion that checks the type of basetype in set_type_vptr_basetype. I did not change the getters (internal_type_vptr_fieldno and internal_type_vptr_basetype), because it seems like they are called by code that handles similarly both structures and unions. Making those stricter would require adding conditions in those callers, which doesn't look like an improvement. For unions, they will correctly return an "invalid" value. Change allocate_cplus_struct_type to not use set_type_vptr_fieldno to initialize the field to -1, otherwise it would trip the assertion when initializing for a union type. Change-Id: Id9b2dc288f24d50eb50da46782b5ec6de5682e81 --- gdb/gdbtypes.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 75404d00e1ac..bd9abc7e7004 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -1805,8 +1805,7 @@ void set_type_vptr_fieldno (struct type *type, int fieldno) { type = check_typedef (type); - gdb_assert (type->code () == TYPE_CODE_STRUCT - || type->code () == TYPE_CODE_UNION); + gdb_assert (type->code () == TYPE_CODE_STRUCT); if (!HAVE_CPLUS_STRUCT (type)) ALLOCATE_CPLUS_STRUCT_TYPE (type); TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_fieldno = fieldno; @@ -1831,8 +1830,8 @@ void set_type_vptr_basetype (struct type *type, struct type *basetype) { type = check_typedef (type); - gdb_assert (type->code () == TYPE_CODE_STRUCT - || type->code () == TYPE_CODE_UNION); + gdb_assert (type->code () == TYPE_CODE_STRUCT); + gdb_assert (check_typedef (basetype)->code () == TYPE_CODE_STRUCT); if (!HAVE_CPLUS_STRUCT (type)) ALLOCATE_CPLUS_STRUCT_TYPE (type); TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_basetype = basetype; @@ -3320,7 +3319,7 @@ allocate_cplus_struct_type (struct type *type) TYPE_RAW_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *) TYPE_ZALLOC (type, sizeof (struct cplus_struct_type)); *(TYPE_RAW_CPLUS_SPECIFIC (type)) = cplus_struct_default; - set_type_vptr_fieldno (type, -1); + TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_fieldno = -1; } const struct gnat_aux_type gnat_aux_default = base-commit: 6660ba84d5484a51e09985c741091152f9febe5c -- 2.52.0