From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 875A73858D38 for ; Thu, 11 Apr 2024 13:24:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 875A73858D38 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 875A73858D38 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=1712841857; cv=pass; b=bDAP0QLrTmP3GhMSb40+EhGrVgKnjccuzOHkI5feV0iwTGKMAgWgB0SfmLatuv5z97VsfX5pnstN7f2SA/6ckFKOnLNM5ERuEp/EeIQ+05umDYIy3qjLSdz5fLwkVeCW5FLN32Dqo1+qt6hWDX4BlCs1ujI6azjiOFJUEfNbRag= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1712841857; c=relaxed/simple; bh=lKWNGjbWJ5qd5N9euMKfBwyfxW6uq51l/rA4/Fo+eEA=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=fLro+2hIsW+/Bf7RBDNyxB4IcbC2UWFjwYjPj8VOkSUz+JG0Y0tqsVrynaJcOwjbRjhNdnYMiYg9V5ExhTzF/fu3otzBZ7Wy3fgMrX8Bdi9J2R5ALN7U3caJPaFagapmJG13VCP3zr4GhOk1zDrJEQxpOePAwFTLf5RZXzigV+k= 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 43BD49bo013479; Thu, 11 Apr 2024 13:24:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : mime-version; s=corp-2023-11-20; bh=F91MQu9ZUa7uxA5OcC5O8uKkETU6COHUMZXrQw9ks5E=; b=RzhSP9EUZLMl4mmCVo33aAJOHoJDuwlKAkNQmAWpNK4wMIRWkcwiawhoOLT9ubZf8oNU oy0KYKBUqL23GcQaKBQGehDlWJGAIZMtd7H2lGC90cy/znUkCl9nIfvbQpWh2yndJfWk pMUZoEnrUpdNxkzK5zUVmQ9cYEN8AAg6zbSwdfdHG1dKbY/s1ZWYAxs6EAnEnQOmkoLw uBxdIcYj+I81PDNK6HQfIP85jwaDRGkvgWlobaxwbtwlB2WYbCYzYZhd6FvaBe5CjU2t OU9o4vp6AMlSldAaEuFSGT3rnh5xJ+o/ztsSL9YdfW8YuKmv4lyoBYAhlB5LquD9cdij LA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xavtf9dqk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Apr 2024 13:24:12 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43BBtBfe007861; Thu, 11 Apr 2024 13:24:11 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2101.outbound.protection.outlook.com [104.47.70.101]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xavu9gmqj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Apr 2024 13:24:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nmZ6rQlK6xY7OXZPzeIV5zA9gOzXWsJzpK0PopSWeV9IqzhPmYPopVZem4/45t8QZ6aRTGGG+bwFmwYLLmqHp1/rdJIGBYXKtEdpqKRC+7g8kitPalyIci8oYYFiOxKw5X1RyVl/BxYoa34kQ3kJo6tg/jE4y8mcdTHcXhnqgw5vfdULZU9R+C+KGZ9UxZQraidEVtFjSNx45uJ9TEOQjbgm01kVCOZZBnTuS9KxEaH9eVCkxr+4AOGOMssxp5WXTdPG7zjCHx0RdJ/exA9XAHAMsGek4837Dt1/KT30G7JjwIRNlU1HTZmQL4frIHqWOwB8RHdtET3eoNIXWXeLmQ== 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=F91MQu9ZUa7uxA5OcC5O8uKkETU6COHUMZXrQw9ks5E=; b=KCpdOEB/RfVrfKU93LPdx7NZoU36ClovWNIhGvxyDhC+14x47pti5/GGEi8f7MMly3D/1WOOB+MXUm9x3gknR3Zob3lYzmk8pgXi0svgd+ugfxvl5JgvIbvPYc3pXEok69kV1er00vl1Ai5q6W0FQvEfcKyaIjHI30S/SQoanEhmrk2vMG/Pww3uypeqFBbEHos0QvgLuOzf86xdGg/8PqBnP/QkB/zlw3TDTlkIox09dQcNR1TrNId3AZrcVSMk/dvRcdMIEJcPFKOa/w5a+KtdtU2QgFVx0NsIoIRURIs8+ItKAEbI0ErPtmbAKFZHrMBJ9qGSOtCxVyAm3L1wSQ== 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=F91MQu9ZUa7uxA5OcC5O8uKkETU6COHUMZXrQw9ks5E=; b=QsQE6IUnxWaIgX7FHj1UIKnqWytJKda6L3Z+aG3UnD2wyr3Cr7bP+pNqRt5OpnHMH+lzQRHPFAGlmuNSTW4nu6uK6oei4p622bTlTXweEwmyy0IP0z3FZOZlB+IlzKevqGwCbCHoVcFbA5xkF056SpUyBH7P9485qva4JAvNi6c= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by DM4PR10MB7425.namprd10.prod.outlook.com (2603:10b6:8:180::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Thu, 11 Apr 2024 13:24:08 +0000 Received: from CY8PR10MB6538.namprd10.prod.outlook.com ([fe80::2dae:7852:9563:b4bc]) by CY8PR10MB6538.namprd10.prod.outlook.com ([fe80::2dae:7852:9563:b4bc%6]) with mapi id 15.20.7409.042; Thu, 11 Apr 2024 13:24:08 +0000 From: Qing Zhao To: Siddhesh Poyarekar , Richard Biener CC: Joseph Myers , Richard Biener , "uecker@tugraz.at" , Kees Cook , "isanbard@gmail.com" , "gcc-patches@gcc.gnu.org" Subject: Re: [PATCH v8 5/5] Add the 6th argument to .ACCESS_WITH_SIZE Thread-Topic: [PATCH v8 5/5] Add the 6th argument to .ACCESS_WITH_SIZE Thread-Index: AQHagfMx21bW+kfn6EaH5P314/oG27FiHamAgAEFdQA= Date: Thu, 11 Apr 2024 13:24:08 +0000 Message-ID: <1B2B2BF0-4DEB-4957-AB0E-B35687E09586@oracle.com> References: <20240329160703.4012941-1-qing.zhao@oracle.com> <20240329160703.4012941-6-qing.zhao@oracle.com> <6afbe685-f8f1-4dfe-8cee-13ae5c65da28@gotplt.org> In-Reply-To: <6afbe685-f8f1-4dfe-8cee-13ae5c65da28@gotplt.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3774.500.171.1.1) x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CY8PR10MB6538:EE_|DM4PR10MB7425:EE_ x-ms-office365-filtering-correlation-id: a7245814-6a85-4a5e-c4cb-08dc5a2aab32 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: r59bExLtTqL0POSCSJwy2KP+OXpNZ8brLwwbmvZjygJF7aPGmyewLLx4i41rc6KRGkB18k/Kw9BhMtI+i94mC1vFSFPCH5E8UfRoTYjXWMXcalzNO1gF8UEFOOIf0fLmwyeGW4uhGm37JaiHa3wSNmSXrpE7bKgmqyXNHs5GWdtsItTyBNLTRrU7TVQolVc/gqDeuJJECmG0LCP8p0Dp3HjjHmJjnJM/BBBzpa+PlYmDuLNyrtKCbVVRGljzPTVpSEgvjUYjxMnRtdrKaJw6z+jnKrB4ROaPIc9ycjFB2DezH6fTxi1kR9YhZihLZsbvplLkP4NOEqONthj9LDMEymZNN355hCs5VtVK3ieaYT5eUEFVU13UDyBl1t75jrG7hD7o4xWgTPLsD9gely+ixICCP54w/EnujkfI5nR/3HlJnUYTbXQ/paQYrMUg3MZQuJGnmNtcfZewhv8CNOkiEP5FObxmmwbUkkXAVP0xNydOuviB0sLgWAv/brhS8DibXiQy9bmX0xe2nqFZKKp3Xn5LLivKgEOkxZVafl86BP1EYb90+qlnCMtRzbaP6Q4crjiXhfUhaENQrpOnKkmBIXCy+NxydKZG4OWkztEQm0qxCBT3sOT6yP8J1+ntoN1yLjUBEhF8wsFg6oAujJ+HDSQWgmOsby3GvniYFAG4wjs= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY8PR10MB6538.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(1800799015)(366007)(38070700009);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?c55xKg3Ot79dDK400pd9DId21wyu17IcJn+uEIswC9LfX8nrjllY/zwIOB5Z?= =?us-ascii?Q?ojPq09Ij58lSrh7WbrzZJicEOYnISVm/qdtDWoSx2MB6Lte0AfIulpSo6Vxv?= =?us-ascii?Q?BxnOCNxvshZ89oKMyiUzV/RiMhqG0/oDQrtdG4gbHxy7wtz8ZvD+j32SvYuT?= =?us-ascii?Q?3o0/1rQ6lhqcNOthBvGEAwv5CoRNbqZU0BLTNo3H0ywHIm7TFoStdti5yQF8?= =?us-ascii?Q?RdhFvzrOb7jo5q/PPIfe2qPxvqvIZSNoJJVoW3NV+ceEiIu6gIPX+qn/Hs7H?= =?us-ascii?Q?Yoiq+EXmmABEQalzYsB+IkX93oyXl3o6jHLxZtE1HHerIxJt5yCN74Byysvk?= =?us-ascii?Q?J+JFPpu5k8gA3Co2h2Xbxt6drVqXxsrFDLKFZgTtRKQ+7pJPGAlCQBypimGX?= =?us-ascii?Q?SPoXZXvZ/42bhj9pClORd2L2QUJ5JQTzrFjbjF5T2DL3hJphZnig15W0g5cE?= =?us-ascii?Q?1uqEU++GauLacGvbqytrHjB6p/k2vHaqxxCovCSFhZEE0cHbaLE4gKIVQpKM?= =?us-ascii?Q?AqN51hmLDPxwifCFgNNaJ4DfKk8HDB6roGFZ3on2Ly0BAKlUWi6hZvgSK9lH?= =?us-ascii?Q?mv1NYX7XcjFiOqoIsAXFwbWaLLP2FtIeI2aM1nEXrseOkB0cxNFSqV4LAI04?= =?us-ascii?Q?OEvUsczN4vTgsuGt31YWcosPoV4h/axx+SwqvrLvBSv8dN51ibA9nXKkhiMl?= =?us-ascii?Q?6NdJbax9PPrKsS5l4SfxuAeSh1EKD3KJjvJh6qMN4UyQHfPcHrA7gGgR4nX0?= =?us-ascii?Q?GW8l4odXuHynYPY0gMLPZufbplU/AkPMSRI/mQZtkz+Gyarmm3RuueGJ+ebf?= =?us-ascii?Q?wpclqk7wszoO+3wj29KWHHW8cSD02IYYLVHJCBwlYH0qhbjs8kDcZCweCl1H?= =?us-ascii?Q?EOv1UlMjhLd6IGYa1tTwZ21J7XQ1ivoyxTPoAeY1dUau7lZITDYVGF7nUq6A?= =?us-ascii?Q?7KB7jisH5LWXMBqN1unxnmrSSeCWbACXxbkhcDcXZsd5ImTqmpbVA+/twhVk?= =?us-ascii?Q?RLF3Sphqjg9Df+R8VyD74bd52teYfis4BIwWkj4/lM0U1RFyC66l+PDnJ6hV?= =?us-ascii?Q?SHhRigzrzPeV6Jhlm4/Y75rqg0hqnZXIinXGK7W0KrKghGBYLcOOCdiqRGeR?= =?us-ascii?Q?AsThQZgKcsD0Zlujas8rHJIL78nmFMRuPnoddGtTi++G1xQhCgzaBGO1d8d4?= =?us-ascii?Q?vyrVqQ5uXmKSiq6yJsubLHoNOiDSoJm6othYzXQ0BZDv0MYKP+f486EAh0y8?= =?us-ascii?Q?zDtdEe1084qBSzMD0fADwxxmd3WXa6TNAfIlY+nPOwowkkPuGdM11Amqgzh1?= =?us-ascii?Q?c0ze9QRaUYfDgb8onaQoXr7Ahr23uCrgL6nSH4f2MRam8Cq0vTrWyAMkqT/+?= =?us-ascii?Q?0yL7GyVH5Zy2MkR5jbCKH1pE7eBTKH9pPYbwmvmKxIO49OpI2Yh2zlJ+boQ6?= =?us-ascii?Q?dDL44A363VOHSZO1Rh5QmSMGN1O9xM7NMpilZ2kyHPIPr7DvhMe5Fe4f9ieC?= =?us-ascii?Q?2QReDXyE8z1+kbh8r08bL8OlxcEN7JHfAtbKb61o7CD/OudaDH0tcvvkj20V?= =?us-ascii?Q?hwSgybEMP3uwex2lUU8gCmii9FtFPAX1IcoDaba18OBWp+GSjEuOR8F/BlIR?= =?us-ascii?Q?6i2ofBcgDkdOPsgrTQknTOw=3D?= Content-Type: multipart/alternative; boundary="_000_1B2B2BF04DEB4957AB0EB35687E09586oraclecom_" MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Q3KM3SecI0Cc6Pm1e9mTjcj62RVw0TpFOOhAP/+t9wo65FM3OyzCrnO4PCnL9iVhCiCkKhpgvDOzADtrpo2ddNxVY3+uFR5Ia8sSsTjqNzS/LKRSHepnmLhT1+UzHEKRUtJIQOGnlXqZINPF6L1dHt0ecysSjtNDC3u7LO+kAottoMdj+4CP1NWZ0/tsbqmaApAuItVPfcasnQKw4UCxpi5rXDgUZFJbel2ovB9AxLtcW6wXh7Tbvs7BYQSpYMYEJNGxeLT9Wo8UEcHUXotkXxBxtKeQloHi04z1mcypK1BftPfVyzQjdQ7GUZwVP83P2tcPIYZ+niy9F3xgoiaN/RJt0ilVeJLizyoPkL/iYrGdr+KGOIQEzhBX1TVxI5qwe0ej7vekEnm3D8ZhreTRW+twhrC1egHYpDEAfr2113wNS23F2rD850BWzq+roiXwWmswZIDeszgYlv1SNf46kqZ0AsHRiHmVTPrgA/aUq7i9v/y04J2f5Vicq/vOoQtNMZ9om4cfYHfoWQ9WlyDopt8MkKK2Rz8YLC5VSBQeLx1WtFnF3OolcE9j6K5/+pcwhCYWEw4Z4ytlz9f1yzzQX7SG/cPRjfVJw0opz+dzg2w= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a7245814-6a85-4a5e-c4cb-08dc5a2aab32 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Apr 2024 13:24:08.6598 (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: DLybU2i/w2f9ouAF0SuIqKD388S4chuUNi2p0TWf/mz05uYV6NpmQPGuOI235kcKTGp+kzlhdaNaL2TCE5hN1A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB7425 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-04-11_06,2024-04-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 mlxscore=0 adultscore=0 phishscore=0 bulkscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404110098 X-Proofpoint-GUID: EFw25md0EuXw_m_hfqhCC-mZjOesPF22 X-Proofpoint-ORIG-GUID: EFw25md0EuXw_m_hfqhCC-mZjOesPF22 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: --_000_1B2B2BF04DEB4957AB0EB35687E09586oraclecom_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Sid, Thanks a lot for your review. Richard, Could you please comment on this patch? Is the middle-end part Okay for sta= ge 1? Thanks. Qing On Apr 10, 2024, at 17:48, Siddhesh Poyarekar wrote: On 2024-03-29 12:07, Qing Zhao wrote: to carry the TYPE of the flexible array. Such information is needed during tree-object-size.cc. We cannot use the result type or the type of the 1st argument of the routine .ACCESS_WITH_SIZE to decide the element type of the original array due to possible type casting in the source code. gcc/c/ChangeLog: * c-typeck.cc (build_access_with_size_for_counted_by): Add the 6th argument to .ACCESS_WITH_SIZE. gcc/ChangeLog: * tree-object-size.cc (access_with_size_object_size): Use the type of the 6th argument for the type of the element. gcc/testsuite/ChangeLog: * gcc.dg/flex-array-counted-by-6.c: New test. This version looks fine to me for stage 1, but I'm not a maintainer so you'= ll need an ack from one to commit. Thanks, Sid --- gcc/c/c-typeck.cc | 11 +++-- gcc/internal-fn.cc | 2 + .../gcc.dg/flex-array-counted-by-6.c | 46 +++++++++++++++++++ gcc/tree-object-size.cc | 16 ++++--- 4 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/flex-array-counted-by-6.c diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index f7b0e08459b0..05948f76039e 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -2608,7 +2608,8 @@ build_counted_by_ref (tree datum, tree subdatum, tree= *counted_by_type) to: - (*.ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, 1, (TYPE_OF_SIZE)0, -1)) + (*.ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, 1, (TYPE_OF_SIZE)0, -1, + (TYPE_OF_ARRAY *)0)) NOTE: The return type of this function is the POINTER type pointing to the original flexible array type. @@ -2620,6 +2621,9 @@ build_counted_by_ref (tree datum, tree subdatum, tree= *counted_by_type) The 4th argument of the call is a constant 0 with the TYPE of the object pointed by COUNTED_BY_REF. + The 6th argument of the call is a constant 0 with the pointer TYPE + to the original flexible array type. + */ static tree build_access_with_size_for_counted_by (location_t loc, tree ref, @@ -2632,12 +2636,13 @@ build_access_with_size_for_counted_by (location_t l= oc, tree ref, tree call =3D build_call_expr_internal_loc (loc, IFN_ACCESS_WITH_SIZE, - result_type, 5, + result_type, 6, array_to_pointer_conversion (loc, ref), counted_by_ref, build_int_cst (integer_type_node, 1), build_int_cst (counted_by_type, 0), - build_int_cst (integer_type_node, -1)); + build_int_cst (integer_type_node, -1), + build_int_cst (result_type, 0)); /* Wrap the call with an INDIRECT_REF with the flexible array type. */ call =3D build1 (INDIRECT_REF, TREE_TYPE (ref), call); SET_EXPR_LOCATION (call, loc); diff --git a/gcc/internal-fn.cc b/gcc/internal-fn.cc index e744080ee670..34e4a4aea534 100644 --- a/gcc/internal-fn.cc +++ b/gcc/internal-fn.cc @@ -3411,6 +3411,8 @@ expand_DEFERRED_INIT (internal_fn, gcall *stmt) 1: read_only 2: write_only 3: read_write + 6th argument: A constant 0 with the pointer TYPE to the original flexib= le + array type. Both the return type and the type of the first argument of this function have been converted from the incomplete array type to diff --git a/gcc/testsuite/gcc.dg/flex-array-counted-by-6.c b/gcc/testsuite= /gcc.dg/flex-array-counted-by-6.c new file mode 100644 index 000000000000..65fa01443d95 --- /dev/null +++ b/gcc/testsuite/gcc.dg/flex-array-counted-by-6.c @@ -0,0 +1,46 @@ +/* Test the attribute counted_by and its usage in + * __builtin_dynamic_object_size: when the type of the flexible array memb= er + * is casting to another type. */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +#include "builtin-object-size-common.h" + +typedef unsigned short u16; + +struct info { + u16 data_len; + char data[] __attribute__((counted_by(data_len))); +}; + +struct foo { + int a; + int b; +}; + +static __attribute__((__noinline__)) +struct info *setup () +{ + struct info *p; + size_t bytes =3D 3 * sizeof(struct foo); + + p =3D (struct info *)malloc (sizeof (struct info) + bytes); + p->data_len =3D bytes; + + return p; +} + +static void +__attribute__((__noinline__)) report (struct info *p) +{ + struct foo *bar =3D (struct foo *)p->data; + EXPECT(__builtin_dynamic_object_size((char *)(bar + 1), 1), 16); + EXPECT(__builtin_dynamic_object_size((char *)(bar + 2), 1), 8); +} + +int main(int argc, char *argv[]) +{ + struct info *p =3D setup(); + report(p); + return 0; +} diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc index 8de264d1dee2..4c1fa9b555fa 100644 --- a/gcc/tree-object-size.cc +++ b/gcc/tree-object-size.cc @@ -762,9 +762,11 @@ addr_object_size (struct object_size_info *osi, const_= tree ptr, 1: the number of the elements of the object type; 4th argument TYPE_OF_SIZE: A constant 0 with its TYPE being the same as= the TYPE of the object referenced by REF_TO_SIZE + 6th argument: A constant 0 with the pointer TYPE to the original flexib= le + array type. - The size of the element can be retrived from the result type of the ca= ll, - which is the pointer to the array type. */ + The size of the element can be retrived from the TYPE of the 6th argume= nt + of the call, which is the pointer to the array type. */ static tree access_with_size_object_size (const gcall *call, int object_size_type) { @@ -773,10 +775,12 @@ access_with_size_object_size (const gcall *call, int = object_size_type) return size_unknown (object_size_type); gcc_assert (gimple_call_internal_p (call, IFN_ACCESS_WITH_SIZE)); - /* Result type is a pointer type to the original flexible array type. */ - tree result_type =3D gimple_call_return_type (call); - gcc_assert (POINTER_TYPE_P (result_type)); - tree element_size =3D TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (result_type)= )); + /* The type of the 6th argument type is the pointer TYPE to the original + flexible array type. */ + tree pointer_to_array_type =3D TREE_TYPE (gimple_call_arg (call, 5)); + gcc_assert (POINTER_TYPE_P (pointer_to_array_type)); + tree element_type =3D TREE_TYPE (TREE_TYPE (pointer_to_array_type)); + tree element_size =3D TYPE_SIZE_UNIT (element_type); tree ref_to_size =3D gimple_call_arg (call, 1); unsigned int class_of_size =3D TREE_INT_CST_LOW (gimple_call_arg (call, = 2)); tree type =3D TREE_TYPE (gimple_call_arg (call, 3)); --_000_1B2B2BF04DEB4957AB0EB35687E09586oraclecom_--