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 918663858432 for ; Thu, 30 May 2024 12:27:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 918663858432 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 918663858432 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=1717072042; cv=pass; b=qbtc5yfoHDvGeszHnyWkIeFiwQzzYPzMKd71v6/NhD/oMRGiXNvHrgUOIJ+awVmKO3QylDcsE3kwGD16JbT0JPxs0RvideN9VGNrq/YLd5ymxXJsM+QOuEoy41KQIDPJrdK3QOHLKw1D6Wx9MQMSBzdd3g41WX9wnFpJBLeRDEE= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1717072042; c=relaxed/simple; bh=A9MKK9MDDxBPckL/irt7Gzpd3jhy8MvDhhyQP1uU3c0=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=ivyRKD/FjjXI9pXgBCJCFINVmU/pOD98G7WnOdJ+JfjDZGwQucElhO2rUfSRQTwefA4+FTIISTrIoQ3Di3bDVMv75oCZMO3ZslOfCm7aZI8BMLcAVfVTZbPb7vye04YJypVS8yhx5oIi4+MX7uTLJuUq3lDBCpa71M8W7HPNUHA= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44U7mt8d019749; Thu, 30 May 2024 12:27:19 GMT DKIM-Signature: =?UTF-8?Q?v=3D1;_a=3Drsa-sha256;_c=3Drelaxed/relaxed;_d=3Doracle.com;_h?= =?UTF-8?Q?=3Dcc:content-transfer-encoding:content-type:date:from:in-reply?= =?UTF-8?Q?-to:message-id:mime-version:references:subject:to;_s=3Dcorp-202?= =?UTF-8?Q?3-11-20;_bh=3D+uxsV82XgakOeCOah8hKCUObQtKJE64dmJMNRrdC1ZM=3D;_b?= =?UTF-8?Q?=3Dm1Ue3hYcjeRCdjAd2ddaC1IpUIxTnuDDCnBC15mAhHpVskq9BrArWi/9OwrN?= =?UTF-8?Q?zMJVOr4c_Sh5zzXO7kuNJK1ammuluLBuBFM/IH+vGnrYc+j9+i9pObAngQVUNja?= =?UTF-8?Q?hF2WGa/4YzD4fQ_7e537f61yWXoL1Yy6uZ8PjGIu6ytekU+jSZYNweIfK6HzuPt?= =?UTF-8?Q?RI3WgQyv8kROgE/RvC3P_+n429f+1lgU4TVBsJ9LWflEHDbAwi7cX8NSm7fQNsx?= =?UTF-8?Q?tXQV87f2hLZFNib1UCpsVLOZP9_o90hx4dphln0IVRJD9/MQGdR0HWkVp/rKBSW?= =?UTF-8?Q?Xa6kFXl2sMIj7vH+jtO49WcVTbRod+vP_tQ=3D=3D_?= Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3yb8g9ryqf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 May 2024 12:27:19 +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 44UC6j43026519; Thu, 30 May 2024 12:27:18 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2101.outbound.protection.outlook.com [104.47.58.101]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3yc508fwwb-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 May 2024 12:27:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bqkL82nw/p+cpT0xDv+Aef9brGXuFjKmjyWo0Uq4nEUW/XxQQG6Bs08AFiYctVx6Leaww7UYW8VFqNX4yT0bKZgse013D4bD4FfZL+AJGwxC85dtY0U78OJvPpCOZo11Q6GGM1aKgrEPmSlMIiJcAMvIvP8WEr/nunk3R9CjPvNNvMQNbEFnx4z0YYYCNuMrtcTYiraJ4cc4YaH8rwxwvdUy2AaI86pK7mXKQVW4U9pUVFOhvE2PX7Kt7rF0iK9CjiRw+ILz9jwnFQcNu6rh+3PRwGIpsgm+H4eSffdicmDILGjJC5J6K6KwmigruE8XkotTv6R4jDjoeMPl6BKmMw== 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=+uxsV82XgakOeCOah8hKCUObQtKJE64dmJMNRrdC1ZM=; b=HuFF/cW2QHoimGwso0dlv/Q0YxNxq35RzTBK2vT00/uv/bSejE4WP7unMkwLTFkrq4M/bMMeNL9CrCa0O2uHKDYQ+SfdkNDvWwaESsWeFPbb1QqVsBb6NT34+E9aFalnJ9WwjAVKzldpkHjZtMJuzys8rnmbOXPkESo0Y2t1u2szgUqgo/+9zIgNC+oq1uD+3Xf9iIuCy6tWT3v5Dock5U0XqAlpQx+P+FqdgaH7EpPGb1Dhn5XV7/zVIHXJDy7LLmAcbfeis7QG002uvvwkU3rCyun3AqzPBRHdnZsCg33zzTRMzLduO+IUI7x8xK/c5VHhdBygLbUdlWJ6O0jiIA== 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=+uxsV82XgakOeCOah8hKCUObQtKJE64dmJMNRrdC1ZM=; b=DGW5Wr1RVvT1XDJRZjxn8MJHQofXtZp7HZ5Y4/P5HNwvoU8qphO0mT/qSCxT/cZkW7n2m5Mmgg5mZZWFPu1Oq2XojeXJgC+FPEOmyUj4Gm6tpcAN0LJSnCmHqwCzpTip8V/V2wgIPPIGupaIi2FPfFyR9Dp6fk622wUv9cbEWQY= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by PH7PR10MB6155.namprd10.prod.outlook.com (2603:10b6:510:1f4::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Thu, 30 May 2024 12:27:16 +0000 Received: from CY8PR10MB6538.namprd10.prod.outlook.com ([fe80::8a:61cd:764a:e47]) by CY8PR10MB6538.namprd10.prod.outlook.com ([fe80::8a:61cd:764a:e47%5]) with mapi id 15.20.7633.021; Thu, 30 May 2024 12:27:15 +0000 From: Qing Zhao To: rguenther@suse.de, josmyers@redhat.com Cc: siddhesh@gotplt.org, uecker@tugraz.at, keescook@chromium.org, isanbard@gmail.com, gcc-patches@gcc.gnu.org, Qing Zhao Subject: [PATCH v10 5/5] Add the 6th argument to .ACCESS_WITH_SIZE Date: Thu, 30 May 2024 12:27:00 +0000 Message-Id: <20240530122700.1516243-6-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240530122700.1516243-1-qing.zhao@oracle.com> References: <20240530122700.1516243-1-qing.zhao@oracle.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MN2PR03CA0008.namprd03.prod.outlook.com (2603:10b6:208:23a::13) To CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR10MB6538:EE_|PH7PR10MB6155:EE_ X-MS-Office365-Filtering-Correlation-Id: 716dd579-fe2a-425c-c0de-08dc80a3d733 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|366007|1800799015; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?BJYAjeJ+tFZeaSDAhfmH5oYY3DTtusHLJ6gtPTZKCM9KucmHS/Pm7TgtU6bZ?= =?us-ascii?Q?2RdeCDt93ZFl+XlXKgJSxnaEkN9rBVoULfzLKGshCLlouXq95I7h3PKdfbpn?= =?us-ascii?Q?02epVrfa1HvwmiuvnUrW7TQVJGFoICel965tRhQjyZg8aKbuDRktRwkyglgN?= =?us-ascii?Q?ErBqBDy2R+S3JLS7Y6Fv+X93wDYYwNK70lcr/UsDrVhJj5xkxStY/EPHPRGE?= =?us-ascii?Q?z21qxflRL6uLoJnC8N4wC0xBNxyitXSR2D6112nJ6bpbPM6mhwRPrKQXieZI?= =?us-ascii?Q?EaqvKVZXCnD5iTCsyP27IIZ87Pw7T2BI0WptBsxpFUhlmeZONiSPzlQpByrq?= =?us-ascii?Q?rD+IjnQxj7FG/RXvOMfosJCww2Qxjg7QVsy0wW+yS9YfmLsj0MBCXGhxsyVO?= =?us-ascii?Q?pzAg1WTKAN+qWE0n3mLlLXtrO72O79ZddMB7YdFt4n89ZiohIaQjK6tndoO1?= =?us-ascii?Q?Eya5jK0Oijzkf0Y9NW15R6AS9qI2eKpE/bQXElBqj2ql8Ay3dbxeUCV4DbHp?= =?us-ascii?Q?W5S938telCZ2YepYcHzRRLUQWr6xLXdv8rYl1wb05Ev1XEe9dnSL59hhuNbl?= =?us-ascii?Q?EHWutKG5bBFps/PsBhUhsRRobrW+4PGIJYJVrzF/WkET1BsKK8EHw2xbz70o?= =?us-ascii?Q?8KCHtWRk5YBNGalpJjj8Td3mngyIeLeqKp5Xkj0//jbPfTGDZEKgEKHK5Vl+?= =?us-ascii?Q?DtBnrV7QDZgmVOlKBjJk+urYYm8bMHktyADWDsmJWj/88su+eURr7JzKv824?= =?us-ascii?Q?sfZapY+NT3HauQH4yp8xuvT+hNeKapXbitKWLf+xh6zWTEH978r8Zy2mRjQQ?= =?us-ascii?Q?YZYrtuo89z4nSvBPqUq2uDgsbgLn6b24G0+cUTp5E/nh6hxcdeOC81XLW/bs?= =?us-ascii?Q?xyzhQ5kHI6u3/8BbNDTBeOwGE0k12oPhQCDRAdQzgaxr39hGvqSNzDdLK5Pc?= =?us-ascii?Q?TehCU8QSdrF0aY+Lp6O3I8O6d8dPy1VGp3W/R2N6hKdcVWs7Sj2ZdQ4tEGec?= =?us-ascii?Q?WR0IaDrr6PGkMUx38sUbIZON3MxXx3kiZ5Ob/jhvg9QZt+qSms2zTajxsmL+?= =?us-ascii?Q?qA3l8meFQHrxLDs1KWHu3GdhQXIQ4n9rjzri8fA0fXySpbvGW02J1IEHUuH4?= =?us-ascii?Q?9A8TK70sq6W03PKnyQ0z1pdDk3yasI4aCpJoIOC9f75tmbVRzDahPN4FWEh8?= =?us-ascii?Q?9ScAjXhbSTj1ZqiU4cmWnzKTQOz7892VOH204Ozof6ZiCHScn/xRmognON0?= =?us-ascii?Q?=3D?= 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)(366007)(1800799015);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?q5mtUpNJdmcLPE/dEKzmJMCjvSmE+jXQUc/MyFddje7PN6MHHVhnBGeE3bn9?= =?us-ascii?Q?nD9NMnHhIefb5K8MgRMwrM+eattNwMU4Xm+FqH26St9kdqjhsFdV65SXGYTi?= =?us-ascii?Q?Pnk6JwCM5a/39kzhytdCssVNIg87GlTJD9tm1UiRbSbzvYcwwRZc0B636fWy?= =?us-ascii?Q?QNKVwIlQ1f6KsPtLLHiLJQGAqE5zJrsIbsDC7NsGNUkxSf2gwsABlRHotQh9?= =?us-ascii?Q?hMkU6NNY8JHNnZD4OJcMm11Wwpd0ntvfA/CqQZgHIJahAv6bi+wEr+OgDdpo?= =?us-ascii?Q?xGQvGXO3UiQooNlef2WSL8fOLGd5BE+kdwB9cXZahhfMzF7HpuiL2V4wJ8i5?= =?us-ascii?Q?3uuVjkI1vzFKwmBcQaNec7ZSw/69RZStXEMdZo/IgM8QYQobmDTYbWFmfQC2?= =?us-ascii?Q?1f2JYVcAMYSVqBXWyGB7cb/jH4okCSw7Y/AA6KJUD+2leY4kEBz852Jh2QeA?= =?us-ascii?Q?E+RzqxedvVc4dZNbVQ8s02Ph6pPkUJruYhZTgXKUBHG4RvAqygF9UFT5MLPT?= =?us-ascii?Q?VzyP5mSw/GkA2Kwdpdm3eI7TJXtrBE2/AKrcQ8S5+X17nLgfG0NdxQePBJFn?= =?us-ascii?Q?aXMqifpykbRW5L94CdeSLBwI0/vlEm7VMGCUBIC+TyKhsnCuW9CDbwMrNvvi?= =?us-ascii?Q?WgllNI60QwilWibhMAVoGdogyEX9i3viLLudQ7P6GCFxqzTQELNS1/pKn3dZ?= =?us-ascii?Q?IiDxnOok83jq4PFl8nuR3lrTKNWbuq1Jom6rN+niyxwPxtldDqVP1LbaA6EA?= =?us-ascii?Q?0bKoWBv4HYS6PoqsTZc5j7uX3gG5bFFwfdMdfUKXG614/vzB8qXiI3udksF2?= =?us-ascii?Q?aO09pNGedq9fQlme0CaUsH5ezkORC44s8iH03KSmJELZqC7B69GDMA+nr+Zw?= =?us-ascii?Q?hJem8yD0ejTbXvF4zxCNxuB9b1ID/szRuj21EIs8SwPVtPIo+IwC7s0y7QJg?= =?us-ascii?Q?AqdkOgCS9QHv/LueTu7xTLe4e6kWIevj4yR8uxwEntDoghZAGUZphG6HmQv6?= =?us-ascii?Q?DfBVklG70m5bMw+bZAazODEEfbG1IvYpnTkCMNe3DfxfPUzQT23ZxAlEP0KA?= =?us-ascii?Q?5GdIuYjnsnXYPsoPkzMqvnpgwL6QTrIbOF7yKh3fREbNxLRSjDwwzmP534wS?= =?us-ascii?Q?b9do5nEYC8QX8tffQnbGLRAV/HVEwBEYjrybuoP/XT0dwmplFphrLzZ9Yt2O?= =?us-ascii?Q?9Rdjmnc9gd+VmR3fbpUUylxkKaYYcPo/B6tfbeVIGkj7DyMLGL68fuGOCIC2?= =?us-ascii?Q?I3nr8zHGrGR/MOnyj+XIaAwv0Z1MRChmihegcqNH16pQUlYaZ6Xtx0YhP5rZ?= =?us-ascii?Q?PPP/qE4LbqP37zQmkfbtGFkhSbHs6uLYJVK2psi3JMN2eFrHpBLPEaD4ULYN?= =?us-ascii?Q?m/r8Y18epUuAQWRI2h/s80kyZ/1f7JC8GCSPoL6D4SFTko4qvVEQuva1gkxc?= =?us-ascii?Q?DfkI3vfpApignD6V24OLWk3DYZCDySBW9YFtkwA2+sYo4CuRy5AoNVumJ7Fk?= =?us-ascii?Q?MkqcWSdYn7cCRG3Acik+2UeAJv9D5qrSn7so0E69yf3nk7OSOfKKVg16CL5T?= =?us-ascii?Q?Rx8OJVqXxyrvk9+Ounphzfy4qQe6BjkLJh4NbjE8?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: biFM4zRXi3NOyAzfUm0CeReZjSLArcFVA5eK2ACAIryGHux3VIxlgA3hA5duHLLHpkeCoViAfKlGDE5vaSQXNPxdUNSsV4yOLVBuN99/+X4iYJvAtks2S+fo+MMTiQnY3e6mPny3iO/ry8QJrQ2xhxX5+09KGeAPcy8zdFidC9inMcHnUxK/z9QsNjfeSlssrGzBdYSdy4frhcK74z0bufGEsgGOAcfxrfE1ahngFO+Xuozc76BqcfhYQNv94UdtdW6KQTBR+i7N1mpve40LzQG+k4+MSmiYKOKnz+tNXzB+4NhDQQJvPvuZRUsXVTusrZuJK5pFGFa8fV2dn8ATt831M726igXHcLhujWNddHrBIg+e4b8cD0jvhZ72ujG6jvDakO1dWs2a4Whr0Vs1upEXC0t5oduoSuoHvMNjhLKbTxgTF6FgsJub+rjndnHvMTqxEhds3L7YqxCEBwlS+EhfPQTka+VIurvguDYWzGpsFs9f6JMug5yBLDqoN9Pf0Cb1jPQKcJiJDiMs0xtcxzVXoFb3Dwoinv5mUPKcy566YeLo8mM0oVzYlR6m5DP8fgwvTu4JXnlg4aScfsP07Fu6T4vNJvVaiG+K4l20xYo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 716dd579-fe2a-425c-c0de-08dc80a3d733 X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2024 12:27:15.9326 (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: S5CECcnNAidlIwWijn+kzLh8a3TakLSf3kZ3B82J2N25Zv3aLxTQ33lZwGR8mwmuoGyW2W5sBw1qHlnaAbL4Zw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6155 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-30_09,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 adultscore=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2405300094 X-Proofpoint-GUID: xvm3gfEYqcptux3C5H4BsB-FwalTAx-U X-Proofpoint-ORIG-GUID: xvm3gfEYqcptux3C5H4BsB-FwalTAx-U X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,KAM_DMARC_QUARANTINE,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 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 0d9c7a34a0df..efd111305b5a 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -2646,7 +2646,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. @@ -2658,6 +2659,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, @@ -2670,12 +2674,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 eb2c4cd59048..0d27f17b2834 100644 --- a/gcc/internal-fn.cc +++ b/gcc/internal-fn.cc @@ -3456,6 +3456,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