From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id EAD6B3858D20; Thu, 9 Mar 2023 18:28:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EAD6B3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678386526; bh=lIAUKwdwyLe1KD3AXfkbQbVn87n+LbmYBRZEdQJDPck=; h=From:To:Subject:Date:From; b=mS1Ap9l2/Wu3NsddPTe28up7kKczy+OV03M+zVhF8oX+N46gRXzcmZcddStRmCqCC 0J2aZHQ/co8P5Qkk7WVGNTX8h1rrFqOGJL4WVrdc2HZJ0p2a2uCf5LZOp7OM5EH+gX mrM7t5lupdpR++yyoKVb+dmBSIcr3rGoIJ8DRVYU= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Pinski To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6559] Fix PR 108980: note without warning due to array bounds check X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 3df9760d56662bdf38dd45f7398f003bbd64fdfe X-Git-Newrev: c6232ba229a4fcd453b50f11351fcbd35296809c Message-Id: <20230309182846.EAD6B3858D20@sourceware.org> Date: Thu, 9 Mar 2023 18:28:46 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c6232ba229a4fcd453b50f11351fcbd35296809c commit r13-6559-gc6232ba229a4fcd453b50f11351fcbd35296809c Author: Andrew Pinski Date: Wed Mar 1 11:13:21 2023 -0800 Fix PR 108980: note without warning due to array bounds check 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. Diff: --- 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);