From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id DF6473858403 for ; Fri, 12 Apr 2024 13:54:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DF6473858403 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 DF6473858403 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=1712930104; cv=pass; b=CiWXbhhVg1vnzeSP64/A2EnvYnREIIOgI0AOvHS+AyfMF/YFs2RMPtxNtC4E1Uw1ccub2cZDIKZU7B8y5kJXHE9SjOLOKjVKYIZ/UKKlOdobBOA8xXjq9YEji7jn3sQNG7O97LynCSNCskEi+47yJ7qRN0yioXfLpsFC2HTOOzU= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1712930104; c=relaxed/simple; bh=Tp7fVz/qePzkjUGJIjpyguWwtk53aaYSD99UTxH5kLA=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=r5Agi3dJIQNiwBQDfw135b9LW0jYL9ZKSL/j2TIRZQRQvjhOJYjcFYjJdoosvlyEzTeNKtl9KLTpmWwSlbobzhHmDWANMRu6wvxRpiKzr9vLirbTxZH4sS9UkqYaASc4z0196jLUu5tmEwi9sN8Rn6nnVA+zPyrrUT5Bgrb7wBk= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43CDj3Md023471; Fri, 12 Apr 2024 13:54:58 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=F7BUBOFE9RqyYj0U8aQVUhUhr1s0aa/jcoPQeW5qKuo=; b=SBeYOTUCSm2K240Rnz1V8sChRSzVTd5Ga8cRNulLUxdeaTTUk8+bImuyZSYF6RkC6hFr ikAXuHBZIT6psRO5clmWtMu6BAO+zFEHGGHRud5b1vogosP0SaN7hup2opxMyiBoByho 7zlQ62qY69LaXOvWjl/wj1p30zx8EPv/PJTPmely4b117a804TE8N5CU/64azLiA5yjX kajXqoXGR8vg/l7b0kvnrVrKkS54lqZzNcGl92Rv3rIVXfgGb6FzEWWw0tvVZASrYO+O iiKs2NkYFwZJ9RSHM4HUWoj4oWnUYMIH3+/FtODtiwZQ1SSwqxqrl7wivv5M72dJ2hBh 2g== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xax9bbpfh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Apr 2024 13:54:57 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43CDCHcq032527; Fri, 12 Apr 2024 13:54:57 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2168.outbound.protection.outlook.com [104.47.73.168]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xavubqfg3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Apr 2024 13:54:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ETg5+zAa1iCcFbHNmLBBe0j//KhXgbGT3vbpYvoxJBeiUPnL5eW99rXw3Rnk9IUyRz40h9HacrKvt+ib4c9uCcgMGJyCaok295OBIRaZX73suq6mrQIQs9JTDRJTZqf30RtGTFitljD/MYbHvQgkVPk89SMTfMtCrUXyMv1kULMO+x0YPrtYPdb03bg+m1Q54yWPbe/23nAKz/+h1IW3O3AxLmACqRO/kxsaukic3mMvQMmB08+LpimWGwXC4m49QgaeDUPTH2oNXP7OZ+BDNDJRDMNMNoS9PrEAYLIbTEo7mEtMfhWLjl61gJnORjk26fztZmszU1s7D6nTQwED5A== 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=F7BUBOFE9RqyYj0U8aQVUhUhr1s0aa/jcoPQeW5qKuo=; b=K+EgY1ay0+POYoj+SaRnjDbOxTNBdMUDQrbLpcVMidaGB/TJ5pa1leuMz1b0jJ7Z9Sh6r0JxxAoo9QBBHmBA6JLqRy2DTxdyPBP/dHdfY6k2dUM07EJYpWIN6FyVENowKefLle03e/Fe1A3LL5nUfL1evKXYRrVVz5116tvjlhDCfZHh0RBYZQBkP+RjT+QkhQIIlxgKTd2CO2NkJlZMeOUjz4zH3NBcFz/HRlvfpC/e1XAJAY92myxnnEe/xDYObHTqebLP6IykrGN8UhdNOYhIUhiftX69pU5xXp+uHn+aYyF/1TEtUqtkCaEHw+Dm0BbuW0pB9eBZrv7tlNeRbw== 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=F7BUBOFE9RqyYj0U8aQVUhUhr1s0aa/jcoPQeW5qKuo=; b=uzU9f2d/osoraDxN3hbg0qHNI8FWWzjr4sIQqJkyTeHqY7SIORerimhKjNyNhjD/M05dmCh2QQCNNc1g69b3bWTTM86J6XNLCOETPXPVevhwazQvG5a51AbwRdxJEr4/tFXr3gbOv6q/LZ2beKHEsMwL2I3P0JH5ZJTtW9zX5WQ= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by BL3PR10MB6114.namprd10.prod.outlook.com (2603:10b6:208:3b9::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.55; Fri, 12 Apr 2024 13:54:53 +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; Fri, 12 Apr 2024 13:54:53 +0000 From: Qing Zhao To: josmyers@redhat.com, richard.guenther@gmail.com, siddhesh@gotplt.org, uecker@tugraz.at, keescook@chromium.org, isanbard@gmail.com, gcc-patches@gcc.gnu.org Cc: Qing Zhao Subject: [PATCH v9 5/5] Add the 6th argument to .ACCESS_WITH_SIZE Date: Fri, 12 Apr 2024 13:54:30 +0000 Message-Id: <20240412135430.4122328-6-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240412135430.4122328-1-qing.zhao@oracle.com> References: <20240412135430.4122328-1-qing.zhao@oracle.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: PH3PEPF0000409A.namprd05.prod.outlook.com (2603:10b6:518:1::46) To CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR10MB6538:EE_|BL3PR10MB6114:EE_ X-MS-Office365-Filtering-Correlation-Id: c25f13e2-1301-4ebe-2beb-08dc5af820d4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: drngj9nHPWM1sHb5/2wz3/B3NrbZPBRnUw8k07cergD9I6kAvCMI5I5ampJSy2I139liSBWeYmnw0syyjDnI3RAR7M1NUQiXMscwAEfpNxtxH4/36aXYK/A0z0Az8b+BdFw6l7j2GEaCkmz6OSbP+pkB7AvBCy08e+JqosvbPx94/amWPZQi4uU0Kxu4bWJvZ+Tfd9TPtJE3nYGXVrfs14owyOLvmLehI0qbc+ZxYOxILZjyRbNWKKl5jtBdciP5rZl8/F4qroaQOQvM4tO5dJQoCf613DIfxhZl/FUz6k85HwOXYF+9X5rzBAXNg36/5bfI+a3zRn2U0FmwJDxxTG0icJ4w2wu/oEwDV9Y6rjHvK4AJsMugx7HDRfBESJ+6X4XnEYlvHm6IxwL1z5UwgqGgSNhS0mPlFQVDb/4yoykug4D+F48tRF/jxTTObE+z8KnehpY3goEws6cK7GY8b8Nof1JGmybaBHzoQVPNwX9t/OIVRQ1jLepJtL6qiunTeNczi/rXgtFIWiTjtcYmklWLdNmfxbfJN1o+j+2g1+r6cj8o8b2vtqP8LuuTihHBBDtssu/GksDvefYREfLvnQWa56rwJYa+U3qiz/z9OCM= 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?E2POAHY+OxZCGyedi9DD/A2EX/8uUp8rtSZbu39Rjv8n0D+auASPuuyaxsSX?= =?us-ascii?Q?FZzXG0PJoR1zZvxINoelXTnmbQDhFoJXmsBseTdqBC+cIcFSH4A2RMGZRExB?= =?us-ascii?Q?ZCxlZvA3nKAo6j7NERtyov7aBE7dAinDvndBVnhCOjadGyzmYHrgk+EtC71y?= =?us-ascii?Q?JWIn0XjtQXE+i7KHEk1Ord8ShlXT2xhElhgUduBWB5AGbgHXUN+bJfdHBnVI?= =?us-ascii?Q?LjqSvOIZfVFCGX5JGT+ySpJKo3HPuJaLnfXfceDXKd9lb3o+7v/d6XknW4DJ?= =?us-ascii?Q?MnlupiLAb/hv0jxbixGwXc+ryCfZ6J08AVnNdnwIz2Kpzv5J9s1hVZJ3swAv?= =?us-ascii?Q?IQCS7a5VY+i2/U3Eu3pavXA5T6rmXrutjjxW/7uBJAy5faDgvy6BS/FaYO78?= =?us-ascii?Q?/oQSaw1w/RLls0uaq2asWLvQ2jMmWGkJwMJjP5V6sUolbcDG72kOZAGqsKRM?= =?us-ascii?Q?u+8jiIVj1+E2UnW4rpnVIVHjZTfTyTYb6N7fPYFQTnkV8k9PsiC9AWcLtO6X?= =?us-ascii?Q?UHSTHvTgfy2KBMiKgCDovLnpYpvKHDMQ9SiiTOk071EbEOPIeUnJIakmI3be?= =?us-ascii?Q?EUUIeloGOXU1Fc9mhcBeH5Lhfl+hUawut3Yb8lsiUMiKoDoHPj21xYeTYNQ2?= =?us-ascii?Q?Gtiym7qO8LplPFws5vuTPPAePDkgE74XnHXXu+LDeca8S+jo3uaxMDf64NIa?= =?us-ascii?Q?+2oqzgwuaRWd2OqC3A+xqQQhc3v+n3Af3HVL/hD+n6tolz7SGpdDpdiLQt3f?= =?us-ascii?Q?/Mi/h8skT0/DF3UVeVbcXopMmmfIWofGguyhm/5aa1iWAKAwvWeRJmU5olkl?= =?us-ascii?Q?S0Ssc58TMCeKRFJ0SzWR245Tbn1ZARjYrKOFCu2Pj6YNyul/721/TLZ9u2TJ?= =?us-ascii?Q?Dzw744pVimSmvELLF+xcq7nPuM5XkkAH4bSuDE0V1t3au2dfk44VukCRDf6F?= =?us-ascii?Q?VABT07jI39ar7Tfc4fyFG3nVGGFI3pRtTUohMGahp8O2h8svMo0Y+JQSRarw?= =?us-ascii?Q?MNXTiB88cQPDX0Pxo4ghGrfw9hRmUvPvIUgYzWghqIvAVk7LAkkKEjUVaISJ?= =?us-ascii?Q?MXRfPiXfTu8EVybwtZi4LcAeohX4Mmt9oTEQH+uCOeLx3O2h/egLKIpYIots?= =?us-ascii?Q?WzZ4pMYJFMKvo3wyVeZ8FFpjVeNpL9hZugl11XSM9iQkyZJGDqRBv8uLKqt6?= =?us-ascii?Q?rA/IgqmxuQO2SLAOCKWW6uwLuTp3E0HwE/Y0pxJjG8s988GT26Pb9smN3bTf?= =?us-ascii?Q?vp6RL+RqGMKCdRccEiCxQbMerRcjMGK+2XypWqCtNBcxmJqI+hVDGroaYpPj?= =?us-ascii?Q?5IbKYLgdCuCm9opruXfcT8sQbK3S2uoVfoztHew+NO8jfoeu81e9IN9dHtRK?= =?us-ascii?Q?JDqeX87AhKHMSpRVEemI8bl1IC4YZENMqoGR0CJ3zQal5T+cqY8nOMWIDWnu?= =?us-ascii?Q?cqDptoXphulqvxfkpmdKQlanEEPMJUt9rxufpcXmLKhXhlDEKng/OxIyXx3k?= =?us-ascii?Q?kWw6WtCPFhFkZkdzpXJvXN9BZF1uFXG5gr7iXK/gDUCXGxkdi7oTBbG7WQvz?= =?us-ascii?Q?fPv5vLzkcWjMuFfJ8rEC0yYX4GZlMj927iza/ic7?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: phExjfuuLY2eq5MMnh6sJMaztkACsRBFrgYrWy9bcuRGGJlqth2cLEyGDhdELqfXhRchDaY4sskxSLZvU9/2QDJzJciIEEYGNA5uHBPaGwcmBUFwKFdusHA5m8vuTBj91PAOFGd5rel0+7AA+661PJm4dThq+Y6yJtMxvwDw8E8NQSx32bTc99+8C1W9V/r47yAuxYjoukTtj9oeOmf5A0G8LTMSjfnDfDq/XoLNdiXBPZaTbXCf/aPHBK6EZqJSXSZfqL6o3B4rXSs0hkZ+fVpN1IsFjoZ3vFnzdE4xrEpxKNUqpbV8y8PlnOUGNE+h5asG1g/sOwGfXnWEtu0Gp7JdE73y1BpkNYudfP+gZHS+/V2rwO3ogJIKTMPA9vEfWi/ycmr20xFOMemLTuuN1NeF36npGNIX6vCxn7UNhJuzspoCOh5iBCd+9W8TQdFGyzDNC33+SDCRs5acKRIXc/rVmhTXCz1mOSEq1jhS1IVd8IPSBwCjMLQUEqnspAwyhbdGkDZ581/piJ8YDSsmN9Uh9hyy0tZmzta5kYR2RhsFydWjDlfxEtmacz5HO7whOgBPr51O5Cs0sNrDpHOQIp/kvUgQiYSUIFdbrq62PVk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c25f13e2-1301-4ebe-2beb-08dc5af820d4 X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2024 13:54:53.0328 (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: 7D1JQjPvdyCCHHdqI7+9LW8zAlT4/GbFQHnCZbsZBEqRAfrwPq0fT9QM34p8V4x15q7kl5MBrlVPzxBemafuLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR10MB6114 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-12_10,2024-04-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404120100 X-Proofpoint-GUID: sfqrdf6v-ElOfkzvkuXP7n5OHd7KIW7o X-Proofpoint-ORIG-GUID: sfqrdf6v-ElOfkzvkuXP7n5OHd7KIW7o X-Spam-Status: No, score=-11.2 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 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: 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. --- 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 ff6685c6c4ba..0ea3b75355a4 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -2640,7 +2640,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. @@ -2652,6 +2653,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, @@ -2664,12 +2668,13 @@ build_access_with_size_for_counted_by (location_t loc, tree ref, tree call = 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 = 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 flexible + 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 member + * 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 = 3 * sizeof(struct foo); + + p = (struct info *)malloc (sizeof (struct info) + bytes); + p->data_len = bytes; + + return p; +} + +static void +__attribute__((__noinline__)) report (struct info *p) +{ + struct foo *bar = (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 = 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 flexible + array type. - The size of the element can be retrived from the result type of the call, - which is the pointer to the array type. */ + The size of the element can be retrived from the TYPE of the 6th argument + 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 = gimple_call_return_type (call); - gcc_assert (POINTER_TYPE_P (result_type)); - tree element_size = 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 = TREE_TYPE (gimple_call_arg (call, 5)); + gcc_assert (POINTER_TYPE_P (pointer_to_array_type)); + tree element_type = TREE_TYPE (TREE_TYPE (pointer_to_array_type)); + tree element_size = TYPE_SIZE_UNIT (element_type); tree ref_to_size = gimple_call_arg (call, 1); unsigned int class_of_size = TREE_INT_CST_LOW (gimple_call_arg (call, 2)); tree type = TREE_TYPE (gimple_call_arg (call, 3)); -- 2.31.1