From patchwork Mon May 13 19:48:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 1934796 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2023-11-20 header.b=EXPUiCCY; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=vUm8q5gf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VdVRf5B5fz1yfq for ; Tue, 14 May 2024 05:49:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E7ECA38708F3 for ; Mon, 13 May 2024 19:49:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id C86183858432 for ; Mon, 13 May 2024 19:48:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C86183858432 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 C86183858432 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=1715629722; cv=pass; b=PEhUVxMHy+o++5U7gxng1z/4tsp+eiRDu9/tCZR8GPVngtBJWpVznZlOKDaDwbv2m4nhNt9oNEVmXKom8Yx3RUdk4UCCRGCSz8URCFZqqCpCvqG5P3PFS09f+TpFndngn1lU6gTEeM/K/+xklmxIeJaSgMLifu4g4o3hAMHX4Ns= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1715629722; c=relaxed/simple; bh=R1azoUdusl6xlDjarl68j14tYmJqklMu7YQmvQViZ7c=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=MFOzMU8sSMj9DJMvps/m3+9LtzCSG31904EqA3bylf+caTeDiix6RrjtOVLcVE4FWAVOLntUTrj5JAnmeLqQoQzVR7zadc8OwqKMA4qAL/XXwLxTrjFM8FBF8A5h0z4kabtx8Qo9NNFZep+GxkdVayaIo1Y8HszNIGMnUm6XlVM= 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 44DJEPiv029619; Mon, 13 May 2024 19:48:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=Q7we0I3v6tH3CH6kjDB97MUvR7hvsi9iqlM6f8eV0aU=; b=EXPUiCCYvNKyQgqdi2IZLT3gXRWKj011up4EVsPBeLPXjm3ZLrYxtnBjjDAFVXnzGKdd Z9cvWA56r+Uvl1B4TNpTyZNlDhx+noDALU3OQqrGFfesNQPIj3ET4jxQxfCyA+GGDyVQ fzEGhThVKVCeNy0vMpRNl+2UK6BVqTknwXHpui1s/x9R/MiQ7YQwQyshdFmaiQ9f/fSc YThcHsi4ttUpLGcnjpc+LK9SEU2Kujyz4rBjyRubCkqCSfCrcl6UoOtWpwsASgu2qUH9 zfr2JmEcmq4RG8cwQP+/tLU42CxFE06DHlqkNXyX+RnJbWk89Gy2CuazOmiSiFOhQfSI cA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3y3rk4r305-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 May 2024 19:48:38 +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 44DIDZHV017476; Mon, 13 May 2024 19:48:36 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2100.outbound.protection.outlook.com [104.47.70.100]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3y1y468kfq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 May 2024 19:48:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MwWU8/je5exqhZIvB6m45fK1rrNXc8lhd2AN2fr1CIBlgwLGVeC3vMxSkzJhnRWEmvl3mIV2S2zUfqCPWP3PYTre/zEt6T8pMDPaHhoGbd1rskn8sKeH8C3LKoAl0Tx7HckyBy/dJcDCLpzfHN71pse4ZPDwQ2VuGfvXhTSEvxOuha1EIyfMCjbkEpg6GjJJM/bjDzJwwrKrFy28bYEBxXPrzqrV2tU0TiTWTHt4xStP5V3zj7RT/X/FQVbDSRAWvQ/x0ju2LIyXSKRUTmx8WmRbTxXo3iuer14t8+1hz6o2x3dO3wMkqujMEZxwBi951wiergQfm2bdnnePuU+UFw== 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=Q7we0I3v6tH3CH6kjDB97MUvR7hvsi9iqlM6f8eV0aU=; b=QASg0Xk4HyWWsMMtH3tUcWalKC9GbTvZeWZgmxkrymkWlY/bfm8Bwrb5Uo7HK5BXdhv8Ag0Td84EaNMDDf+SeLs5cvYqaodCUrGq0xpvNcEf0fm+T7XLCv8ehPd+0SXHWRvhaH2BYFG2/F3IGztUTQXv9w0WZv4hybsaCxrW0HctDcVDFHp6BPhIjkVmslyBSeKTRmWTKQOX6t0K7O6sPs/go9BD6Kd5XyO1KRk6W9rEx/uvUUl7PLCvGUnwfocD/WxEPX60gJICcSL1krMZGkovmpNCuaZ6UkNQktV+Ubzpe1PZH1kI3esJEipXrGPjobOCQAqjIOO5Y7fuwvsgWA== 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=Q7we0I3v6tH3CH6kjDB97MUvR7hvsi9iqlM6f8eV0aU=; b=vUm8q5gffgz4hw6nmmFTkmcdFUamzOVSLITsI6xk93OOoJupQNpzkFaRMlVjYu1KptT6H94Zr29TyqoHKy/3Ryt6tFlNz0bpcIXuXp4GIffUxgxwDijL1SnNwhapQgtp7pYNTNxIjpo/ZSFevF9a+4px/MNei8q8Aa1hY1jnFfI= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by BN0PR10MB4853.namprd10.prod.outlook.com (2603:10b6:408:115::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55; Mon, 13 May 2024 19:48:33 +0000 Received: from CY8PR10MB6538.namprd10.prod.outlook.com ([fe80::8a:61cd:764a:e47]) by CY8PR10MB6538.namprd10.prod.outlook.com ([fe80::8a:61cd:764a:e47%4]) with mapi id 15.20.7544.052; Mon, 13 May 2024 19:48:33 +0000 From: Qing Zhao To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, pinskia@gmail.com, keescook@chromium.org, Qing Zhao Subject: [RFC][PATCH] PR tree-optimization/109071 - -Warray-bounds false positive warnings due to code duplication from jump threading Date: Mon, 13 May 2024 19:48:30 +0000 Message-Id: <20240513194830.1676938-1-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 X-ClientProxiedBy: BL1PR13CA0100.namprd13.prod.outlook.com (2603:10b6:208:2b9::15) To CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR10MB6538:EE_|BN0PR10MB4853:EE_ X-MS-Office365-Filtering-Correlation-Id: 3fdbd83a-523d-4a5d-67b6-08dc7385abe2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|1800799015|366007; X-Microsoft-Antispam-Message-Info: Z6pWTneGr/UALGvAxwffQaSVALLRdvnvvOyauFilJmbKbYHENoBqMmDs1GbsQSVhFBFo+DK7cvZOVtFQFOicubmYmxo0EOPDvX3rf9Vj3XlBTb491pOWb/jn5LVYY6cy5olptymV1Z0RhVv8a8RAWIMPAhjFuQdemQK14AIAQhcHNt8qZux5f6VvMWBb+iFUCcdafzGbl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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: 8FM7LeAYOgXVYliXNV13kPRJFvY/rnz8Gj5ejFL4hkPnPpzkrDeEpgwXGhDHu2yy7duqi73XP6Th7NG1Y15SsyeBt6dewdujKSpe7y3MQ3vigmhMs1J16ZB8lqhUQf81LCKc6d+kYj1reA+0h1Z6Q0mvhYoN57Iz+U48LX+gBQzIZ3KAAZo4/cf92R0bZl58CCFKUZF54ZYqfYmEDCzAma3E8j9n4qwvuDHyNv0R0kMiSImP/MZlsiyYMF59bW+GumBEF7wYzraHD9KXCKL2RbVYncDWvaZoluYuxqkL19WkyLcA9R5gy4YihVrN+VOb8zKJhLfnuxr+OId+JDxXNFtDbH8tlFzo6kmeSnULfBqG31oOY5/XM+DDPIYsbWS40jbp7JeSFmwLx6AjyWvd/vZS9LHLrVeqnBZDYsYJSfH1PLDNOTP2aE9iUQ/CjN7W9dBtBAcfj/2QeG+NFTbU55mRkewbPcWtnfQVF+N+0kLVkhsNHYFMtG1skH/Zlq6g/32lBuNKUIamnn/+fBG4EdS3XORfpt5gsIcZS/lL/Kg85UeTaJybBdRapPRtxCq00v6T92gzrLwmLngzqGLjz5Sref/X1Ok7P5ehgx/2VxpPqocZd3iH10UoEcwVCHT2GDeRprEklufQ6TXAjEfxq8Uegbw4waSQIwG+cRLX7KSzKMVRpdRKaCsjXmbSIF0IazniQevKyocGXx2ToKUhFBaYaSu8rUccn2OOHx29W+dgSy0QnjGrnGon9dqhDqYjshnVvmIzm7IGceakjhFCjxMoCUzfzYLLnSrF5/dTxIhdjm2y5O2VOrY6Hzc8CbyGH8JRlHZPsuYT5jTWSChUzTRFELREhuE4L2cy5jokf0aZUTOq79rxuXBnb+cT2tj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Kb5/UmCoIQZRjZXJ2VDvU6OXLqp9pJ8oXkn5IHjnjL0dFLHEK8pgPk1LWA4P3jKx+D8WQrcEiYits2MsJ/DeWeCWn/+Cn9ts6xuha0gR0tX75TyHKWG+Dz/q6bVfHYjG8XQcjEYLKLEIXVzV6HYGOolN/2w8uz/REpJb9xUVlpdSOgkz4BLvJKLtYvMQeTmVh1I8CGCSqot1e3ql6rCRcAGfjGX9/IRO+eLO8sX6kw9S6HZTNK0T/9s3Z2KypTv8dmBqy1eqV+UybPv0ERak1Wm2j5rjbeY732cqC2Ki7TRMwQgNndSTM230= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3fdbd83a-523d-4a5d-67b6-08dc7385abe2 X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 May 2024 19:48:33.2723 (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: l9+W8233Js7dGHmQW2TNt048+y9/izkSaj/crXrUq/hR4K3RBeTQpcM6q9BCVMIbXi+3dLM3sNTkbNGKgptMzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB4853 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-13_14,2024-05-10_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2405130135 X-Proofpoint-ORIG-GUID: ik3Zk7KalPdIW0LEX0MRSS-DU8Tk9Vdr X-Proofpoint-GUID: ik3Zk7KalPdIW0LEX0MRSS-DU8Tk9Vdr X-Spam-Status: No, score=-11.6 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_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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org -Warray-bounds is an important option to enable linux kernal to keep the array out-of-bound errors out of the source tree. However, due to the false positive warnings reported in PR109071 (-Warray-bounds false positive warnings due to code duplication from jump threading), -Warray-bounds=1 cannot be added on by default. Although it's impossible to elinimate all the false positive warnings from -Warray-bounds=1 (See PR104355 Misleading -Warray-bounds documentation says "always out of bounds"), we should minimize the false positive warnings in -Warray-bounds=1. The root reason for the false positive warnings reported in PR109071 is: When the thread jump optimization tries to reduce the # of branches inside the routine, sometimes it needs to duplicate the code and split into two conditional pathes. for example: The original code: void sparx5_set (int * ptr, struct nums * sg, int index) { if (index >= 4) warn (); *ptr = 0; *val = sg->vals[index]; if (index >= 4) warn (); *ptr = *val; return; } With the thread jump, the above becomes: void sparx5_set (int * ptr, struct nums * sg, int index) { if (index >= 4) { warn (); *ptr = 0; // Code duplications since "warn" does return; *val = sg->vals[index]; // same this line. // In this path, since it's under the condition // "index >= 4", the compiler knows the value // of "index" is larger then 4, therefore the // out-of-bound warning. warn (); } else { *ptr = 0; *val = sg->vals[index]; } *ptr = *val; return; } We can see, after the thread jump optimization, the # of branches inside the routine "sparx5_set" is reduced from 2 to 1, however, due to the code duplication (which is needed for the correctness of the code), we got a false positive out-of-bound warning. In order to eliminate such false positive out-of-bound warning, A. Add one more flag for GIMPLE: is_splitted. B. During the thread jump optimization, when the basic blocks are duplicated, mark all the STMTs inside the original and duplicated basic blocks as "is_splitted"; C. Inside the array bound checker, add the following new heuristic: If 1. the stmt is duplicated and splitted into two conditional paths; + 2. the warning level < 2; + 3. the current block is not dominating the exit block Then not report the warning. The false positive warnings are moved from -Warray-bounds=1 to -Warray-bounds=2 now. Bootstrapped and regression tested on both x86 and aarch64. adjusted -Warray-bounds-61.c due to the false positive warnings. Let me know if you have any comments and suggestions. Thanks. Qing PR tree optimization/109071 gcc/ChangeLog: * gimple-array-bounds.cc (check_out_of_bounds_and_warn): Add two new arguments for the new heuristic to not issue warnings. (array_bounds_checker::check_array_ref): Call the new prototype of the routine check_out_of_bounds_and_warn. (array_bounds_checker::check_mem_ref): Add one new argument for the new heuristic to not issue warnings. (array_bounds_checker::check_addr_expr): Call the new prototype of the routine check_mem_ref, add new heuristic for not issue warnings. (array_bounds_checker::check_array_bounds): Call the new prototype of the routine check_mem_ref. * gimple-array-bounds.h: New prototype of check_mem_ref. * gimple.h (struct GTY): Add one new flag is_splitted for gimple. (gimple_is_splitted_p): New function. (gimple_set_is_splitted): New function. * tree-ssa-threadupdate.cc (set_stmts_in_bb_is_splitted): New function. (back_jt_path_registry::duplicate_thread_path): Mark all the stmts in both original and copied blocks as IS_SPLITTED. gcc/testsuite/ChangeLog: * gcc.dg/Warray-bounds-61.c: Adjust testing case. * gcc.dg/pr109071-1.c: New test. * gcc.dg/pr109071.c: New test. --- gcc/gimple-array-bounds.cc | 46 +++++++++++++++++++++---- gcc/gimple-array-bounds.h | 2 +- gcc/gimple.h | 21 +++++++++-- gcc/testsuite/gcc.dg/Warray-bounds-61.c | 6 ++-- gcc/testsuite/gcc.dg/pr109071-1.c | 22 ++++++++++++ gcc/testsuite/gcc.dg/pr109071.c | 22 ++++++++++++ gcc/tree-ssa-threadupdate.cc | 15 ++++++++ 7 files changed, 122 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr109071-1.c create mode 100644 gcc/testsuite/gcc.dg/pr109071.c diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc index 008071cd5464..4a2975623bc1 100644 --- a/gcc/gimple-array-bounds.cc +++ b/gcc/gimple-array-bounds.cc @@ -264,7 +264,9 @@ check_out_of_bounds_and_warn (location_t location, tree ref, tree up_bound, tree up_bound_p1, const value_range *vr, bool ignore_off_by_one, bool for_array_bound, - bool *out_of_bound) + bool *out_of_bound, + bool is_splitted, + bool is_dominate_exit) { tree min, max; tree low_bound = array_ref_low_bound (ref); @@ -273,6 +275,13 @@ check_out_of_bounds_and_warn (location_t location, tree ref, bool warned = false; *out_of_bound = false; + /* If the stmt is duplicated and splitted, the warning level is not 2, + and the current block is not dominating the exit block, not report + the warning. */ + if (is_splitted && warn_array_bounds < 2 + && !is_dominate_exit) + return false; + /* Empty array. */ if (up_bound && tree_int_cst_equal (low_bound, up_bound_p1)) { @@ -386,12 +395,17 @@ array_bounds_checker::check_array_ref (location_t location, tree ref, } } + bool is_dominate_exit = dominated_by_p (CDI_DOMINATORS, + EXIT_BLOCK_PTR_FOR_FN (fun), + gimple_bb (stmt)); + warned = check_out_of_bounds_and_warn (location, ref, low_sub_org, low_sub, up_sub, up_bound, up_bound_p1, &vr, ignore_off_by_one, warn_array_bounds, - &out_of_bound); - + &out_of_bound, + gimple_is_splitted_p (stmt), + is_dominate_exit); if (!warned && sam == special_array_member::int_0) warned = warning_at (location, OPT_Wzero_length_bounds, @@ -476,7 +490,7 @@ array_bounds_checker::check_array_ref (location_t location, tree ref, bool array_bounds_checker::check_mem_ref (location_t location, tree ref, - bool ignore_off_by_one) + gimple *stmt, bool ignore_off_by_one) { if (warning_suppressed_p (ref, OPT_Warray_bounds_)) return false; @@ -574,6 +588,16 @@ array_bounds_checker::check_mem_ref (location_t location, tree ref, } } + /* If the stmt is duplicated and splitted, the warning level is not 2, + and the current block is not dominating the exit block, not report + the warning. */ + bool is_dominate_exit = dominated_by_p (CDI_DOMINATORS, + EXIT_BLOCK_PTR_FOR_FN (fun), + gimple_bb (stmt)); + if (gimple_is_splitted_p (stmt) && warn_array_bounds < 2 + && !is_dominate_exit) + return false; + bool warned = false; if (lboob) { @@ -654,7 +678,7 @@ array_bounds_checker::check_addr_expr (location_t location, tree t, ignore_off_by_one = false; } else if (TREE_CODE (t) == MEM_REF) - warned = check_mem_ref (location, t, ignore_off_by_one); + warned = check_mem_ref (location, t, stmt, ignore_off_by_one); if (warned) suppress_warning (t, OPT_Warray_bounds_); @@ -690,6 +714,16 @@ array_bounds_checker::check_addr_expr (location_t location, tree t, if (!mem_ref_offset (t).is_constant (&idx)) return; + /* If the stmt is duplicated and splitted, the warning level is not 2, + and the current block is not dominating the exit block, not report + the warning. */ + bool is_dominate_exit = dominated_by_p (CDI_DOMINATORS, + EXIT_BLOCK_PTR_FOR_FN (fun), + gimple_bb (stmt)); + if (gimple_is_splitted_p (stmt) && warn_array_bounds < 2 + && !is_dominate_exit) + return; + bool warned = false; idx = wi::sdiv_trunc (idx, wi::to_offset (el_sz)); if (idx < 0) @@ -809,7 +843,7 @@ array_bounds_checker::check_array_bounds (tree *tp, int *walk_subtree, warned = checker->check_array_ref (location, t, wi->stmt, false/*ignore_off_by_one*/); else if (TREE_CODE (t) == MEM_REF) - warned = checker->check_mem_ref (location, t, + warned = checker->check_mem_ref (location, t, wi->stmt, false /*ignore_off_by_one*/); else if (TREE_CODE (t) == ADDR_EXPR) { diff --git a/gcc/gimple-array-bounds.h b/gcc/gimple-array-bounds.h index 3e077d0178ff..7c98f02204c9 100644 --- a/gcc/gimple-array-bounds.h +++ b/gcc/gimple-array-bounds.h @@ -33,7 +33,7 @@ public: private: static tree check_array_bounds (tree *tp, int *walk_subtree, void *data); bool check_array_ref (location_t, tree, gimple *, bool ignore_off_by_one); - bool check_mem_ref (location_t, tree, bool ignore_off_by_one); + bool check_mem_ref (location_t, tree, gimple *, bool ignore_off_by_one); void check_addr_expr (location_t, tree, gimple *); void get_value_range (irange &r, const_tree op, gimple *); diff --git a/gcc/gimple.h b/gcc/gimple.h index bd315ffc2dd4..08f52d107084 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -254,8 +254,8 @@ struct GTY((desc ("gimple_statement_structure (&%h)"), tag ("GSS_BASE"), /* Nonzero if this statement contains volatile operands. */ unsigned has_volatile_ops : 1; - /* Padding to get subcode to 16 bit alignment. */ - unsigned pad : 1; + /* Nonzero if this statement is duplicated and splitted to two pathes. */ + unsigned is_splitted : 1; /* The SUBCODE field can be used for tuple-specific flags for tuples that do not require subcodes. Note that SUBCODE should be at @@ -2327,6 +2327,23 @@ gimple_set_has_volatile_ops (gimple *stmt, bool volatilep) stmt->has_volatile_ops = (unsigned) volatilep; } +/* Return true if statement G's is_splitted field has + been set. */ + +inline bool +gimple_is_splitted_p (const gimple *g) +{ + return (bool) g->is_splitted; +} + +/* Set the IS_SPLITTED flag to IS_SPLITTEDP. */ + +inline void +gimple_set_is_splitted (gimple *s, bool is_splittedp) +{ + s->is_splitted = (unsigned) is_splittedp; +} + /* Return true if STMT is in a transaction. */ inline bool diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-61.c b/gcc/testsuite/gcc.dg/Warray-bounds-61.c index 5b66cdc0aab1..cb3c64a813d7 100644 --- a/gcc/testsuite/gcc.dg/Warray-bounds-61.c +++ b/gcc/testsuite/gcc.dg/Warray-bounds-61.c @@ -23,7 +23,7 @@ void test_ua3_ua0_a0 (int i) if (i < __LINE__) i = 5; - ua3_a0.a0[i] = 0; // { dg-warning "\\\[-Warray-bounds" } + ua3_a0.a0[i] = 0; // { dg-bogus "\\\[-Warray-bounds" } if (i > -1) i = -1; @@ -44,7 +44,7 @@ void test_ua3_ua0_a1 (int i) if (i > -1) i = -1; - ua3_a0.a1[i] = 0; // { dg-warning "\\\[-Warray-bounds" } + ua3_a0.a1[i] = 0; // { dg-bogus "\\\[-Warray-bounds" } if (i < 7) i = 7; @@ -60,7 +60,7 @@ void test_ua3_ua0_a2 (int i) if (i < __LINE__) i = __LINE__; - ua3_a0.a2[i] = 0; // { dg-warning "\\\[-Warray-bounds" } + ua3_a0.a2[i] = 0; // { dg-bogus "\\\[-Warray-bounds" } if (i > -1) i = -1; diff --git a/gcc/testsuite/gcc.dg/pr109071-1.c b/gcc/testsuite/gcc.dg/pr109071-1.c new file mode 100644 index 000000000000..a405c80bd549 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr109071-1.c @@ -0,0 +1,22 @@ +/* PR tree-optimization/109071 -Warray-bounds false positive warnings + due to code duplication from jump threading + { dg-do compile } + { dg-options "-O2 -Warray-bounds=2" } + */ + +extern void warn(void); +static inline void assign(int val, int *regs, int index) +{ + if (index >= 4) + warn(); + *regs = val; +} +struct nums {int vals[4];}; + +void sparx5_set (int *ptr, struct nums *sg, int index) +{ + int *val = &sg->vals[index]; /* { dg-warning "is above array bounds" } */ + + assign(0, ptr, index); + assign(*val, ptr, index); +} diff --git a/gcc/testsuite/gcc.dg/pr109071.c b/gcc/testsuite/gcc.dg/pr109071.c new file mode 100644 index 000000000000..782dfad84ea2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr109071.c @@ -0,0 +1,22 @@ +/* PR tree-optimization/109071 -Warray-bounds false positive warnings + due to code duplication from jump threading + { dg-do compile } + { dg-options "-O2 -Wall" } + */ + +extern void warn(void); +static inline void assign(int val, int *regs, int index) +{ + if (index >= 4) + warn(); + *regs = val; +} +struct nums {int vals[4];}; + +void sparx5_set (int *ptr, struct nums *sg, int index) +{ + int *val = &sg->vals[index]; /* { dg-bogus "is above array bounds" } */ + + assign(0, ptr, index); + assign(*val, ptr, index); +} diff --git a/gcc/tree-ssa-threadupdate.cc b/gcc/tree-ssa-threadupdate.cc index fa61ba9512b7..9f338dd4d54d 100644 --- a/gcc/tree-ssa-threadupdate.cc +++ b/gcc/tree-ssa-threadupdate.cc @@ -2371,6 +2371,17 @@ back_jt_path_registry::adjust_paths_after_duplication (unsigned curr_path_num) } } +/* Set all the stmts in the basic block BB as IS_SPLITTED. */ + +static void +set_stmts_in_bb_is_splitted (basic_block bb) +{ + gimple_stmt_iterator gsi; + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + gimple_set_is_splitted (gsi_stmt (gsi), true); + return; +} + /* Duplicates a jump-thread path of N_REGION basic blocks. The ENTRY edge is redirected to the duplicate of the region. @@ -2418,6 +2429,10 @@ back_jt_path_registry::duplicate_thread_path (edge entry, basic_block *region_copy = XNEWVEC (basic_block, n_region); copy_bbs (region, n_region, region_copy, &exit, 1, &exit_copy, loop, split_edge_bb_loc (entry), false); + /* Mark all the stmts in both original and copied basic blocks + as IS_SPLITTED. */ + set_stmts_in_bb_is_splitted (*region); + set_stmts_in_bb_is_splitted (*region_copy); /* Fix up: copy_bbs redirects all edges pointing to copied blocks. The following code ensures that all the edges exiting the jump-thread path are