From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 47sTFhoWa2o4gzQAWB0awg (envelope-from ) for ; Thu, 30 Jul 2026 05:15:06 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=bvkXesF6; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 44E791E09E; Thu, 30 Jul 2026 05:15:06 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,WEIRD_PORT autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 119981E099 for ; Thu, 30 Jul 2026 05:15:05 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5329F4B92094 for ; Thu, 30 Jul 2026 09:15:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5329F4B92094 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=bvkXesF6 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazlp170100005.outbound.protection.outlook.com [IPv6:2a01:111:f403:c111::5]) by sourceware.org (Postfix) with ESMTPS id 5C32F4BA79A5 for ; Thu, 30 Jul 2026 09:14:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C32F4BA79A5 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=amd.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5C32F4BA79A5 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:c111::5 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1785402876; cv=pass; b=TLPpuFG72l4WfBCFOl208bjM9bsIgUXkqdIviL7x1/rYptqXfp11U6MMpjE96vQ9TZHJ2KdOvS2Y8WatHOQNNHCMlVSf2geKh6hQLFH0m0gojhtjdC+8myTX7ZjMHHXeIgt64miX7uXpFMsGKtK1hdY5MyBR+jQ+Y2q516lTfuM= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1785402876; c=relaxed/simple; bh=Flb0/kRxJmu7IwGNTNn1o5sBZCU6UUqx/+30/V//Fp8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jv+BBt0MXDyOceCfMRnqB7GfW4SIBDQqviea4t57v8ECD8a0Bs32P0wfu9rMy/Hg/eedHHIhagH3o5zqsNFCepMwXxyCSomqi+mrGB125zU6v/gmUCv/VCUBZizRwuWc+5kOU4tg5cFLAvqkM40gf82mUKt6itrDZLIjTEgmCGg= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=bvkXesF6 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C32F4BA79A5 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=w95XDQv2PpwycnirVon8Qr+sZtJiON6dv860QZrn0Wc/S5GxUFaDnDy6sxziXJ9bm+WOGD4rbLNMVPtzpzYBTc41WYhFF5QKdGZxwdHuGErZ6NtdmUJC4VC3EDOgjwuShQZvgF+UFLKpywK6AuF39r5g4Qss8BN8qeDfcKHtmhzIi50TKpcR3ytbnenZ8O+DxKrzBa9z0sNasA4fV9mWpEACB/raBb2FYAzCaYqEv3Zv4YCIYlsJNQpVBkDe2fLFQrYEcU554AG4Esp1NsSH6ObV9lY0etEz+wipFQh5J0Vi7QDvrQAF3nn+GTsESfnngR9ocjo7cKO7NKyksPQvSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gZO6jntHEUUAeasVZm+7KzWnCU6YqDw0by1NL3ALorE=; b=aKsXcXBD54xGTNFbKkWkqgc2QRG8p5Dfa/2zFXSvOEBth8FXN3zpIT9UaLBpeY/9IWWoMvCwvrKkoV7u0fa2R8MTloGDoF1BFfZaP4KsgOmRREBZwkgcTNbzzq9tMihkwRkiiEIyYXV8Hj/sHeX6J6IhXSz/beXCCHmfMJvVcDI+QqhJ15+npNMK8zap6z0ySa6WQb850ibAgC4Yak5vKQAYYaw4UV7i1ipwY7f1SuquXauXFrO23p1GVg1lXTkPBQzrgElicZ4EJP3+AK25ZgDnoeTYlmvh8TFxft8s660Q6ZICMSBSVinEIH/D0T/jgjTDyYMCdMrXjh3PrmDimw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sourceware.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gZO6jntHEUUAeasVZm+7KzWnCU6YqDw0by1NL3ALorE=; b=bvkXesF6dFYCb6w6C4q/etPlThcIsc256huExXlczsTPQUra4VI1oE+2RFoWwQxA5/fqT+WlmsB1f9wCBwzTXVBM4d0R4DgN92AYtV8apI1kNOanS2Tlm1zzY8zz273P966eLhE4SID4HsiNlV9yWzBlZth/Q1Q899WjIWaU6mY= Received: from MN2PR01CA0047.prod.exchangelabs.com (2603:10b6:208:23f::16) by SJ2PR12MB9088.namprd12.prod.outlook.com (2603:10b6:a03:565::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.15; Thu, 30 Jul 2026 09:14:30 +0000 Received: from BL6PEPF0001AB57.namprd02.prod.outlook.com (2603:10b6:208:23f:cafe::43) by MN2PR01CA0047.outlook.office365.com (2603:10b6:208:23f::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.270.12 via Frontend Transport; Thu, 30 Jul 2026 09:14:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BL6PEPF0001AB57.mail.protection.outlook.com (10.167.241.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.8 via Frontend Transport; Thu, 30 Jul 2026 09:14:29 +0000 Received: from rocgdb-taktemur.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Thu, 30 Jul 2026 04:14:28 -0500 From: Tankut Baris Aktemur To: CC: , Subject: [PATCH v2] gdb: prefer lhs type's address spaces/classes in check_typedef Date: Thu, 30 Jul 2026 09:13:57 +0000 Message-ID: <20260730091357.2528178-1-tankutbaris.aktemur@amd.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260727092001.1683349-1-tankutbaris.aktemur@amd.com> References: <20260727092001.1683349-1-tankutbaris.aktemur@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB57:EE_|SJ2PR12MB9088:EE_ X-MS-Office365-Filtering-Correlation-Id: 51ce4aba-472c-455a-f6e6-08deee1af5da X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|23010399003|1800799024|82310400026|36860700016|376014|13003099007|18002099003|22082099003|10067099003|11063799006|56012099006; X-Microsoft-Antispam-Message-Info: 5pH6BH+QVCyVK6xigc5kvDDrWevkjyYrn2+hBbd7giGt+dxjo8YVEvoFWsB9+jO6WvkIKavtxjoGSnhPcl5BXgbnuOX3uV8F1c+Jh56tkbEmkjw8ewKmntduQ9JSeHsguIkumLLr6cpFLVJakE7BCRrNvNLKABIwnxOSwTfjiwTYhp9y+WUmFlktEAEU9g7C6n1xJqwlya9hnhPHTkP1CMI4GDT+DZSRum9ONmbTBTvfpBwJWtzphQMFxSaCa/77F0sR9gpLJSvxyVJk4tZ8ny29OD4WzEdVZh9XCXcqarhaooIOQoUU3YfYtvVy3vZggJSvQTYeLvGNGJdYTHvLEDHjrJA5smZtceoQN1BrDym/7Y5Ud/u2xt0YmopkIEyk16ev8MkwvPCvAX2GG3zG3M3xnR50dDPZf+3DfzKyD2GmvixYQ6CxoxhxAtTiz3VG1r+xHqkAO8xeZbqY19hpKct7zDhZLWFjkvC7+Pmq/KNPK8WumCkE7PFtxUtFGPiC7kTqMy6y0NlJYUJZaeTvGWHUkTBqiXNkQORZb9RQ+7i4jOUDxbodIJAUK5773EKXYrkkqpeF4dIOu/V/cklO/v3Iez+BilK4NCDIAW7OmcIDJsx1aGLIqb9BK5GxEXIDnfFo3Q94Ok9R594pA/efJVTV8zyVij0BGwuIxOeIXzIkAo9sQQ1jOG0G+en8MFqqfeASqCEt/fhaX/cnX8Mn9w== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:satlexmb07.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(23010399003)(1800799024)(82310400026)(36860700016)(376014)(13003099007)(18002099003)(22082099003)(10067099003)(11063799006)(56012099006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: v31TVIV2XJpslIT9e3qH61r5G9jATMT6/qmGzN3QU7sQ+ZxaVLkJr+N0mGfXTLcemrD0LaRYfOVoAYVhjUgo50piKiMJh1ifH6qUSiEWeyeCunLIp1X++YuxhUzHLx2crbHy29/DWfiW3hmqhBJ9QFbCTUAIQhSElFLc6JFjOM2Ai2FFFaWrymq1S31XqxcGfbtE7nyuxSgoOgGjby8f57LfBvuJDQaXkJXJ41MBCvWF0wR3sIDrkFFiEDYXrb0o2Bq0yivMPRmCf3fAKYNi+FwbPd0S59VASEf1NuqEDgUBh/h8sbHUPFd5SOYVjAyt07ec5ZHfb3td9ff0NAXZyCRGrx5/1ToG5jWS1CgBQSVvKqJWIiYAnaJ3K4F7ANuNwVGLkKu9U+ZnO+WWwxCE3xr9AS5S3e6h1xwFiyvWnzCO/nchrmijnqZDzjGbmKW9 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2026 09:14:29.4088 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 51ce4aba-472c-455a-f6e6-08deee1af5da X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB57.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB9088 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 In commit 92fdad7 "gdb: convert type instance flags to bitfields", `operator|=` of type_instance_flags required the address space and address class values of left-hand-side to be zero. This introduced the following bug (thanks to Keith Seitz for reporting it at https://inbox.sourceware.org/gdb-patches/053e90c0-53f0-4748-9d27-0237b9f21221@redhat.com/T/#u): typedef int myint; (gdb) ptype (@code myint) 3 ../../src/gdb/gdbtypes.h:127: internal-error: operator|=: Assertion `harvard_aspace == 0' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. ----- Backtrace ----- 0x5bb1d1 gdb_internal_backtrace_1 ../../src/gdb/bt-utils.c:122 0x5bb210 _Z22gdb_internal_backtracev ../../src/gdb/bt-utils.c:173 0xdfbbaa internal_vproblem ../../src/gdb/utils.c:434 0xdfbf45 _Z15internal_verrorPKciS0_P13__va_list_tag ../../src/gdb/utils.c:514 0x162763f _Z18internal_error_locPKciS0_z ../../src/gdbsupport/errors.cc:57 0x87e8e6 _ZN19type_instance_flagsoRERKS_ ../../src/gdb/gdbtypes.h:127 0x875d71 _Z13check_typedefP4type ../../src/gdb/gdbtypes.c:3072 The |= operator is used in check_typedef as follows: /* Preserve the instance flags as we traverse down the typedef chain. Handling address spaces/classes is nasty, what do we do if there's a conflict? E.g., what if an outer typedef marks the type as class_1 and an inner typedef marks the type as class_2? This is the wrong place to do such error checking. We leave it to the code that created the typedef in the first place to flag the error. We just pick the outer address space (akin to letting the outer cast in a chain of casting win), instead of assuming "it can't happen". */ { type_instance_flags new_instance_flags = type->instance_flags (); /* Treat code vs data spaces and address classes separately. */ if (instance_flags.harvard_aspace != HARVARD_ASPACE_NONE) new_instance_flags.harvard_aspace = HARVARD_ASPACE_NONE; if (instance_flags.address_class != 0) new_instance_flags.address_class = 0; instance_flags |= new_instance_flags; } So, the assertion in operator|= was wrong. The outer type, which is the left-hand-side in this case, should preserve its values if they are non-zero. The right-hand-side values are used, if lhs values are zero. Fix the bug accordingly. Furthermore, rename operator|= to "merge". Type instance flags are no longer stored as a bitmask value, but rather as a struct. Having an operator like |= gives the wrong impression that we are doing a bitmask OR. Using a method makes the intention clearer. Include a regression test. --- gdb/gdbtypes.c | 12 +----------- gdb/gdbtypes.h | 15 ++++++++------- gdb/testsuite/gdb.cp/typedef-operator.exp | 3 +++ 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 9098727959e..bf4cfe0250d 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -3060,17 +3060,7 @@ check_typedef (struct type *type) error. We just pick the outer address space (akin to letting the outer cast in a chain of casting win), instead of assuming "it can't happen". */ - { - type_instance_flags new_instance_flags = type->instance_flags (); - - /* Treat code vs data spaces and address classes separately. */ - if (instance_flags.harvard_aspace != HARVARD_ASPACE_NONE) - new_instance_flags.harvard_aspace = HARVARD_ASPACE_NONE; - if (instance_flags.address_class != 0) - new_instance_flags.address_class = 0; - - instance_flags |= new_instance_flags; - } + instance_flags.merge (type->instance_flags ()); } /* If this is a struct/class/union with no fields, then check diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index eda09641248..dd2d24fa8e2 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -119,21 +119,22 @@ struct type_instance_flags return !(*this == other); } - type_instance_flags &operator|= (const type_instance_flags &other) + /* Merge OTHER flags to THIS. Address space and address class + values of THIS are preserved, if they are non-zero. Otherwise, + OTHER's values are used. */ + void merge (const type_instance_flags &other) { is_const = is_const || other.is_const; is_volatile = is_volatile || other.is_volatile; - gdb_assert (harvard_aspace == 0); - harvard_aspace = other.harvard_aspace; - - gdb_assert (address_class == 0); - address_class = other.address_class; + if (harvard_aspace == HARVARD_ASPACE_NONE) + harvard_aspace = other.harvard_aspace; + if (address_class == 0) + address_class = other.address_class; is_nottext = is_nottext || other.is_nottext; is_restrict = is_restrict || other.is_restrict; is_atomic = is_atomic || other.is_atomic; - return *this; } /* Constant type. If this is set, the corresponding type has a diff --git a/gdb/testsuite/gdb.cp/typedef-operator.exp b/gdb/testsuite/gdb.cp/typedef-operator.exp index 9513b3725dc..e03502769a4 100644 --- a/gdb/testsuite/gdb.cp/typedef-operator.exp +++ b/gdb/testsuite/gdb.cp/typedef-operator.exp @@ -32,3 +32,6 @@ if {![runto_main]} { } gdb_test "p *v" " = 42" "test typedef" + +# Test that address spaces are preserved. +gdb_test "ptype (@data D)u" "type = @data class C .*" -- 2.53.0