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 F06943858403 for ; Fri, 29 Mar 2024 16:07:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F06943858403 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 F06943858403 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=1711728454; cv=pass; b=Wx9s+3cPleftsqUUf6XcSHy/Ny93oZCAnafoRqmXV8Uz2/wKpjOtXCMtj+RVXTnyAnzkcqfmD+d0FPnYhmJneE7I56s+ttV8iXcbEMrc7HOZX0QZdEFweOsWk1tnxTNOY4J2ECqgur6L/K/hvGMkLjO99TEoiyTtt0dSCw53h6E= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1711728454; c=relaxed/simple; bh=7bjX6iVvqWpVSBih/7auveEI4o0ttRTupMLEATcbYd0=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=ZK4ShkHirL1f+c5GTpD+iJa8rUf+/YTp6W4iCgN1zC2t30tjXvPSP6wXWp2tYnf1ITRGYwqa5fWkTHGK1bQgXFOvlV0g4D6mDLY4drWvOFE21OGyZd+mVKvkRQRDZxnk2mbAkrUg3p7rBLQFtIPNcIgwZoG0jofN7zQg2CpeIBs= 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 42TFO7vZ029883; Fri, 29 Mar 2024 16:07:30 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=AkqzJzCoZvTkFH1G/lDg7xg8Zn5aeK7WBqKf4Gj/PRs=; b=Yacy8o4rV/cgDDgDC23pW3edU0ICM6v1qdQozJTQ4hi0jhEc/x88p8eppeMTzq0zuod1 S+5LgcnhhHCmRquUAvU2NHh91n72oDmb0EjNFe3C5V4rm84GzK/6vguaEhoZguYU7U/+ wPeoOPYLM4yKwmT2LRsJYuKpy2TIZOMKgeEy1IT8UOrW6JrAiAbZdAOcheJuEMGsNx3j qjqSJ2zjx7xUDII6p5qQv7V+ajDRw9rPzl9M+ns49Ytl7/218FhoZuKOqZqwb9ef2n10 xGR9DzPAiXuoncXGKcUyb//qCOqBEho4v3Ty5fndkptI7bmZhvcnk/yWQgA4rpsHl+HN hg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3x2s9h2e5u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Mar 2024 16:07:29 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 42TG3AcR018111; Fri, 29 Mar 2024 16:07:29 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam04lp2041.outbound.protection.outlook.com [104.47.74.41]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3x1nhbn26f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Mar 2024 16:07:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N21U3I3SQv3pKI/K3MG0Jbio3UYPOymK9PgjEUZMjW4nHoOPOmpq+wDzCRjrCYvyUqJkqEyqoufvb6OPf5BkjWyyTVQbMPONIPDYgg4Ii/XZCWFC4j+KKGvNEdetT4nqs6dtxnaWONGAzLhU8CATKhskGRx49TbFbn+ryVChDfrHCheZFcVfbrbHJpuOQBFfGJc7zIkQYRnBzTKTcX3Af3eUCSUUbm/l0clZYK1cgxr7i1cthVgzV2wBgpQqxVpAaFPAIiZoXQVUXCXcP/XAOvFnoPwBJUGNyDENoKJVmtR/4H0MCZZZFnmUYszooYyhnXgIhp0c2PRwfGXOE8gXLg== 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=AkqzJzCoZvTkFH1G/lDg7xg8Zn5aeK7WBqKf4Gj/PRs=; b=kMe94bSg8VySOnsW1IF0pMZfT+dDxyPxdLGfH4YqyEIeu+SbLdd1VxbHKXztp1wLPEtT4xCaK5ZhFuoKjMk6TeNdfKCkOPrepHKMoW0r4ZWW6qhHOoaLQXmG4Ep3cXwWtIas3Rs56jMwevVeLq4r3dx1KsUlKBCpPJStSw9OmDXBxJhJU6uUcfXDS8By21Auq5xBhym33pCdBdo+eGx4N3W07CKK/XZk+xYicS4/yqdhNuJ101xDug2gYsiQcR6btA6xG7D33L93HrPEg1fBN+QyXzLvXIsCLR91/cajMPa3AkUfcbzTL8jzvfGi6muUEPS/Wm4UB7Pb/ZXatbYF6g== 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=AkqzJzCoZvTkFH1G/lDg7xg8Zn5aeK7WBqKf4Gj/PRs=; b=fOuIk+UmZS7m+4crRiIUgrnu7WXf/xvLODR/mm8Xk7uTwEVvpBr/DdCxTe1NhzfVp2Nbdhzy8iLASHQFu+2oO6iblp/hZqu9PHPHusCFHWP/r5WUVx7b3DSk+3cvXc/pnp1TofcKtoM8S58ITS6aybrV3/3Y/J6x5L4Os/7dWy0= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by SJ0PR10MB4638.namprd10.prod.outlook.com (2603:10b6:a03:2d8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Fri, 29 Mar 2024 16:07:26 +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.039; Fri, 29 Mar 2024 16:07:26 +0000 From: Qing Zhao To: josmyers@redhat.com, richard.guenther@gmail.com, siddhesh@gotplt.org, uecker@tugraz.at Cc: keescook@chromium.org, isanbard@gmail.com, gcc-patches@gcc.gnu.org, Qing Zhao Subject: [PATCH v8 5/5] Add the 6th argument to .ACCESS_WITH_SIZE Date: Fri, 29 Mar 2024 16:07:03 +0000 Message-Id: <20240329160703.4012941-6-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240329160703.4012941-1-qing.zhao@oracle.com> References: <20240329160703.4012941-1-qing.zhao@oracle.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: BY5PR17CA0041.namprd17.prod.outlook.com (2603:10b6:a03:167::18) To CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR10MB6538:EE_|SJ0PR10MB4638:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4Ih2MA2eEtAjRl62M2WEVNqfweTldMH/KLouH7OEXpzqYEZ2AJn2aw0UqbMlFAII/wFngb1qsUjC7M9kQHUMCnYYwRyx6p4z9qGkeAIORD70sFjudMI23ub8Nqg5b2QstQEInfIKNKZKbQImKg9u7+DsAWGvNTQfT3z0Y3yAl36rJCLCIVko71LFI/nueq4g6urtp1y6BP0LzPDBTMhtyEFdjoO/DcgF196/unKQvbj71j9/P//fVnI4a82dGwFnbvyREjXEI07+VWAj7/4P4Y0PQoHWvTZVrw8+YkLJlm+lioMg2vQJDWjumR2s5PUks3XQNcOCBlPfI9QmkRNvNjWnKpOYTqGanH5+3u3gOV8TCO3ZlDyGPVxo8cSe0XPeBQVkv7WTkupyJpAZA5rqg3/Exg9oA3b8jzaT5EuW5WqZXE/vIq0SB67KXGHsYRQBwwCvgQVgkSsAjqTcUTqMLeLhx/4oBJfJhHuET2hRuzJTiavgyXiTxnr7NrvMvX/yF0Td1YjEgB2US82hxWokNDEaFBE87FyyFHk1+SZfAE7IsUI6cpEhDMAZYcobsMCbHCTSXTK79IqMlEEGWSyQgyaiOeud5/CtgDITTb8XntM= 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:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?AASwSFFql4FxZFWfE9BAjkxiyY25fyWbuAesd5VWvWg7CgRMeGqvSSt7/nHV?= =?us-ascii?Q?rMeT3XexdVG1BW55nc3RAlEE8aaS0KsQuGRVQC9uEo17zIEKpwWR4EHOiIMZ?= =?us-ascii?Q?LHKD3N9p07Xf2CWbTbHk8NTXAv1lqQ5jiBW3JDw+N9QSjwAHa3MaYNDFDDCJ?= =?us-ascii?Q?uC+8Bl4pOwToWI9/U4i/j5DDP7j2nxi7hR/YbokTyucg/v98IKSiwD6i4Q9c?= =?us-ascii?Q?+64WdfCsTIwGkpDCC24+TlL6BICYvey6/ogSOLEaEGlnzYRmu2eoMZ4Oe/hT?= =?us-ascii?Q?Bf+eDmq2FxUHPftjl+2537qZwh5wYftGxaAyX3hEw/e3KUJftG5xRMo42dfK?= =?us-ascii?Q?hMlVlaRxqfJ4FEUfbqNNvfMXygQaxVxuYGH8xsbbd1rBMrn/7lQJ6wWyaWC1?= =?us-ascii?Q?OQix6tWvXixBasmLT/+XZPv/ESAkgKOYsl4JWIkc57Bcj/Q/vvG8zAkoeOir?= =?us-ascii?Q?sIa1QSR1mXMgat9rWE+Q3lh2O+JAbaAegbJ3uGbFOnlq/m2bPZgJIeUz2hJm?= =?us-ascii?Q?UPVYwIslpWGKMW41NdiyNZGePQTHiTH4L8UbFRqKbxF8jglIusUaH5f0Xw+D?= =?us-ascii?Q?4cvXvXwEm313vws4Ur9UEP4CUtM3PDQ1R1afrL2TYl4piCf4ZwEK2pJ5AL+A?= =?us-ascii?Q?QPYqeMn00s32NpQk9EluLptzw6O4rdu7uI3RLaUKV6SEFJYLo07GwxF/VE1T?= =?us-ascii?Q?7+ZaLeJbf4u8NYU7Fyy9YfCcONBkohzGHTzVDuS3x04bGal6rjAlj7+o4ipU?= =?us-ascii?Q?PH5Snoqg2MJqgxs4wK5PePI1w+NSS5SqTxnQoXBo1aktBEMItwCbVuYJXUS9?= =?us-ascii?Q?GJ25DDX7K8WBO7YS03ASD1Q+6bUkZzbWGWfMKz3AAUUPMySW5LuDCY1A24/8?= =?us-ascii?Q?obAHDHl2fSdRTIvJCAiRmphLcBY5un2/JqAR/FTPzK/Edk+0b3icgTp9rdtC?= =?us-ascii?Q?Ok6Y6pR2lpy+RmkUCzw/InjtEK92Jy5bUscy9hOuK8pouiHFT69FLQu3lVC9?= =?us-ascii?Q?CPzMyu0u+N0d42Kp2PKgLG6gWqW4Qe4+xW7ImmPyRoMzT2bzVwtm+TqdcPAS?= =?us-ascii?Q?1/8EXuGoz7Nt3NScvN9h4l/byROFmPKc2Qw5vKFj06mWlbKCFa/uPjUf2f0W?= =?us-ascii?Q?LfaZS7XSAYjup+02TJq5M+ujJe7ks1t1GpHlYsvKOMIhMiOCHbVdkTdqEr+m?= =?us-ascii?Q?+gZ2koWmyWTeqjI9RmK8rutUhaW3MF62HPXkqB9avQ6OM7vsxtDGO38qeN6z?= =?us-ascii?Q?OYzVSx0zplXB+7mm7jM7DF5wfifxuEQrW/dgbO6zH57eFZSLobPdVR+DpQuB?= =?us-ascii?Q?r+WnIj4jJJX/XMaz//oWHWndX2fsBFe3kGqBMZxPLfrulZHh9bEamf22Zcwp?= =?us-ascii?Q?qUwdqtgsxXNtb+Miq4nlXAeTemhbu8SYbvvqd9z96fm1UnK78VScKpl9IupH?= =?us-ascii?Q?orkPPIM9i7gqIv1mWuu/4TDwS2WRRCrLq0bh5NaOT3P554CAvlz1Wly0zKhr?= =?us-ascii?Q?w5n7QQ5aHgvK5Fnwet9ZeocOhHH0gw1KeCZ1CvejPLtalg9RVJyLAT7K+oNS?= =?us-ascii?Q?hg5hMRa/llRch44Kcnp5v3FgKpoUC19kjLiIqDFH?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Mgzs7zzaSPnsI0V9VCZvVs9MW9NSboLyQ0ZSeOXSkF8CGPF05WEr8XizjBP4kx+FfTfvfmVqzQflaiE3k88jApTpu6GkZ5eDxydHZpA5zSdp0N3HrG+wp3c+8ZTzQK720Pj4LuAOJwwe8t0DwoDeM/h9EhDqjVzmAlUSsPCAqntXzzjUAjzstrASNu8R48by6i4Bsq/IvhAoPrfS1AQed0ZQnlcSwYrunfjCZd1NBfqGUENRVl6Akeocr13yeR6ENhQaT9gJyrKe1bqN1Za4qgDvbNQGPdevQjA2LPhBAhRHFYgVPZBg37hjSHuXz0gw8VqVbtp+Q6TII5MgSzI+IlQkk0A/lbIl1EaePfOoTRp2/NQvK0lWMAyGIsNssAHfXk5JWYrTaOX0tvRqpIOyUk+xFAAwTvHrTYW9Ks42laQe4GOiIZZYOucAA7z/IuPbabw1yY0nx99GurD173bOMeSSPkWIPgeDH0+XHtceX2IkAkUwm99JpeX85fWMRJjaaxh0dUlztIkZTThOAbNgDK4SXFlJL8wIgpK/mSU1HvZmigY8svtQdM0zQaVqcrnTIVn+SNaM9+Nlkxa5SJZiDqkWdxXWltclGmVL31Nb2YQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1213848f-b0f5-4e12-ad9d-08dc500a53c8 X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2024 16:07:26.6842 (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: 1oM1aGyu+x8ojryL7wBQCp9KmMzfbK7Ppcim3eLxT9fV2ZwBxECye1H4nE/7dPEfQ7WjiueiNVDHHXLrauGKcg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4638 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-29_13,2024-03-28_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2403210000 definitions=main-2403290142 X-Proofpoint-GUID: chXn81Fvt1p3-flK2rpjvcG7m_NpmoUg X-Proofpoint-ORIG-GUID: chXn81Fvt1p3-flK2rpjvcG7m_NpmoUg 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 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 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