From patchwork Mon Mar 4 18:00:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Indu Bhagat X-Patchwork-Id: 1907835 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2023-11-20 header.b=lx3f6m3y; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=Ulduesn0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TpRMx2zMWz23cw for ; Tue, 5 Mar 2024 05:01:32 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6CF36385840E for ; Mon, 4 Mar 2024 18:01:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id F3CBD3858D37 for ; Mon, 4 Mar 2024 18:01:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F3CBD3858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F3CBD3858D37 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1709575272; cv=pass; b=FhtAfPZBV/SCL4YF7LkzIRV3Z1pPiPzGTgnzluV1OZEmSJ2+3BZI/wBIejt1+Pn/ji3oNfTqWdRXyVUmT9kjpgRclFBt2+enRtnlbVFDs789gF15OK4qrBsC/UtudrVXmkq/myonel+iTG/CLnxYx3mPkPJcwKs+PwuRdouQ3U8= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1709575272; c=relaxed/simple; bh=fj3RBcK2i+x/Z34A7gGPMp3vhj+buMr3KfZVNYnMyLM=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=rlH0R4uyC+QapCz/lQw4ekhm8QyT3KyXrTp/V3IvFQVnBlK70WaEhKpoelAIFZxyFqVIcexsxQD5w4X9qA/vJ3DmO26yy0N9AbcZNO1gyI3lhXjY8ETzg2npGpjSy/vD/OsFY5BjrWjmNMyvwO8/4J5+4Oo8GlaANgPx7/8yLR0= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 424GXwFx003012 for ; Mon, 4 Mar 2024 18:01:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=Rbf+BhTrUmZQMYEeZ3+s6pfcHHmzpsIY6M6AtoUOcsw=; b=lx3f6m3yqfBk0tgcc04lgloaqsseJ/TPKoYo1ikrgP2jPBeBVS2Nqs/JTs4jDpVC9aMU jWPuNH82PRzFddx0staIlDBbZPioMtWKAkunjpjy+BTUux6uwFiIPz+Mttd2OC4TP40d v51JJvPUsUFdG5ig4pcZ3Q0EOVhazu1NpbCYTHdJB1EQo/72vGSAFT6E7r9jb6+SFiPP 7yc2FJcAJBsLeH60JQIIY7WsUpNS2EEkHbgI98z7VSJmFawBR4669Im66ezJDSroHtcr 5WM5ufaUPRhLiSrZVIMBiHQgf/bYLbqALpz9Hg9JiU5MTFmxKEp6mWvKQ4EE+UY5+Z+C CQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3wkthecdrq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 04 Mar 2024 18:01:09 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 424HCuGo017606 for ; Mon, 4 Mar 2024 18:01:08 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam04lp2041.outbound.protection.outlook.com [104.47.74.41]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3wktjc61ts-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 04 Mar 2024 18:01:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h2l9tKL6lKYssaKvH5K9OBTMKKN1E9TalXq7gQckxWN+9pRwVgYHnBHkDx5lnOTQwLMRkHhl+ACiID29IYi3c4peUsnlcUk/g7zeUSV8l6WMuFc0rCbExEFh3JT0x4PGMyB1eyddsGocjrWmEdgRh7XslnQf9PnnZxHqmenDMxQYRY+E3nc5PHfU7U+8BwQoKeEuten2ESbIqOD5kymXrLm0se4/foEUt9vHnKN2GYbamPJVCXmlgVFfneVxk2fPXEhbsT+YP/EDkbu60F3+apaV7+eleIwRHxilqAPOjFBG3vWdXf9JLf06gwRLxB202bmX7f+emI8ja/NTK/PhQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=Rbf+BhTrUmZQMYEeZ3+s6pfcHHmzpsIY6M6AtoUOcsw=; b=lNdoXUiBYaXEBaxTVQbMlGBnc545ueKZUpY1sVBFyMMEjGQbnzNZ/1E4mT3hWRsyQesepmjvKmTvEp1H6fFjb6s/pZakUZvCIhO/kptDOi4zZtgHSbtqenPsENJLuVHQuO2vbTfwotQsSYzSkVBOQ3kko2Iej9/Ww6UbwGdVtuKExApdF298iu0/1VucIuCtPbIEck/TphQrUbc4VYaEnb88tbNE27rdepCEyXfU9k7hfnOd/m1ZAPxii17HfGzqe1AFr20Lk0KgC7446hqtdcTtbQFZV83ilgU6SMLH5OD+rB7Fa3jgHamRJxz/vZ0HtwzbXsK9jhtrV046aQjulQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Rbf+BhTrUmZQMYEeZ3+s6pfcHHmzpsIY6M6AtoUOcsw=; b=Ulduesn0UMiij9gyhz0a9yUfk7V0lU4lC4zW4+A6K7mP1uYrZ+H/erm3hsMbJn34R3D/OAWTYbz6IfA81evFs8Tk05GWiwM7aRINVV2fd8GW7etJbSIv2kLEaKI08s7EUyHWGqIBnK9cginYSUVZmh65OGMX0YwG2uCjhTdqd14= Received: from MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) by SA1PR10MB6493.namprd10.prod.outlook.com (2603:10b6:806:29c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.39; Mon, 4 Mar 2024 18:01:02 +0000 Received: from MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::f3f7:686c:bee6:d4ae]) by MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::f3f7:686c:bee6:d4ae%7]) with mapi id 15.20.7339.035; Mon, 4 Mar 2024 18:01:02 +0000 From: Indu Bhagat To: gcc-patches@gcc.gnu.org Cc: david.faust@oracle.com, jose.marchesi@oracle.com, cupertino.miranda@oracle.com, Indu Bhagat Subject: [PATCH,V2] ctf: fix incorrect CTF for multi-dimensional array types Date: Mon, 4 Mar 2024 10:00:57 -0800 Message-ID: <20240304180057.1078652-1-indu.bhagat@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240228150341.54713-1-cupertino.miranda@oracle.com> References: <20240228150341.54713-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: MW4PR04CA0279.namprd04.prod.outlook.com (2603:10b6:303:89::14) To MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR1001MB2158:EE_|SA1PR10MB6493:EE_ X-MS-Office365-Filtering-Correlation-Id: fd894ac5-0ec0-4f9b-433f-08dc3c750dbe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EzRR1ZtRMIgRGhyRzsOQsHoFGSh8lHYMgPen77Ts1pq/GKvjNwRVAEXYccDVYSQrpEl0EHBmZYS48SOaO41VnEHvSZfrp/kexk+E5fsuFoGaZHqr+NxgJSxFS3eWZ2Hy/e86UccOyWcBd0KLSA59qlbLSgy12RiO2Orc6RpASB1t+NiDRnyUMhe96EUBQ4RuNqKpT3kyRSOe+FxEZsT9hir6N5S42zMZ7EDH3f3ycM55mReyJE0a/PoAzEL5R2heLiRkD2nizdoICrbiKu8gAPaEEaQepsyEtSl3tml3dS0ZY/WazbcV6/DZDUGZbnawTZZA/GuUiaylyPxMOV24GLd4jdR8gsu3/I3a7H9sIJgXZxm0LaEbY365OeC+Zr1N6GDF8Euq32xojer6Ql/gx05bCa8WXzcBqlTNfSdaRdkOMueDN1dg098QdnRGBr59JBYWfzA/hKWvQ197sx4zF50P1TWLnl2/UQrahqywztvOKQL/upZrarmSqtrhcXnxjjUNdUaCMzn5WxWlzYF/Fmjark566zoViS6V69Ja2nnF4H5gqCaZOSFW32IXnITgxmyFdBVd/2Tazn/JxqIMxTAaMiSyEHqIPIs5FccRCaE= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR1001MB2158.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(376005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: V3ioK/DgYD20eGq01Lc+nT2U0HUgQ8m33leX+IBds3vP29J+3DPaIiQ8bPqxip1UFnI3ZxLQTB9EZ1orgjSCD3vkSHJmlOJYK7uJqWUlAR+4+uUMSewNLVarhVBeqSiZD6OR5j4URGKS4ZO2xZ7fgnERu+1rUzvXHyNFTbji3eJyz3Ufc9rEE2EOfUJ2JMsiEXfaOe/EQGf3gxhkGzEcNBtbaURdzRRc+1IXVs9CnIL3BENoR8Mbh6SvZsOc1BqJIrYTytIhI7AzLSAWZHiomcTEoHJVkztOFn/86YJ6zJ/lS3GmtXb030WVrrFOMQxWDSWSOqV9VLM9CeLWoO10ZM6BPGxzIxauBqBeILCPyNc8sen/S6ztrv1PXjuCGg7vBoBj1uAWhmyfK3mlJyoiBQKkebYAMQD7mscRqs59DYmU/R12H7y22ugn3HcDUrKgQskuDHgyWxmTC5GH2laFMFgW51Uj8DN6yIy5BRr7XZ5AZHQODBx7yb/eokFwuSSx8B8cwB1f2rYMtavngCQ4MF53lct2B8i5mxqOK2Ot/0+UxakKVoPFO27nPKAGmbtPHuHwnSiba4hSdyvMceR/EnU7EdO19y6gJsWCiZ1w3S23EPDz5c/O2mkAcQfH1Y4vzc3bMYIGY+S96FkS/ZDDpdFHYZG0Z38SF6oTteWRmIt/ylUK/inBNwkhp/nheSwaMr72Q1L901VKP7NISnA9v8FJfWqOEVlZK9kyGAU7pHdnj9IWQcqc5QS+FLJSBaTz44bVyHKGxCtk4BenGvSAByjaA5k+jhzNVASb9gU9aT3tZf96fUu7jkdgnwOqTFFslHNijfEJkgu6roeYGbgTT/6qNSPqCY6ge3v9O+nqH+7En16M1PldOfLXU/Pt3Q36EMndFh2qfwCym7e/0NnWenc1hvS5Oh5/vA6CcSztNHinOxSkRV+DVqF6VBdXdnjEPsRBCBMXaz5r+NNUGoRMejlO0u5zjSA6dGW/K+Y1C7tnOObfgopxsHdbJ3yeWEcwLn52XKnVxdw0Bu3sz1AbZewdj6kFipa5ZNGFPNIElc8xmpkgI055TcTeLQUMtdQajPv3Jk1sEsObHo8dG4NL9KtS9NttkRM+LeOI/2klM4EMSNNt8zlrHsJg+CFbRsbMvr/1cZlSRAVdsOkjZ9jEOdWc0D3fGcZ5+wlvav4cVNggSpNi1jntwf2omaDiv1K+drG+hEvwgsKHsdizn4zUvbJxnba6BLsrD4OAXPaIR3hegz/Rlkw4flFXtPhUJupiaOyM3l+qI7kEJQmioUraA/Rc9SVdl26O425ZkhvxtisXyam1E3yzAvSB9uPqSYT4gQdaomJrbCVC74EIqmcXjWQVA/A4Z3v2ooVbGWDWtxhq5MnpJoVfwHFmxpp173RB+bwIEFrlKGbQCklA1FW7LKWCXAyLkv6EItC3mq5X5pyvz35nMJmUiMuqQMZGO/nyNc6nMQ9h/QNPMs3RLJtv6Dv/m1ziOPjLY5z73UkQzh3RMxEJg8Pk8bRp8GDanLNBdzR5D62E9uFf6LZv8qdUum/zkytsHV6iwb10ACMZAgwoFD9inYutevxwuyqTF+Z9+RdCJRG5yUftPGKwLN4XwkYRv4nulvpAO5dySxCfp5c= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: mOrTNjXvdxrI1ddGirHTlcfmqfVYoKDxoEehKmYy/8/GDdGN/SCiayrizAherm1dThAHpHiMXijF4tJeJfwsu9l6Z0d2gyqLO+4TDY3cI1WHlS+N9LcTj2fLKKYbZEuWKa1wzGEfRuW5HKVRs+47eekYQGYKBahAskIH4mQWtAsg3fGov5CfJu00fJm19rwzZK2iAY4fntEzOQ5ZvmMamn56zp6vCDD3EIcxNLX680xbqg0JDb7z4Yo/kEsuFp1/tTqSIPw/f7/YG68hHzatMAQ4Lh7fIZuZseinxWC71UL7XZ4ruNThzlrvOzxqqZgwL5pYEpOs1JuiCpgxZ36ZzDgMqKZ8+n0bfbedh29k5GJQstpMDTicK7ajmYLuMmYnix/i9Fs5TDFzQGwBS26r5HSd2SLbLjPBr2sUrp6ddWJjLJfx9W5Ygc8mLsklKrjKF+QbuT0ql8SvY61ggwVTMwGJSBwkpd/lY/synOXSebqb87gnMcSJkADfEpS6+70nNOK6Lnq1RoYKzgLgSqHRwda+CgRRosIrmxghwCtEf59GS2lD+jL/qCxL1YBjKo4xFCbl/Bw5Riaur7t9f0axkIapUxH3lrYQQVwaOfOGWtQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fd894ac5-0ec0-4f9b-433f-08dc3c750dbe X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2024 18:01:02.0864 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nh16H0kAjxhwITyCnu44Y9DW0vnuslSO/CNeG3XSO9YX4F/XJVk21b5CeC0JIZhB1ea4W38Om/IeerH4F2D1Mg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6493 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-04_13,2024-03-04_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxlogscore=999 adultscore=0 phishscore=0 spamscore=0 mlxscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2403040137 X-Proofpoint-ORIG-GUID: kDaAyFThARhcdgYiZnWsiI3QnLDVpoHD X-Proofpoint-GUID: kDaAyFThARhcdgYiZnWsiI3QnLDVpoHD X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Cupertino Miranda [Changes from V1] - Refactor the code a bit. [End of changes from V1] PR debug/114186 DWARF DIEs of type DW_TAG_subrange_type are linked together to represent the information about the subsequent dimensions. The CTF processing was so far working through them in the opposite (incorrect) order. While fixing the issue, refactor the code a bit for readability. co-authored-By: Indu Bhagat gcc/ PR debug/114186 * dwarf2ctf.cc (gen_ctf_array_type): Invoke the ctf_add_array () in the correct order of the dimensions. (gen_ctf_subrange_type): Refactor out handling of DW_TAG_subrange_type DIE to here. gcc/testsuite/ PR debug/114186 * gcc.dg/debug/ctf/ctf-array-6.c: Add test. --- Testing notes: Regression tested on x86_64-linux-gnu default target. Regression tested for target bpf-unknown-none (btf.exp, ctf.exp, bpf.exp). --- gcc/dwarf2ctf.cc | 153 +++++++++---------- gcc/testsuite/gcc.dg/debug/ctf/ctf-array-6.c | 14 ++ 2 files changed, 84 insertions(+), 83 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-6.c diff --git a/gcc/dwarf2ctf.cc b/gcc/dwarf2ctf.cc index dca86edfffa9..3985de115a79 100644 --- a/gcc/dwarf2ctf.cc +++ b/gcc/dwarf2ctf.cc @@ -349,105 +349,92 @@ gen_ctf_pointer_type (ctf_container_ref ctfc, dw_die_ref ptr_type) return ptr_type_id; } -/* Generate CTF for an array type. */ +/* Recursively generate CTF for array dimensions starting at DIE C (of type + DW_TAG_subrange_type) until DIE LAST (of type DW_TAG_subrange_type) is + reached. ARRAY_ELEMS_TYPE_ID is base type for the array. */ static ctf_id_t -gen_ctf_array_type (ctf_container_ref ctfc, dw_die_ref array_type) +gen_ctf_subrange_type (ctf_container_ref ctfc, ctf_id_t array_elems_type_id, + dw_die_ref c, dw_die_ref last) { - dw_die_ref c; - ctf_id_t array_elems_type_id = CTF_NULL_TYPEID; + ctf_arinfo_t arinfo; + ctf_id_t array_node_type_id = CTF_NULL_TYPEID; + + dw_attr_node *upper_bound_at; + dw_die_ref array_index_type; + uint32_t array_num_elements; + + /* When DW_AT_upper_bound is used to specify the size of an + array in DWARF, it is usually an unsigned constant + specifying the upper bound index of the array. However, + for unsized arrays, such as foo[] or bar[0], + DW_AT_upper_bound is a signed integer constant + instead. */ + + upper_bound_at = get_AT (c, DW_AT_upper_bound); + if (upper_bound_at + && AT_class (upper_bound_at) == dw_val_class_unsigned_const) + /* This is the ound index. */ + array_num_elements = get_AT_unsigned (c, DW_AT_upper_bound) + 1; + else if (get_AT (c, DW_AT_count)) + array_num_elements = get_AT_unsigned (c, DW_AT_count); + else + { + /* This is a VLA of some kind. */ + array_num_elements = 0; + } - int vector_type_p = get_AT_flag (array_type, DW_AT_GNU_vector); - if (vector_type_p) - return array_elems_type_id; + /* Ok, mount and register the array type. Note how the array + type we register here is the type of the elements in + subsequent "dimensions", if there are any. */ + arinfo.ctr_nelems = array_num_elements; - dw_die_ref array_elems_type = ctf_get_AT_type (array_type); + array_index_type = ctf_get_AT_type (c); + arinfo.ctr_index = gen_ctf_type (ctfc, array_index_type); - /* First, register the type of the array elements if needed. */ - array_elems_type_id = gen_ctf_type (ctfc, array_elems_type); + if (c == last) + arinfo.ctr_contents = array_elems_type_id; + else + arinfo.ctr_contents = gen_ctf_subrange_type (ctfc, array_elems_type_id, + dw_get_die_sib (c), last); - /* DWARF array types pretend C supports multi-dimensional arrays. - So for the type int[N][M], the array type DIE contains two - subrange_type children, the first with upper bound N-1 and the - second with upper bound M-1. + if (!ctf_type_exists (ctfc, c, &array_node_type_id)) + array_node_type_id = ctf_add_array (ctfc, CTF_ADD_ROOT, &arinfo, c); - CTF, on the other hand, just encodes each array type in its own - array type CTF struct. Therefore we have to iterate on the - children and create all the needed types. */ + return array_node_type_id; +} - c = dw_get_die_child (array_type); - gcc_assert (c); - do - { - ctf_arinfo_t arinfo; - dw_die_ref array_index_type; - uint32_t array_num_elements; +/* Generate CTF for an ARRAY_TYPE. */ - c = dw_get_die_sib (c); +static ctf_id_t +gen_ctf_array_type (ctf_container_ref ctfc, + dw_die_ref array_type) +{ + dw_die_ref first, last, array_elems_type; + ctf_id_t array_elems_type_id = CTF_NULL_TYPEID; + ctf_id_t array_type_id = CTF_NULL_TYPEID; - if (dw_get_die_tag (c) == DW_TAG_subrange_type) - { - dw_attr_node *upper_bound_at; - - array_index_type = ctf_get_AT_type (c); - - /* When DW_AT_upper_bound is used to specify the size of an - array in DWARF, it is usually an unsigned constant - specifying the upper bound index of the array. However, - for unsized arrays, such as foo[] or bar[0], - DW_AT_upper_bound is a signed integer constant - instead. */ - - upper_bound_at = get_AT (c, DW_AT_upper_bound); - if (upper_bound_at - && AT_class (upper_bound_at) == dw_val_class_unsigned_const) - /* This is the upper bound index. */ - array_num_elements = get_AT_unsigned (c, DW_AT_upper_bound) + 1; - else if (get_AT (c, DW_AT_count)) - array_num_elements = get_AT_unsigned (c, DW_AT_count); - else - { - /* This is a VLA of some kind. */ - array_num_elements = 0; - } - } - else if (dw_get_die_tag (c) == DW_TAG_enumeration_type) - { - array_index_type = 0; - array_num_elements = 0; - /* XXX writeme. */ - gcc_assert (1); - } - else - gcc_unreachable (); + int vector_type_p = get_AT_flag (array_type, DW_AT_GNU_vector); + if (vector_type_p) + return array_elems_type_id; - /* Ok, mount and register the array type. Note how the array - type we register here is the type of the elements in - subsequent "dimensions", if there are any. */ + /* Find the first and last array dimension DIEs. */ + last = dw_get_die_child (array_type); + first = dw_get_die_sib (last); - arinfo.ctr_nelems = array_num_elements; - if (array_index_type) - arinfo.ctr_index = gen_ctf_type (ctfc, array_index_type); - else - arinfo.ctr_index = gen_ctf_type (ctfc, ctf_array_index_die); + /* Type de-duplication. + Consult the ctfc_types before adding CTF type for the first dimension. */ + if (!ctf_type_exists (ctfc, first, &array_type_id)) + { + array_elems_type = ctf_get_AT_type (array_type); + /* First, register the type of the array elements if needed. */ + array_elems_type_id = gen_ctf_type (ctfc, array_elems_type); - arinfo.ctr_contents = array_elems_type_id; - if (!ctf_type_exists (ctfc, c, &array_elems_type_id)) - array_elems_type_id = ctf_add_array (ctfc, CTF_ADD_ROOT, &arinfo, - c); + array_type_id = gen_ctf_subrange_type (ctfc, array_elems_type_id, first, + last); } - while (c != dw_get_die_child (array_type)); -#if 0 - /* Type de-duplication. - Consult the ctfc_types hash again before adding the CTF array type because - there can be cases where an array_type type may have been added by the - gen_ctf_type call above. */ - if (!ctf_type_exists (ctfc, array_type, &type_id)) - type_id = ctf_add_array (ctfc, CTF_ADD_ROOT, &arinfo, array_type); -#endif - - return array_elems_type_id; + return array_type_id; } /* Generate CTF for a typedef. */ diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-6.c b/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-6.c new file mode 100644 index 000000000000..5ecbb049535d --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-6.c @@ -0,0 +1,14 @@ +/* CTF generation for multidimentional array. */ + +/* { dg-do compile ) */ +/* { dg-options "-O0 -gctf -dA" } */ + +/* { dg-final { scan-assembler-times "\[\t \]+0x2\[\t \]+\[^\n\]*cta_nelems" 1 } } */ +/* { dg-final { scan-assembler-times "\[\t \]+0x3\[\t \]+\[^\n\]*cta_nelems" 1 } } */ +/* { dg-final { scan-assembler-times "\[\t \]+0x4\[\t \]+\[^\n\]*cta_nelems" 1 } } */ + +/* { dg-final { scan-assembler-times "\t.\[^\t \]+\t0x1\[\t \]+# cta_contents\[\\r\\n\]+\t.\[^\t \]+\t0x2\[\t \]+# cta_index\[\\r\\n\]+\t.\[^\t \]+\t0x4\[\t \]+# cta_nelems" 1 } } */ +/* { dg-final { scan-assembler-times "\t.\[^\t \]+\t0x3\[\t \]+# cta_contents\[\\r\\n\]+\t.\[^\t \]+\t0x2\[\t \]+# cta_index\[\\r\\n\]+\t.\[^\t \]+\t0x3\[\t \]+# cta_nelems" 1 } } */ +/* { dg-final { scan-assembler-times "\t.\[^\t \]+\t0x4\[\t \]+# cta_contents\[\\r\\n\]+\t.\[^\t \]+\t0x2\[\t \]+# cta_index\[\\r\\n\]+\t.\[^\t \]+\t0x2\[\t \]+# cta_nelems" 1 } } */ + +int a[2][3][4];