From patchwork Tue Mar 5 08:47:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Indu Bhagat X-Patchwork-Id: 1908086 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=erkjTt6O; 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=CVf57ing; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Tpq2W17Qjz23hX for ; Tue, 5 Mar 2024 19:47:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6577C3858289 for ; Tue, 5 Mar 2024 08:47:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 4720F385843A for ; Tue, 5 Mar 2024 08:47:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4720F385843A 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 4720F385843A Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1709628436; cv=pass; b=kMa/1FHE4ExgnnMVy46UUqO8qNVp1WMg/DUj8d5GmUXbHOPAiLD49wc0xEDv9N8AVCXwHFYU8KeQAyvIpPX5xoSfZEWMSwRvEmkU74qWKmqCv3UBtjDEWVQI6YFmt0GSZkPmfjGQ2rTjCtjy7OjN2N8LE6QxlH877CHppQ+yYcc= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1709628436; c=relaxed/simple; bh=EB3AVVtRHowex6QgcwVRTiEF8l0TdfQGK444CQ2xOts=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=eiwg5EicHmDr8lqxaITl3P4heAr5Oluig0avi1arNiJvijUair3ZHA5Mfm9XMApt7svVtygeireD2t9aceomt8dmZGphomClS0MDnGQ/nhFFviwqAfTO6GMT11UL4q/I+R4SHPJEIwJQ1W/EeN6Q77HDvBHcLH75ubUFmDwwCoo= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 4257Ax3A017221 for ; Tue, 5 Mar 2024 08:47:11 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=NvZXw+nQ2Ayn9eEZSJIB5+ZyTEn2rVzXVOnZKfLPc18=; b=erkjTt6OOuhjS4vndwZBfo7snd1hlgvuaPZZ3Vz8BfUTprY+Uo6kUXW02BWTEH33LqoI WE5C2EEoKUHk+9rmhIzhfdStwtjm0iAxmu2ZLatRjVIUplWtosfiFOGbzT7vdp7Wav8X kUxiYq9a/dckJPJEqB+QKoH6fSgQWNVkvVsVfyNA+G/+lgVliVRP/xJI6XSAynF4MwtG J9tP/kU3+Jrd+PYk64AiE8f/xa9jrIRFvnD4m7JIgMWa/vwjA56Pv2WzIReKIivEIKZI lj0bfTBAID3D9E9GG1DjctHee2T7onCIys3jeBaa+z1+sclZN66KbOCd9qLZe6mM/V6c Mw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3wkvnuwjfn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 05 Mar 2024 08:47:10 +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 4257Vogv017607 for ; Tue, 5 Mar 2024 08:47:09 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3wktjd6vye-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 05 Mar 2024 08:47:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FBW9Hm1Z5Ruti8ibE9lpGmtKC5ftPwjDuxPcrPDLMyer8KZ0pVIttDP/z951gXcMIFlj0FwTyFSf80LVOdgcVlYoIKLm6oMEz48qZNebe6mJOaTWbwJ1ko0xEVWAwl4fV9pb32aydMAoBGmSpINegKH1kFk0WzV4HUsKREY6tj8T3Zowzzq4TKHDZgwhMBPFtfpIIAx3pKP3qsHIh5fB6d1DASyCB9WzzyaTjvOvL0nBk55TOyb48oZDAIwb+EZ7VdnI3GdMBTyFsdzJVWD+50CZvC+5erPW6Ldlp6+xXhBwBzxXKiG4Mfx4MvwfqL7MMv+htogozgtUEOircAX0Yg== 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=NvZXw+nQ2Ayn9eEZSJIB5+ZyTEn2rVzXVOnZKfLPc18=; b=FtC654blxrxKdPy1Bg+6lU8DbKGpO5MXwK+HtQBXzOfMFM7nNaY5buwxFHwV10HvJ0XoJgqEz8jiWUF15yAFYw9FcLfEcz+uQI1DrcRfDDnMzvEjtr2lMbr2i9RVCjYeoROmPfU2fMQGqWY0WurozbtvSQyDNiSH5a6FZMzBgyz5ZJ9ZCQc9mD42+n0dcoN/SDXAHNGE/yLfyFFUOJ9BLotYlC3MA9P1cwpTcCiaeLvrsGv5fftBnCQLPNuspnI+u6JPMX1iJGvhH3dS910A1zdBsMf0Y71PtOmGL3ueVS8/1IksZnw5LWD5T8CnFIOHLLTpfQ1IXiA4m9fNXx0J7g== 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=NvZXw+nQ2Ayn9eEZSJIB5+ZyTEn2rVzXVOnZKfLPc18=; b=CVf57ing1l/ESzvP0qc1zGGb5Xp5CPdPBbQzpH5nEVkW/cTOBwZ9PFgGlDXlH2NJ2H1jwWEPHG7aqMTPO5DfB96qXbZeDahplSgIsPvY9YTkifso2cKCZjivWB/p16a+G2k1sz2tk8P48BDeZ5BjWSS0yS7ddFZnqGiNbuWb2NI= Received: from MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) by SJ0PR10MB5890.namprd10.prod.outlook.com (2603:10b6:a03:3ef::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.38; Tue, 5 Mar 2024 08:47:06 +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; Tue, 5 Mar 2024 08:47:06 +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, V3] ctf: fix incorrect CTF for multi-dimensional array types Date: Tue, 5 Mar 2024 00:47:00 -0800 Message-ID: <20240305084700.2097313-1-indu.bhagat@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240304180057.1078652-1-indu.bhagat@oracle.com> References: <20240304180057.1078652-1-indu.bhagat@oracle.com> X-ClientProxiedBy: MW2PR16CA0058.namprd16.prod.outlook.com (2603:10b6:907:1::35) To MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR1001MB2158:EE_|SJ0PR10MB5890:EE_ X-MS-Office365-Filtering-Correlation-Id: 8d5ae80a-b050-4d4a-a183-08dc3cf0d5f7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DG576xXPDuY5TADDoVzMEbR4mDsET28Ya4z3up4Ec2jpxiuPMUdRdQ5r5zlq7IufhQkVnhLe+PLKRjCORB9mSir7CMYS/8Vk3JwKFOpzFpy/TVjAlnZfRYjp7ZjEgu2InRIsiZD6Lv2uMQ+Tt6YP0GSpBMlETllUa8NlS3mLkrD/1WxPaP+uEuTqkXHEuX9SL935D+W/nHsFgHZuE8IlcT6dlWhtQYxu1I8o9eviih8Joud2IFkcrVK55iLoJVwoH9ferGRuBajBSREhfcbFLjfoM/SkBf5tjLXdqLBaYVsRp4e0+BWOH/PPLRIuim3VwL+nk8q+1LjMM0a61LDsWhFTLLqIxeXOt4MHfs7WsSgSJfwk3+POKPHGjKLPNFQM9LJgHEvtoU8rmsd9/tR+PLLHuKHnPR1chwksvDCdp5ErcHyXj5NF5nMSppWipufd92rf+C4/1bYqTMUSTv5IzEJBQktdfgxlDmtJorNk2HOTDomuw5ZmatjmGyXpI3HD8bxRuTgqjx+LQWeL+s6mCfHw2ctNZCIcSXG3Ou/14z+Mn3lF1ij6bfqnmGVlLuVop7ew2atB8YjjDTX5NFjQb1N2csKnnWceHVIEH39DY44= 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: EyZual2bbtji1oYMHc662NMWFG8zBmavmNOgMH0405CkR3/MflJPkP91Qpu6hXAX06Gw/zt/X8XXqZaQcTodt1hVH5hzmTqrTN5mId6hd3H317OzIU+NHAVhLcWVLSkFjQBRvCJINI0r2TjrD5gUu3QM8i+DVnQmMxTQNJ9rBhodBzrfAlI/GdYVGjTG2o3VoDYxlKPpaWXg/ZP8PlvBgnMKp1TpKqvz+QdLv7w2vR9ogymqBFMhzhp8hmeENg89XSRs6BRovQxgckNHOByI8V4K//bTZr6YdoszQWv92iN3NGfixsC1cke9XTPWT6kQef1x/mDRoYC9HxKSoWKpHxbAwv1QbvtxqHHo3uCrBAkD2RgL21L11fkhA9BbpcuO+re/6rOQdoSKnmdiOU6uXzo3TasyKZU5/MDrFj4xCdawPOraRDcCNfmW9Ew2dQ9m8YyoKa1xdoCsD4a0spFF7BkfckjN6OELYsEFPEdOUHuZEhE0hLD9YX7UnLoT7td/uXNDXNumGSErMgoekE/Ilz3dpTb6kbnGFXvBRqgU25li8RMR6cRI+0mFERXnKbAqCvgd4ef31WQdlzLsdxsOlgH1GAqHmDpd2UsGbUV9qAgYo0+jFCJM954yFsaCG+5y7UMksNwV95OEKiaZvwsv/lxbAEuS4cqMIk7AvIFS5vcJ+lbg3y6i3+dYiL4vfl9reG1dCGPaR9Z1Hw2bGQCNBvNE6jUJOAi0DNkcVoJwUwEhBQJfSD1/Pi9XsKRknx59UmQTW2YJcA31U733egL0buaZcskm5OkULKRunyKwTsLfSxMUohWfN8cGohAOHuGL5DvROxPEyP62yQBkoNgyovCIEmCj4eHJPE1YpTLOhMcrsDL7uKrGBPmye128MUys4SE/Oy2+UrIK9ePPcB52dC8q6d3Ro/u9Pw0rmt/gD99nev/NL0qcvbIuG6Nhg+v9llpFpEv1MhrrDznbpdGy9F5o8I4XNog2+aKS2QaYX/c4QPFz9bxVBf4Ub8mD7NYqddab3vfA2ZXeChN0FF+AuxSX6idhsScVLiuOFDvBq3n28aeh/GDfsQxQbeG3tqr9XfTSvKPkNzeNRgyZZ9391/Ej5SalxUo0g8wqMW3Cyigxu9WTPGXXW1SEnl25JxJWfW4wd8v5bZxdwwTTbszDVZ2weT6uidwZiKdUXxd39GvEhRcK8G3M6fmJdKfOtiK+diafbX25m9COwlHfXTHtdBOLBuaBd+ZtPvEGgO9rOc9COjWqpjsGHNv5PPUWyVm4bB2X9TLYO5xTg/rqJrUsOzzlrxGtF1+Ak8ZC7FePZxtxN8I90bRmqHyl8fhT00MbRvvOaCax777f1rcYmb/4uxwK14YH/CjcAZDI++TJt3i5UnzsWoQat6wPHdeK/Rcdwvz9DjuF0PepSX0sOa4/94KxBYGjwR/ayyzymt9vrq9LNhgmKSOIcBuWwjlbKtrwo8jV7bb+BoullC2JwAcBtS6xqqh5+F58rxdUfTtheDZnahPxcfv0PJIX+WfwfJIsy/jCdizgFTvcYo30kG+dA16viWGsN/NziqW3CxCnJR+CpKkTjNQq+q3Rp0uVTM2kUrtzsoKclHBXRQkQfXE2d+GTlojsvyxK01BninFaxfM= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: POUMw9RLmkY/I4fU4CuzDMH0hUD+XJTdIXGE5bmRypnk12ZVQnFBbNwTeIceTlQrorIEWux5PxSWaqUwXiIukvy6b7l3lx6emOjlqytjhFuFBDdIbrc0PN1BogpwmTPJf9rW9zw7iosKRJGku6J5D9kOPL0OV2Rhb8wARs4uxSMVunLynkR3JlUfSdvBygPrJc0y7cTvl3jAB9d0SNS3ftpY0pWOsemJXp0GIA/oV0Fnqrw4MBTMLArTBIW8xU4ULfaiHtP/H5KeQsXRf9lVlsFqPHo6dJ0Kn95QS3MUK4bMArjR9CI75S9aQ7H3QMMvAD1W0jXdA57TlxA+uLaZWnzQIxcTZPWiAgFnKmwKBlCRutQBsBdOp6cX+ys/BTwDkv8KDsmjFd27NVQZofVpDqhMA232cOoctDwPFP1dZ/6bJel2RpcK/DrZsKvSLlPVTphXj4jmErxXiYXZgKxdAkS2rTHKJkUt7Ro0+03KLmLia4ZklkagBjXEzJ5qZDj4p3/aINQ5PlUD2aM1HQfiLMh6d86X/vZNPmJPcvgvmyYvXbdV1IDoB4Js2yQQRxfkGJOxjX7IR9NI7ahxgZvCSmqW9piDsFbH5EaoPB24KY0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8d5ae80a-b050-4d4a-a183-08dc3cf0d5f7 X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Mar 2024 08:47:06.1576 (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: fHdEbQl4NumWiA54DQUArMFGWowmobl9SgKjDaIS+GydDL0fgsKLgmOVC0CGYaiIjWZtCLGEuoAGxAObTkLNHQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5890 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-05_06,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-2403050068 X-Proofpoint-ORIG-GUID: uwTzPSmXp6rN0FPrfieVI4Rl_lK36Hcl X-Proofpoint-GUID: uwTzPSmXp6rN0FPrfieVI4Rl_lK36Hcl X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 V2] - Fixed aarch64 new FAILs reported by Linaro CI. - Fixed typos and other nits pointed out in V2. [End of changes from V2] 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: - Linaro CI reported three new FAILs introduced by ctf-array-6.c due to presence of char '#' on aarch64 where the ASM_COMMENT_START differs. Fixed and regression tested on aarch64. - Regression tested on x86_64-linux-gnu default target. - Regression tested for target bpf-unknown-none (btf.exp, ctf.exp, bpf.exp). - Kernel build with -gctf shows healthier CTF types for arrays. --- gcc/dwarf2ctf.cc | 158 +++++++++---------- gcc/testsuite/gcc.dg/debug/ctf/ctf-array-6.c | 14 ++ 2 files changed, 89 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..77d6bf896893 100644 --- a/gcc/dwarf2ctf.cc +++ b/gcc/dwarf2ctf.cc @@ -349,105 +349,97 @@ 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; - int vector_type_p = get_AT_flag (array_type, DW_AT_GNU_vector); - if (vector_type_p) - return array_elems_type_id; + dw_attr_node *upper_bound_at; + dw_die_ref array_index_type; + uint32_t array_num_elements; - dw_die_ref array_elems_type = ctf_get_AT_type (array_type); + if (dw_get_die_tag (c) == DW_TAG_subrange_type) + { + /* 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 + gcc_unreachable (); - /* First, register the type of the array elements if needed. */ - array_elems_type_id = gen_ctf_type (ctfc, array_elems_type); + /* 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; - /* 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. + array_index_type = ctf_get_AT_type (c); + arinfo.ctr_index = gen_ctf_type (ctfc, array_index_type); - 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. */ + 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); - 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; + if (!ctf_type_exists (ctfc, c, &array_node_type_id)) + array_node_type_id = ctf_add_array (ctfc, CTF_ADD_ROOT, &arinfo, c); - c = dw_get_die_sib (c); + return array_node_type_id; +} - 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 (); +/* Generate CTF for an ARRAY_TYPE. */ - /* 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. */ +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; - 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); + int vector_type_p = get_AT_flag (array_type, DW_AT_GNU_vector); + if (vector_type_p) + return array_elems_type_id; - 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); - } - while (c != dw_get_die_child (array_type)); + /* Find the first and last array dimension DIEs. */ + last = dw_get_die_child (array_type); + first = dw_get_die_sib (last); -#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; + 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); + + array_type_id = gen_ctf_subrange_type (ctfc, array_elems_type_id, first, + last); + } + + 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..5564cb8865db --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-6.c @@ -0,0 +1,14 @@ +/* CTF generation for multidimensional 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 \]+0x1\[\t \]+\[^\n\]*cta_contents\[\\r\\n\]+\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*0x4\[\t \]+\[^\n\]*cta_nelems" 1 } } */ +/* { dg-final { scan-assembler-times "\[\t \]+0x3\[\t \]+\[^\n\]*cta_contents\[\\r\\n\]+\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*0x3\[\t \]+\[^\n\]*cta_nelems" 1 } } */ +/* { dg-final { scan-assembler-times "\[\t \]+0x4\[\t \]+\[^\n\]*cta_contents\[\\r\\n\]+\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*0x2\[\t \]+\[^\n\]*cta_nelems" 1 } } */ + +int a[2][3][4];