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 960193858288; Tue, 8 Nov 2022 15:29:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 960193858288 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A8F9fqF017665; Tue, 8 Nov 2022 15:29:35 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-2022-7-12; bh=4pxuBsoIFaTpiS3x02/wW9B489Yqh3TgajavKQlhLEE=; b=2ifx9ZWYv7kPuWPzRhdTDs31vkMqEunQFEWr0JifGkDdJOQslPWw2zWdv13bnIK7L0tF CNoEgQyz5U7P9p4mn2CJ+k10Q+/OhBbvS3ghvipSPzJO8CbZ3MIrcvyMoBck1X5unbkU Q5POucw0A+deaYJSG2XimMffMzjNUW4kA0bbd29frYC+a8UewERZ+jIh7XT79AfxFL4k Y7Y65J7c5yOMkOnrvJHfZDeZxj1UxhN0Cge3MTc9LQp7rdXyPCXD8MEd6sP+X6bjS9IV vduv7aFPWe+dFi1rB2hzl1jiD3c2iMrcxGEADf0ueWT2kQX/xo+Kl28bUAnzl80ry3Jj qg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kqsgrr3rj-42 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 08 Nov 2022 15:29:33 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2A8D4M2s025649; Tue, 8 Nov 2022 14:51:22 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2177.outbound.protection.outlook.com [104.47.73.177]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3kpcqg1du7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 08 Nov 2022 14:51:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DVB3bL+SaKH3tg1IzgSD3K89N+/Ct2esZ9wqUUgv8lqNUa0HCxu3ElSD764vdbSxMC3ZC8sDGlgnwJJ+NhxB2gxYzh9PjBwbTZ4nyQaRGpG0C2MODHP5XyIogISSy8cuW0LOFVGfbUMAzyrQsdOBxp/CdbY2QegOUWsCOHEB9s7qrdgCAPeFlVs67jTTDdHEwfEQc1DW520XqW4ejuw+5FGIn4IR7hryOnHpxAqmKHjfIS9v0md4GPnqPcTR67xlUPzOf+CS1wVb41zukoMTLHoZ5eBKAf7POLdkVoc0fUOGvUBeFEbPv779WpCqL2mdkTfJDCDDnLEUJknx8lIMtg== 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=4pxuBsoIFaTpiS3x02/wW9B489Yqh3TgajavKQlhLEE=; b=CWzLBoY/B+873Zz2D9ar2NyUNHtczAS2To2rttz3eSHU5h8+ErNqLIlHcwFwBzGCsx+fKpsflUAFDnsUnq6hbFCjVIFUUe1Y3I9i7na+c6/MTHwxG6pmnS0Q75RClkecjnsVl13+qr3MMGNOepcR7XkkaIZzpZKya2tUftNXvU0xkNVEQZ4JQYc/22g11sMGRWw2oLZta0yXmkefl5pLZg3akQplPMk9ZkOuApSlymRb3E5LuQqYQDTTl2oX6k24NywjiX2LhlryJsej9xJU2qb/N3eIFn5HzZMijbA1K0OcnUDn5nuMahwA/UXVCPHy1hCVg7hEoKxlDhSRdxdnBA== 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=4pxuBsoIFaTpiS3x02/wW9B489Yqh3TgajavKQlhLEE=; b=XlUj/hjpz4stbl+AincHVXaW8M+B2LhU+VXQ0a5JC5aoWKzVvWUUZX/ioWRuf0hyLVB0CVApwQcuq6q8PmRj2vWpXt4PFKtqPNuUHuun3j2f2umZnWzujcU/KL43sGPQEBxeiD6pzX5f69SssWBSc1J4x+4VF33B1gBoUsFAyq8= Received: from CH2PR10MB4344.namprd10.prod.outlook.com (2603:10b6:610:af::19) by SJ0PR10MB4814.namprd10.prod.outlook.com (2603:10b6:a03:2d5::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.22; Tue, 8 Nov 2022 14:51:20 +0000 Received: from CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::b18d:b9b8:8c1f:5f6e]) by CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::b18d:b9b8:8c1f:5f6e%8]) with mapi id 15.20.5791.027; Tue, 8 Nov 2022 14:51:19 +0000 From: Qing Zhao To: rguenther@suse.de, joseph@codesourcery.com Cc: gcc-patches@gcc.gnu.org, keescook@chromium.org, siddhesh@gcc.gnu.org, Qing Zhao Subject: [PATCH 1/2] Change the name of array_at_struct_end_p to array_ref_flexible_size_p Date: Tue, 8 Nov 2022 14:51:12 +0000 Message-Id: <20221108145113.955321-2-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221108145113.955321-1-qing.zhao@oracle.com> References: <20221108145113.955321-1-qing.zhao@oracle.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: DM6PR11CA0001.namprd11.prod.outlook.com (2603:10b6:5:190::14) To CH2PR10MB4344.namprd10.prod.outlook.com (2603:10b6:610:af::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR10MB4344:EE_|SJ0PR10MB4814:EE_ X-MS-Office365-Filtering-Correlation-Id: a700d8b5-0994-4f21-b7f9-08dac198b251 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OiUWx9rzfTcPqYov/166ilDRLhh8TMhSbzniCUDyuynZs4YK8G2byKybWNDu+c3GAX+gO3GeVLv/11NmAZ+9ELGjpmHu8/DbKSrGc9vjpTvKKRmKMlkK2YfJLIjxAI1whiyquEccTw0KPGel28SQwbWSn7DdMx0NzzngH7T7wv+2SKZMN4mc7AL8tWks8B/l6aYii2HjQ0spAcvkmiNWu9BZbi2HKZcjuWMNNH7+KQ4o92PG4eUso4CGbtm41KprP0cT0tTvCwIJdDaenBU0w+sn9m07reGV0VplvrnjkseuOvJnEE0iTkcG8U8fCVAj4oQ5daSIJ67nExh3XdkqnFWL2J1ABYDrRfhRBDDO4vv5Tt6USP1PHzefd4x/1BluHBrZDCsetfGp8K8OUK2H0RhkUP2DvvB3+/tOLd2zs5V41edDjOl+fiCbU7Xl+MhUC/tsQ3dHZxK0F6UKKKoAK7C/TApcZxRnIqiB3NkPgGmOY1yn2IUlvFlOL78DAtOwVMjex3/i9/wf+fqbxt2e6IWGcW4qyETeQ6MLrWpSde5IpH3PIAk90fon+sgkjkc5m8xEoU2/NW/mRn18xgm/Zm5KPQbmyUEY2N3KAfFbu2fmD8M/r75a5AM+nBel4SByHOCI6lJt7DVGI8ueBhO+d+GFhrRmxtsZZTyhsAbFFBhvNoh1Bf3wOnDVXssWf59ED/vBFhDiOIhDXH1GUZMEEw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4344.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(396003)(366004)(346002)(136003)(376002)(39860400002)(451199015)(2906002)(8676002)(316002)(66476007)(6512007)(44832011)(6506007)(30864003)(36756003)(4326008)(5660300002)(8936002)(38100700002)(66556008)(478600001)(6486002)(83380400001)(6666004)(107886003)(66946007)(86362001)(186003)(41300700001)(2616005)(1076003)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?OwUPig1ScNJAXItUOoLloBJ6mhgiBLZeEK81x0DXdW+TrShw38uioz7IcsFi?= =?us-ascii?Q?NydhgGjKN4TWrBzBgQMSehCgczRGzXK4dEbHPtBbRk3fv6Omf7SNjsErthDU?= =?us-ascii?Q?xkmzHUi+qo5pKvX6TYTFnO4E6m45cquhZSh83nQIP4ctOZ93f50dwG+iJ2On?= =?us-ascii?Q?Rg3i2fKmQgDuP/29lSaPZ+P/t+mB9TnuBj+agUBgy6yIxUrxI0lL6q1hv65e?= =?us-ascii?Q?64e9gcTQBIna6qeIeLdBPEdMhy+QQxTxi6YyCiL2uZ+WCUd0AZ5olIrpUUCx?= =?us-ascii?Q?3mo1oai8jKcC7OD2+GnvyJqhK6ePbc7CFxJV7DCgg5CQBIEmxHrfkcnr3J6O?= =?us-ascii?Q?mVzXBYWvvtiB1M6wRPCpRlG3SLug5TqM1j9KHMLN4hnkGPPQb/Zteq5GTHSp?= =?us-ascii?Q?vY23soDI+OAK0EcUqvjO/KXkuCbamBp7FJ3beEHZf8QpQx5ItxsQMQY8Kt8z?= =?us-ascii?Q?s8N6L2L6LAPWMXaKqrYvT3WVx40rA4xKw/bYJI+gVIMP7yhcFc/yBcosiLlb?= =?us-ascii?Q?6Tmvd/jHUus9L1h2aqDnIi0g6iB0EBd/jdWtmkz9fKBmXbs3/VOY1p6ke+fk?= =?us-ascii?Q?9I6wMNsl48i6N3iyR2er/P1d3pet4NeoWzJRA4BGZIBz8Mk4t0FqF+5WOBmJ?= =?us-ascii?Q?MgtvM0u/LMEGwMENjPNcF0XWIyyW4zA2WaCd2wo0NMaENXKJ183OW2U0kNzw?= =?us-ascii?Q?oMqqx3meHXGNSSBEoQoCH0gV8YF8ERQQgEQ4P4OWnaJ8TssAdDoi4PXP3OFe?= =?us-ascii?Q?7C5nEQ5ssz+AjfDscjzppje5lFr+pO36tEW9DdPkimTN/bqfxDcoW4MXCn5+?= =?us-ascii?Q?B2IRpQ7UWGPLkEqj2kgnrGx7Pc3KKUhwI7AwW9KtfRqP+GPm6wOHO4LPj436?= =?us-ascii?Q?JTtxzKfakhMIzgeW6tt9ifFPIRxbZmYAFOryFT7oTey9MeVjg5H3sCHSdGM0?= =?us-ascii?Q?3XY69Vb7SCD1kiXFA1ywCQD/nnD9xMquvC+wA9Hy2InQKLe785dSrLm3K1t0?= =?us-ascii?Q?Mu3+bEy9W+iGSjI22TOKLsUtDS8pudURhmUImVNjIPjPFHFQg30xbajPVfo7?= =?us-ascii?Q?/IJMl670+YPnqMjBIYhQcNdduhRhqnUU4QCUtmPh33K5ZDeQeWoUTSfHDhDS?= =?us-ascii?Q?cqRakjgsjBaWWKNYawHuc9lwR3RivJh5ezdmIIyTv9WvnEMZl2spJd4W0qhY?= =?us-ascii?Q?gnrE65/LmOx1awjcXU0Nsk9LlcxJuleRoD/U+hazIthdGkNQf4iLXkvJrQKZ?= =?us-ascii?Q?QoTK4fi+We+kqHKwaOf2DDvPpYn3eK+hVv03Abz9jECNSPWtdDdK1fU7XBOi?= =?us-ascii?Q?OWCbSznXLEzwCX3lqsK0KfetYtBLJvLdLN5Ua1bx2hl8WFHmVRtR2ocAL6Y3?= =?us-ascii?Q?y9wq/dAxTNb9zX9ehtyl+GAo9Oal55EgT9LLVq4BS5pJHesIVMBbBP7KZu3R?= =?us-ascii?Q?gcMnZbINxMiM7VCjNaX0w/yvS339BcXIUogdEOZdaQRI/PU4idiSn6uaSghg?= =?us-ascii?Q?wsO2ZnbhOZbXsaXZGoGNazMsDh/bBelNsk/NatDeog5jiC19oRQPw6zjXTrf?= =?us-ascii?Q?wgLultlXkbofeDEa4XAvYGvT5Z6M1OvYQ9B6ZDfP?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a700d8b5-0994-4f21-b7f9-08dac198b251 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4344.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2022 14:51:19.8777 (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: Fm1IGOv69m9hMZMHF/z8SGUaj/6KykcfkDdrqLUZKjBcfOKCRGb1qqACz6t2t4CK8/bbPVk97y/OrgkN3cRkEw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4814 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-07_11,2022-11-08_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 mlxscore=0 suspectscore=0 spamscore=0 malwarescore=0 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211080090 X-Proofpoint-GUID: j9rYnVlUixyYBPYtcDIEla4tCwEdnLtG X-Proofpoint-ORIG-GUID: j9rYnVlUixyYBPYtcDIEla4tCwEdnLtG X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,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: The name of the utility routine "array_at_struct_end_p" is misleading and should be changed to a new name that more accurately reflects its real meaning. The routine "array_at_struct_end_p" is used to check whether an array reference is to an array whose actual size might be larger than its upper bound implies, which includes 3 different cases: A. a ref to a flexible array member at the end of a structure; B. a ref to an array with a different type against the original decl; C. a ref to an array that was passed as a parameter; The old name only reflects the above case A, therefore very confusing when reading the corresponding gcc source code. In this patch, A new name "array_ref_flexible_size_p" is used to replace the old name. All the references to the routine "array_at_struct_end_p" was replaced with this new name, and the corresponding comments were updated to make them clean and consistent. gcc/ChangeLog: * gimple-array-bounds.cc (trailing_array): Replace array_at_struct_end_p with new name and update comments. * gimple-fold.cc (get_range_strlen_tree): Likewise. * gimple-ssa-warn-restrict.cc (builtin_memref::builtin_memref): Likewise. * graphite-sese-to-poly.cc (bounds_are_valid): Likewise. * tree-if-conv.cc (idx_within_array_bound): Likewise. * tree-object-size.cc (addr_object_size): Likewise. * tree-ssa-alias.cc (component_ref_to_zero_sized_trailing_array_p): Likewise. (stmt_kills_ref_p): Likewise. * tree-ssa-loop-niter.cc (idx_infer_loop_bounds): Likewise. * tree-ssa-strlen.cc (maybe_set_strlen_range): Likewise. * tree.cc (array_at_struct_end_p): Rename to ... (array_ref_flexible_size_p): ... this. (component_ref_size): Replace array_at_struct_end_p with new name. * tree.h (array_at_struct_end_p): Rename to ... (array_ref_flexible_size_p): ... this. --- gcc/gimple-array-bounds.cc | 4 ++-- gcc/gimple-fold.cc | 6 ++---- gcc/gimple-ssa-warn-restrict.cc | 5 +++-- gcc/graphite-sese-to-poly.cc | 4 ++-- gcc/tree-if-conv.cc | 7 +++---- gcc/tree-object-size.cc | 2 +- gcc/tree-ssa-alias.cc | 8 ++++---- gcc/tree-ssa-loop-niter.cc | 15 +++++++-------- gcc/tree-ssa-strlen.cc | 2 +- gcc/tree.cc | 11 ++++++----- gcc/tree.h | 8 ++++---- 11 files changed, 35 insertions(+), 37 deletions(-) diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc index e190b93aa85..fbf448e045d 100644 --- a/gcc/gimple-array-bounds.cc +++ b/gcc/gimple-array-bounds.cc @@ -129,7 +129,7 @@ get_ref_size (tree arg, tree *pref) } /* Return true if REF is (likely) an ARRAY_REF to a trailing array member - of a struct. It refines array_at_struct_end_p by detecting a pointer + of a struct. It refines array_ref_flexible_size_p by detecting a pointer to an array and an array parameter declared using the [N] syntax (as opposed to a pointer) and returning false. Set *PREF to the decl or expression REF refers to. */ @@ -167,7 +167,7 @@ trailing_array (tree arg, tree *pref) return false; } - return array_at_struct_end_p (arg); + return array_ref_flexible_size_p (arg); } /* Checks one ARRAY_REF in REF, located at LOCUS. Ignores flexible diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index 9055cd8982d..cafd331ca98 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -1690,13 +1690,11 @@ get_range_strlen_tree (tree arg, bitmap visited, strlen_range_kind rkind, /* Handle a MEM_REF into a DECL accessing an array of integers, being conservative about references to extern structures with flexible array members that can be initialized to arbitrary - numbers of elements as an extension (static structs are okay). - FIXME: Make this less conservative -- see - component_ref_size in tree.cc. */ + numbers of elements as an extension (static structs are okay). */ tree ref = TREE_OPERAND (TREE_OPERAND (arg, 0), 0); if ((TREE_CODE (ref) == PARM_DECL || VAR_P (ref)) && (decl_binds_to_current_def_p (ref) - || !array_at_struct_end_p (arg))) + || !array_ref_flexible_size_p (arg))) { /* Fail if the offset is out of bounds. Such accesses should be diagnosed at some point. */ diff --git a/gcc/gimple-ssa-warn-restrict.cc b/gcc/gimple-ssa-warn-restrict.cc index b7ed15c8902..832456ba6fc 100644 --- a/gcc/gimple-ssa-warn-restrict.cc +++ b/gcc/gimple-ssa-warn-restrict.cc @@ -296,8 +296,9 @@ builtin_memref::builtin_memref (pointer_query &ptrqry, gimple *stmt, tree expr, tree basetype = TREE_TYPE (base); if (TREE_CODE (basetype) == ARRAY_TYPE) { - if (ref && array_at_struct_end_p (ref)) - ; /* Use the maximum possible offset for last member arrays. */ + if (ref && array_ref_flexible_size_p (ref)) + ; /* Use the maximum possible offset for an array that might + have flexible size. */ else if (tree basesize = TYPE_SIZE_UNIT (basetype)) if (TREE_CODE (basesize) == INTEGER_CST) /* Size could be non-constant for a variable-length type such diff --git a/gcc/graphite-sese-to-poly.cc b/gcc/graphite-sese-to-poly.cc index 51ba3af204f..7eb24c1c991 100644 --- a/gcc/graphite-sese-to-poly.cc +++ b/gcc/graphite-sese-to-poly.cc @@ -536,9 +536,9 @@ bounds_are_valid (tree ref, tree low, tree high) || !tree_fits_shwi_p (high)) return false; - /* 1-element arrays at end of structures may extend over + /* An array that has flexible size may extend over their declared size. */ - if (array_at_struct_end_p (ref) + if (array_ref_flexible_size_p (ref) && operand_equal_p (low, high, 0)) return false; diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index a83b013d2ad..34bb507ff3b 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -763,10 +763,9 @@ idx_within_array_bound (tree ref, tree *idx, void *dta) if (TREE_CODE (ref) != ARRAY_REF) return false; - /* For arrays at the end of the structure, we are not guaranteed that they - do not really extend over their declared size. However, for arrays of - size greater than one, this is unlikely to be intended. */ - if (array_at_struct_end_p (ref)) + /* For arrays that might have flexible sizes, it is not guaranteed that they + do not extend over their declared size. */ + if (array_ref_flexible_size_p (ref)) return false; ev = analyze_scalar_evolution (loop, *idx); diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc index 1f04cb80fd0..2e5d267d8ce 100644 --- a/gcc/tree-object-size.cc +++ b/gcc/tree-object-size.cc @@ -633,7 +633,7 @@ addr_object_size (struct object_size_info *osi, const_tree ptr, v = NULL_TREE; break; } - is_flexible_array_mem_ref = array_at_struct_end_p (v); + is_flexible_array_mem_ref = array_ref_flexible_size_p (v); while (v != pt_var && TREE_CODE (v) == COMPONENT_REF) if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0))) != UNION_TYPE diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc index b4c65da5718..d3a91b1f238 100644 --- a/gcc/tree-ssa-alias.cc +++ b/gcc/tree-ssa-alias.cc @@ -1073,7 +1073,7 @@ component_ref_to_zero_sized_trailing_array_p (tree ref) && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 1))) == ARRAY_TYPE && (!TYPE_SIZE (TREE_TYPE (TREE_OPERAND (ref, 1))) || integer_zerop (TYPE_SIZE (TREE_TYPE (TREE_OPERAND (ref, 1))))) - && array_at_struct_end_p (ref)); + && array_ref_flexible_size_p (ref)); } /* Worker for aliasing_component_refs_p. Most parameters match parameters of @@ -3433,10 +3433,10 @@ stmt_kills_ref_p (gimple *stmt, ao_ref *ref) } /* Finally check if the lhs has the same address and size as the base candidate of the access. Watch out if we have dropped - an array-ref that was at struct end, this means ref->ref may - be outside of the TYPE_SIZE of its base. */ + an array-ref that might have flexible size, this means ref->ref + may be outside of the TYPE_SIZE of its base. */ if ((! innermost_dropped_array_ref - || ! array_at_struct_end_p (innermost_dropped_array_ref)) + || ! array_ref_flexible_size_p (innermost_dropped_array_ref)) && (lhs == base || (((TYPE_SIZE (TREE_TYPE (lhs)) == TYPE_SIZE (TREE_TYPE (base))) diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc index 4ffcef4f4ff..3fbbf4367ed 100644 --- a/gcc/tree-ssa-loop-niter.cc +++ b/gcc/tree-ssa-loop-niter.cc @@ -3716,18 +3716,17 @@ idx_infer_loop_bounds (tree base, tree *idx, void *dta) struct ilb_data *data = (struct ilb_data *) dta; tree ev, init, step; tree low, high, type, next; - bool sign, upper = true, at_end = false; + bool sign, upper = true, has_flexible_size = false; class loop *loop = data->loop; if (TREE_CODE (base) != ARRAY_REF) return true; - /* For arrays at the end of the structure, we are not guaranteed that they - do not really extend over their declared size. However, for arrays of - size greater than one, this is unlikely to be intended. */ - if (array_at_struct_end_p (base)) + /* For arrays that might have flexible sizes, it is not guaranteed that they + do not really extend over their declared size. */ + if (array_ref_flexible_size_p (base)) { - at_end = true; + has_flexible_size = true; upper = false; } @@ -3760,9 +3759,9 @@ idx_infer_loop_bounds (tree base, tree *idx, void *dta) sign = tree_int_cst_sign_bit (step); type = TREE_TYPE (step); - /* The array of length 1 at the end of a structure most likely extends + /* The array that might have flexible size most likely extends beyond its bounds. */ - if (at_end + if (has_flexible_size && operand_equal_p (low, high, 0)) return true; diff --git a/gcc/tree-ssa-strlen.cc b/gcc/tree-ssa-strlen.cc index 5afbae1b72e..b87c7c7ce1f 100644 --- a/gcc/tree-ssa-strlen.cc +++ b/gcc/tree-ssa-strlen.cc @@ -1987,7 +1987,7 @@ maybe_set_strlen_range (tree lhs, tree src, tree bound) suggests if it's treated as a poor-man's flexible array member. */ src = TREE_OPERAND (src, 0); if (TREE_CODE (src) != MEM_REF - && !array_at_struct_end_p (src)) + && !array_ref_flexible_size_p (src)) { tree type = TREE_TYPE (src); tree size = TYPE_SIZE_UNIT (type); diff --git a/gcc/tree.cc b/gcc/tree.cc index 04603c8c902..d2b0b34a725 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -12710,8 +12710,8 @@ array_ref_up_bound (tree exp) return NULL_TREE; } -/* Returns true if REF is an array reference, component reference, - or memory reference to an array whose actual size might be larger +/* Returns true if REF is an array reference, a component reference, + or a memory reference to an array whose actual size might be larger than its upper bound implies, there are multiple cases: A. a ref to a flexible array member at the end of a structure; B. a ref to an array with a different type against the original decl; @@ -12726,10 +12726,10 @@ array_ref_up_bound (tree exp) int test (uint8_t *p, uint32_t t[1][1], int n) { for (int i = 0; i < 4; i++, p++) t[i][0] = ...; +*/ - FIXME, the name of this routine need to be changed to be more accurate. */ bool -array_at_struct_end_p (tree ref) +array_ref_flexible_size_p (tree ref) { /* the TYPE for this array referece. */ tree atype = NULL_TREE; @@ -12862,6 +12862,7 @@ array_at_struct_end_p (tree ref) return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true; } + /* Return a tree representing the offset, in bytes, of the field referenced by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */ @@ -12957,7 +12958,7 @@ component_ref_size (tree ref, special_array_member *sam /* = NULL */) return (tree_int_cst_equal (memsize, TYPE_SIZE_UNIT (memtype)) ? memsize : NULL_TREE); - bool trailing = array_at_struct_end_p (ref); + bool trailing = array_ref_flexible_size_p (ref); bool zero_length = integer_zerop (memsize); if (!trailing && !zero_length) /* MEMBER is either an interior array or is an array with diff --git a/gcc/tree.h b/gcc/tree.h index a50f7b2be9d..0fcdd6b06d0 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -5548,10 +5548,10 @@ extern tree array_ref_up_bound (tree); EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */ extern tree array_ref_low_bound (tree); -/* Returns true if REF is an array reference or a component reference - to an array at the end of a structure. If this is the case, the array - may be allocated larger than its upper bound implies. */ -extern bool array_at_struct_end_p (tree); +/* Returns true if REF is an array reference, a component reference, + or a memory reference to an array whose actual size might be larger + than its upper bound implies. */ +extern bool array_ref_flexible_size_p (tree); /* Return a tree representing the offset, in bytes, of the field referenced by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */ -- 2.31.1