From patchwork Wed Mar 1 23:25:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 65874 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B7F33385840C for ; Wed, 1 Mar 2023 23:25:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B7F33385840C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677713141; bh=O0cPYdP2SYJSEQJPZRn8EhrPEddEtDHLItMMOh8YlI0=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Eseq5FbkOq7a9j/iaraBkM0NKm1xM+9m8h3lrdbDzKT9uB2PFCrVTbTD4wKErGrQI WnEgYPlZCiC70O/5PVRdfa1/tQ2qXOo0kc1YlcpNiy3KeyHnb7yWhtDlYeGrFfygkA QSI4yN7k0Aeu62SCvNCBn+vQ6JhoUxIseX/TJEjw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 2F9323858C53 for ; Wed, 1 Mar 2023 23:25:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2F9323858C53 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 321MTIjq020865 for ; Wed, 1 Mar 2023 15:25:11 -0800 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3p1psechbp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Wed, 01 Mar 2023 15:25:10 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 1 Mar 2023 15:25:09 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Wed, 1 Mar 2023 15:25:09 -0800 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.67]) by maili.marvell.com (Postfix) with ESMTP id 1ECD35B6943; Wed, 1 Mar 2023 15:25:09 -0800 (PST) To: CC: Andrew Pinski Subject: [PATCH] Fix PR 108980: note without warning due to array bounds check Date: Wed, 1 Mar 2023 15:25:00 -0800 Message-ID: <20230301232500.2622240-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: lFiR8ZcTkC6upcr4R6y5GxO-S61Pg9ux X-Proofpoint-GUID: lFiR8ZcTkC6upcr4R6y5GxO-S61Pg9ux X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-01_15,2023-03-01_03,2023-02-09_01 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The problem here is after r13-4748-g2a27ae32fabf85, in some cases we were calling inform without a corresponding warning. This changes the logic such that we only cause that to happen if there was a warning happened before hand. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: PR tree-optmization/108980 * gimple-array-bounds.cc (array_bounds_checker::check_array_ref): Reorgnize the call to warning for not strict flexible arrays to be before the check of warned. --- gcc/gimple-array-bounds.cc | 41 ++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc index 66fd46e9b6c..469baecaa1a 100644 --- a/gcc/gimple-array-bounds.cc +++ b/gcc/gimple-array-bounds.cc @@ -397,27 +397,38 @@ array_bounds_checker::check_array_ref (location_t location, tree ref, "of an interior zero-length array %qT")), low_sub, artype); - if (warned || out_of_bound) + if (warned && dump_file && (dump_flags & TDF_DETAILS)) { - if (warned && dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "Array bound warning for "); + dump_generic_expr (MSG_NOTE, TDF_SLIM, ref); + fprintf (dump_file, "\n"); + } + + /* Issue warnings for -Wstrict-flex-arrays according to the level of + flag_strict_flex_arrays. */ + if (out_of_bound && warn_strict_flex_arrays + && (sam == special_array_member::trail_0 + || sam == special_array_member::trail_1 + || sam == special_array_member::trail_n) + && DECL_NOT_FLEXARRAY (afield_decl)) + { + bool warned1; + warned1 = warning_at (location, OPT_Wstrict_flex_arrays, + "trailing array %qT should not be used as " + "a flexible array member", + artype); + + if (warned1 && dump_file && (dump_flags & TDF_DETAILS)) { - fprintf (dump_file, "Array bound warning for "); + fprintf (dump_file, "Not Flexible array bound warning for "); dump_generic_expr (MSG_NOTE, TDF_SLIM, ref); fprintf (dump_file, "\n"); } + warned |= warned1; + } - /* issue warnings for -Wstrict-flex-arrays according to the level of - flag_strict_flex_arrays. */ - if ((out_of_bound && warn_strict_flex_arrays) - && (((sam == special_array_member::trail_0) - || (sam == special_array_member::trail_1) - || (sam == special_array_member::trail_n)) - && DECL_NOT_FLEXARRAY (afield_decl))) - warned = warning_at (location, OPT_Wstrict_flex_arrays, - "trailing array %qT should not be used as " - "a flexible array member", - artype); - + if (warned) + { /* Avoid more warnings when checking more significant subscripts of the same expression. */ ref = TREE_OPERAND (ref, 0);