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: 63113 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3925437wrd; Wed, 1 Mar 2023 15:25:58 -0800 (PST) X-Google-Smtp-Source: AK7set+SJbuKxu26lH3LqeUPQ6XvVtuwwGgApwEl14DA5ONQOZUORISse1uZN0FKKpFziixP6ZnO X-Received: by 2002:a17:906:714e:b0:872:6bd0:d2b with SMTP id z14-20020a170906714e00b008726bd00d2bmr9690331ejj.45.1677713157982; Wed, 01 Mar 2023 15:25:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677713157; cv=none; d=google.com; s=arc-20160816; b=gbPZiFov2/vdPYhW4JdRL2ztxV8K+5KAKnKKk2kSxz9dkng/m2bfR8LbvANtMCuFmf JniB4NnNk8p8sp7UKiG6qj5hxh22ODfbodO2SUTECPxiqkrVAaVYKtbVTtvnnRd62YSG wGXELmqn5tDdnya36Z93dWEjvMzUQMYbe1YcJPfWE5+yN0Uxw6iJckvt3HnihkIpjazQ HkslwkqBmF3pvDHKNNikfg/oF8cwyX5+NB3kIGGbezZmvJ47qesYAzMxtQT87kqcS422 Z/pog/iCpEaqefvVaAhSXddrrGDa8djNhUA1Sjn6Z0PiWkNv4EXPK3Poh8VT7P7xvyDJ 6R3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=O0cPYdP2SYJSEQJPZRn8EhrPEddEtDHLItMMOh8YlI0=; b=0gaiIcg7GJ4RVpRedLtWXk0yBc0QGUY4r7coG/9nwqX+4K+p5w9P+jYZdhe/D1ZFlP VYP4IiCZI/l7GO+MwBEgICaQxlc2t/mXz7UM+TvKcrH1u0qC3LyMyHpgK8+0pNHKDhJb mgba0mWoHsc103P+CnFBExCCeaINW1R1ah99bNGTphYXUlBGmrYaMkWm8v1Fx2vdrJtG 6/gQvN2HIaV1mntNf1VngcUcMmpWGnkg81IBFfMyUnpBWmKj3N4eAXZeu+lHGkaeOAMb XWZ7/V39YH4SKwZXsc6z6xZhX91LP80TKg3Ufrhd2X7Vz8uu3KQwsRAeC4NSS3wmqz9t uwTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Bl2ZpU1C; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e21-20020a170906749500b008e97faf8ae4si1519146ejl.461.2023.03.01.15.25.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 15:25:57 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Bl2ZpU1C; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0D6D13858426 for ; Wed, 1 Mar 2023 23:25:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0D6D13858426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677713157; bh=O0cPYdP2SYJSEQJPZRn8EhrPEddEtDHLItMMOh8YlI0=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Bl2ZpU1CuqYET1U5rJ6n4sq2ahvrhAY/T5ushn9INf8xbdTQkdqGIcUl0VXkL6EUL aX909Dj2+ajvXm33QiMgOXIDAuA7ev8/ETKY2bayJYtd3+Zym3TUkY9UB/pCB79KvC 0A/0Ut/Yp2GW+3tutIRLJg9PuElngAxhs0sJZv0w= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759209752452737131?= X-GMAIL-MSGID: =?utf-8?q?1759209752452737131?= 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);