From patchwork Thu Mar 9 18:03:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 67063 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp434467wrd; Thu, 9 Mar 2023 10:04:20 -0800 (PST) X-Google-Smtp-Source: AK7set9Wqdxou61guV1dHe7xH54AaEC0jbAK/vie06GkWzGlYyUdMg0GV18yJJt/1sg/Qx+koFa5 X-Received: by 2002:a17:906:e4d:b0:8b1:7b5d:fe9b with SMTP id q13-20020a1709060e4d00b008b17b5dfe9bmr24071291eji.28.1678385060869; Thu, 09 Mar 2023 10:04:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678385060; cv=none; d=google.com; s=arc-20160816; b=jaKz0iSQGLQh/nhme4LEo17iJ++Q3/aCjG49Cj7eGU4XvmjiAufVFk1lH1EQlewmFD gbBTFjnITFU/d0SadZcOUBZo4JY7R23L9Odbz/8OYHXWjuWkw50oWxFnqQyUnN0scG2/ MnTLK1mPjFQov871HLJsqWDH6EwUHuTNe/SduZMjyMYMpuTzXgfCXefLDCpurlwxc5YN VbgMHde6gmyOHSAw+8aG87yzBrBjjWbgeIbCLsGR+8ePeOMNl/i9ZzoMo/wlTu/uyEjm SYGpHDaahVme7JWj7PiZ61cayG555Q6j/MBJYPg1r9uxZt55iwYs/FY8EOT6d/mih+fj 950g== 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=k2jpstwfw9SpDBYzIAWR+KUolPKpRgZbcfrIUaN7uU0=; b=K7ukyKnpZ7lchEF2crIbo6E+qhtVtTOAkM1GcxD6J0R7qzYgnpdmNEZt5RUyYtcppm a6/TTmQyyipP1F/a9bobA/OcvDObi9Rzgci0QCFbOjwRiawwh3Xs4MhdmUi5Iesc0wzK vDWDQrh/h5FTQ/mGxQuQNrrSzVd7qXufwljxZ4Uxb+oLdSEMDHrUnnLykoN+BBPsHtog pKsRO9jP+v2prDD3Xe+dEBCpz9V6CWJhdU7yH7QgdZ9eQ/TZ9kbV7l3pZp6ndi323Yxk ynb9eEF6SI8vJCBe3YDi0Gz7F6CFOSlph0oGyOlPwir4+Xi5ZQELbcnUuw/gYE5h+w3m 2psQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=OZTTtYDD; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id y16-20020aa7d510000000b004bc45c5440esi62750edq.67.2023.03.09.10.04.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 10:04:20 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=OZTTtYDD; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 AA2F53858002 for ; Thu, 9 Mar 2023 18:04:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AA2F53858002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678385059; bh=k2jpstwfw9SpDBYzIAWR+KUolPKpRgZbcfrIUaN7uU0=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=OZTTtYDDwn9hZA6jgJNerOBpAtpnubsXSVGXcq9BhKGUa8otd35XY6O/W1+yWqF7p WHjQJwNhXhxWf+NKXXgvjdTS5/Oo/vcWERT5L+N1AzQFuQyaEEu+Lww2Lz6GVY3thF 1g5htyjfrfI2FMzTBoo0/zHxQPclPVgptybV25N0= 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 159663858D20 for ; Thu, 9 Mar 2023 18:03:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 159663858D20 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 329HJv3t009359 for ; Thu, 9 Mar 2023 10:03:33 -0800 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3p6n7qnkdc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 09 Mar 2023 10:03:33 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 9 Mar 2023 10:03:31 -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; Thu, 9 Mar 2023 10:03:31 -0800 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.67]) by maili.marvell.com (Postfix) with ESMTP id 117563F705E; Thu, 9 Mar 2023 10:03:31 -0800 (PST) To: CC: Andrew Pinski Subject: [PATCHv2] Fix PR 108980: note without warning due to array bounds check Date: Thu, 9 Mar 2023 10:03:20 -0800 Message-ID: <20230309180320.2899452-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 8uBDYW5V-zLLCGAfSXp6pukWKKrlgbSk X-Proofpoint-GUID: 8uBDYW5V-zLLCGAfSXp6pukWKKrlgbSk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-09_09,2023-03-09_01,2023-02-09_01 X-Spam-Status: No, score=-14.5 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?1759914293492113701?= X-GMAIL-MSGID: =?utf-8?q?1759914293492113701?= 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. Changes since * v1: Fix formating and dump message as suggested by Jakub. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: PR tree-optimization/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..34e039adca7 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 + = 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, "Trailing non flexible-like 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);