From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 3B63B384F6C8 for ; Wed, 23 Nov 2022 20:12:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3B63B384F6C8 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x229.google.com with SMTP id d3so22660651ljl.1 for ; Wed, 23 Nov 2022 12:12:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=y1nluQ4piP6N/4lcR+5s+f/oYXygzKDYkH7o/IEB03I=; b=LKSCFwOyUoWpaI72QDnPjR+MK3skGf6nKtCkG/9Avp9gHsw0knAIpp+xWQQyOjpg7L fRs1vGjFrLl6vttbGyS9/tmo07Owa+yAVRvYHrL4EpFU27P0krFlxES4wzeRZWcOMt9w JMCAA1DoD2O1woMY4dFUF1yr9tJ5w65x/3U670GZ5ehU9qgH4YgbmvJncmvG1w139JD5 rfOU3jIx716Pg9LxQ37JtRB/BBckc1ocY2pEE0Tv2JXaC9cQZbcG2q6EZkKM4psU2Dk3 lVpVLVa4RMS5fJdb+4LYd5FQzpf0iFVex/cbDe7BAMasNPHvgoCuzOHrXMAkpQJCfGGk JQzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y1nluQ4piP6N/4lcR+5s+f/oYXygzKDYkH7o/IEB03I=; b=fUMHuSyOQnIJDCXEG+lmn0sm1LkAqnAZExnQv4M85MKNoPClbNuHf0rEo/jN93LTFG i2R33nP9QVxj8ubZYnZM1ey/IamJtykTWMPKiAgwHAhY5H0UF/z2q6zuHXFqnVqqiOi8 B8konMYq+wvszRXd4rKX4+iBwK9HNH0mOoWxtRAZxm0GF97yVpE+Cw4NrHNk2TAqPJKW VKuglFKSMOPwwuxQw2WMPWTG41QjGPGDR2A5uexn2QHONDRJCXGMUi6YkQI6DsjsJa+e KoE84lMSkPqX9srsbFeNBUV6Hyw27Xjjj83sKWAJKwnjgTdeD1OyWcxZ302KaCXM0ULJ k1Qg== X-Gm-Message-State: ANoB5pkVlGM3DfeznilzL5/XK0J2V9OODFL6BnVC2KYM2IuQmRlzl5uQ 1v547y4aD1cIaZyhdOeO+TqZ7NUxtnPLA4CETuDOEH6o X-Google-Smtp-Source: AA0mqf7XXX2cypowsCHYjMZbyLdejC7RzqqGfpek3DvAdFTBxNBFboeD5DM0AllFH6ebOBkGPqi8sExk8Bc2PDpsKrM= X-Received: by 2002:a2e:b11c:0:b0:261:d86f:3cde with SMTP id p28-20020a2eb11c000000b00261d86f3cdemr10283302ljl.86.1669234327776; Wed, 23 Nov 2022 12:12:07 -0800 (PST) MIME-Version: 1.0 References: <9795E6AA-E646-4134-AABE-23F530F5219E@ispras.ru> In-Reply-To: From: Richard Biener Date: Wed, 23 Nov 2022 21:11:55 +0100 Message-ID: Subject: Re: [PATCH] Make Warray-bounds alias to Warray-bounds= [PR107787] To: Iskander Shakirzyanov Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 List-Id: On Wed, Nov 23, 2022 at 3:08 PM Iskander Shakirzyanov via Gcc-patches wrote: > > Hi! > Sorry for the initially missing description. > The following patch changes the definition of -Warray-bounds to an Alias = to -Warray-bounds=3D1. This is necessary for the correct use of -Werror=3Da= rray-bounds=3DX, for more information see bug report 107787 (https://gcc.gn= u.org/bugzilla/show_bug.cgi?id=3D107787) > As I understand, this happens because -Warray-bounds and -Warray-bounds= =3D are declared as 2 different options in common.opt, so when diagnostic_c= lassify_diagnostic() (opts-common.cc:1880) is called, DK_ERROR is set for t= he -Warray-bounds=3D option, but in diagnostic_report_diagnostic() (diagnos= tic.cc:1446) through warning_at() passes opt_index of -Warray-bounds, so in= formation about DK_ERROR is lost. How did you test the patch? If you bootstrapped it and ran the testsuite then it's OK. Thanks, Richard. > > From 51559e862d191a1f51cc9af11f0d9be5fbc0b43c Mon Sep 17 00:00:00 2001 > From: Iskander Shakirzyanov > Date: Wed, 23 Nov 2022 12:26:47 +0000 > Subject: [PATCH] Make Warray-bounds alias to Warray-bounds=3D [PR107787] > > PR driver/107787 > > gcc/ChangeLog: > > * common.opt (Warray-bounds): Turn into alias to > -Warray-bounds=3D1. > * builtins.cc (warn_array_bounds): Use OPT_Warray_bounds_ > instead of OPT_Warray_bounds. > * diagnostic-spec.cc: Likewise. > * gimple-array-bounds.cc: Likewise. > * gimple-ssa-warn-restrict.cc: Likewise. > > gcc/testsuite/ChangeLog: > > * pr107787.c: New test. > > gcc/c-family/ChangeLog: > > * c-common.cc (warn_array_bounds): Use OPT_Warray_bounds_ > instead of OPT_Warray_bounds. > --- > gcc/builtins.cc | 6 +++--- > gcc/c-family/c-common.cc | 4 ++-- > gcc/common.opt | 2 +- > gcc/diagnostic-spec.cc | 1 - > gcc/gimple-array-bounds.cc | 38 ++++++++++++++++----------------- > gcc/gimple-ssa-warn-restrict.cc | 2 +- > gcc/testsuite/gcc.dg/pr107787.c | 13 +++++++++++ > 7 files changed, 39 insertions(+), 27 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/pr107787.c > > diff --git a/gcc/builtins.cc b/gcc/builtins.cc > index 4dc1ca672b2..02c4fefa86f 100644 > --- a/gcc/builtins.cc > +++ b/gcc/builtins.cc > @@ -696,14 +696,14 @@ c_strlen (tree arg, int only_value, c_strlen_data *= data, unsigned eltsize) > { > /* Suppress multiple warnings for propagated constant strings. */ > if (only_value !=3D 2 > - && !warning_suppressed_p (arg, OPT_Warray_bounds) > - && warning_at (loc, OPT_Warray_bounds, > + && !warning_suppressed_p (arg, OPT_Warray_bounds_) > + && warning_at (loc, OPT_Warray_bounds_, > "offset %qwi outside bounds of constant string", > eltoff)) > { > if (decl) > inform (DECL_SOURCE_LOCATION (decl), "%qE declared here", dec= l); > - suppress_warning (arg, OPT_Warray_bounds); > + suppress_warning (arg, OPT_Warray_bounds_); > } > return NULL_TREE; > } > diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc > index 6f1f21bc4c1..b0da6886ccf 100644 > --- a/gcc/c-family/c-common.cc > +++ b/gcc/c-family/c-common.cc > @@ -6811,7 +6811,7 @@ fold_offsetof (tree expr, tree type, enum tree_code= ctx) > definition thereof. */ > if (TREE_CODE (v) =3D=3D ARRAY_REF > || TREE_CODE (v) =3D=3D COMPONENT_REF) > - warning (OPT_Warray_bounds, > + warning (OPT_Warray_bounds_, > "index %E denotes an offset " > "greater than size of %qT", > t, TREE_TYPE (TREE_OPERAND (expr, 0))); > @@ -8534,7 +8534,7 @@ convert_vector_to_array_for_subscript (location_t l= oc, > if (TREE_CODE (index) =3D=3D INTEGER_CST) > if (!tree_fits_uhwi_p (index) > || maybe_ge (tree_to_uhwi (index), TYPE_VECTOR_SUBPARTS (type= ))) > - warning_at (loc, OPT_Warray_bounds, "index value is out of bou= nd"); > + warning_at (loc, OPT_Warray_bounds_, "index value is out of bo= und"); > > /* We are building an ARRAY_REF so mark the vector as addressable > to not run into the gimplifiers premature setting of DECL_GIMPL= E_REG_P > diff --git a/gcc/common.opt b/gcc/common.opt > index 26e9d1cc4e7..e475d6e56eb 100644 > --- a/gcc/common.opt > +++ b/gcc/common.opt > @@ -539,7 +539,7 @@ Common Var(warn_aggressive_loop_optimizations) Init(1= ) Warning > Warn if a loop with constant number of iterations triggers undefined beh= avior. > > Warray-bounds > -Common Var(warn_array_bounds) Warning > +Common Alias(Warray-bounds=3D, 1, 0) Warning > Warn if an array is accessed out of bounds. > > Warray-bounds=3D > diff --git a/gcc/diagnostic-spec.cc b/gcc/diagnostic-spec.cc > index aece89619e7..7a03fc493e6 100644 > --- a/gcc/diagnostic-spec.cc > +++ b/gcc/diagnostic-spec.cc > @@ -79,7 +79,6 @@ nowarn_spec_t::nowarn_spec_t (opt_code opt) > break; > > /* Access warning group. */ > - case OPT_Warray_bounds: > case OPT_Warray_bounds_: > case OPT_Wformat_overflow_: > case OPT_Wformat_truncation_: > diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc > index fbf448e045d..7af85b86f75 100644 > --- a/gcc/gimple-array-bounds.cc > +++ b/gcc/gimple-array-bounds.cc > @@ -182,7 +182,7 @@ bool > array_bounds_checker::check_array_ref (location_t location, tree ref, > gimple *stmt, bool ignore_off_by_o= ne) > { > - if (warning_suppressed_p (ref, OPT_Warray_bounds)) > + if (warning_suppressed_p (ref, OPT_Warray_bounds_)) > /* Return true to have the caller prevent warnings for enclosing > refs. */ > return true; > @@ -287,7 +287,7 @@ array_bounds_checker::check_array_ref (location_t loc= ation, tree ref, > > /* Empty array. */ > if (up_bound && tree_int_cst_equal (low_bound, up_bound_p1)) > - warned =3D warning_at (location, OPT_Warray_bounds, > + warned =3D warning_at (location, OPT_Warray_bounds_, > "array subscript %E is outside array bounds of %= qT", > low_sub, artype); > > @@ -313,7 +313,7 @@ array_bounds_checker::check_array_ref (location_t loc= ation, tree ref, > : tree_int_cst_le (up_bound, up_sub)) > && TREE_CODE (low_sub) =3D=3D INTEGER_CST > && tree_int_cst_le (low_sub, low_bound)) > - warned =3D warning_at (location, OPT_Warray_bounds, > + warned =3D warning_at (location, OPT_Warray_bounds_, > "array subscript [%E, %E] is outside " > "array bounds of %qT", > low_sub, up_sub, artype); > @@ -323,12 +323,12 @@ array_bounds_checker::check_array_ref (location_t l= ocation, tree ref, > && (ignore_off_by_one > ? !tree_int_cst_le (up_sub, up_bound_p1) > : !tree_int_cst_le (up_sub, up_bound))) > - warned =3D warning_at (location, OPT_Warray_bounds, > + warned =3D warning_at (location, OPT_Warray_bounds_, > "array subscript %E is above array bounds of %qT= ", > up_sub, artype); > else if (TREE_CODE (low_sub) =3D=3D INTEGER_CST > && tree_int_cst_lt (low_sub, low_bound)) > - warned =3D warning_at (location, OPT_Warray_bounds, > + warned =3D warning_at (location, OPT_Warray_bounds_, > "array subscript %E is below array bounds of %qT= ", > low_sub, artype); > > @@ -353,7 +353,7 @@ array_bounds_checker::check_array_ref (location_t loc= ation, tree ref, > /* Avoid more warnings when checking more significant subscripts > of the same expression. */ > ref =3D TREE_OPERAND (ref, 0); > - suppress_warning (ref, OPT_Warray_bounds); > + suppress_warning (ref, OPT_Warray_bounds_); > > if (decl) > ref =3D decl; > @@ -393,7 +393,7 @@ bool > array_bounds_checker::check_mem_ref (location_t location, tree ref, > bool ignore_off_by_one) > { > - if (warning_suppressed_p (ref, OPT_Warray_bounds)) > + if (warning_suppressed_p (ref, OPT_Warray_bounds_)) > return false; > > /* The statement used to allocate the array or null. */ > @@ -493,12 +493,12 @@ array_bounds_checker::check_mem_ref (location_t loc= ation, tree ref, > if (lboob) > { > if (offrange[0] =3D=3D offrange[1]) > - warned =3D warning_at (location, OPT_Warray_bounds, > + warned =3D warning_at (location, OPT_Warray_bounds_, > "array subscript %wi is outside array bounds= " > "of %qT", > offrange[0].to_shwi (), reftype); > else > - warned =3D warning_at (location, OPT_Warray_bounds, > + warned =3D warning_at (location, OPT_Warray_bounds_, > "array subscript [%wi, %wi] is outside " > "array bounds of %qT", > offrange[0].to_shwi (), > @@ -513,7 +513,7 @@ array_bounds_checker::check_mem_ref (location_t locat= ion, tree ref, > backtype =3D build_array_type_nelts (unsigned_char_type_node, > aref.sizrng[1].to_uhwi ()); > > - warned =3D warning_at (location, OPT_Warray_bounds, > + warned =3D warning_at (location, OPT_Warray_bounds_, > "array subscript %<%T[%wi]%> is partly " > "outside array bounds of %qT", > axstype, offrange[0].to_shwi (), backtype); > @@ -523,7 +523,7 @@ array_bounds_checker::check_mem_ref (location_t locat= ion, tree ref, > { > /* TODO: Determine the access from the statement and use it. */ > aref.inform_access (access_none); > - suppress_warning (ref, OPT_Warray_bounds); > + suppress_warning (ref, OPT_Warray_bounds_); > return true; > } > > @@ -536,11 +536,11 @@ array_bounds_checker::check_mem_ref (location_t loc= ation, tree ref, > { > HOST_WIDE_INT tmpidx =3D (aref.offmax[i] / eltsize).to_shwi (); > > - if (warning_at (location, OPT_Warray_bounds, > + if (warning_at (location, OPT_Warray_bounds_, > "intermediate array offset %wi is outside array bou= nds " > "of %qT", tmpidx, reftype)) > { > - suppress_warning (ref, OPT_Warray_bounds); > + suppress_warning (ref, OPT_Warray_bounds_); > return true; > } > } > @@ -572,7 +572,7 @@ array_bounds_checker::check_addr_expr (location_t loc= ation, tree t, > warned =3D check_mem_ref (location, t, ignore_off_by_one); > > if (warned) > - suppress_warning (t, OPT_Warray_bounds); > + suppress_warning (t, OPT_Warray_bounds_); > > t =3D TREE_OPERAND (t, 0); > } > @@ -580,7 +580,7 @@ array_bounds_checker::check_addr_expr (location_t loc= ation, tree t, > > if (TREE_CODE (t) !=3D MEM_REF > || TREE_CODE (TREE_OPERAND (t, 0)) !=3D ADDR_EXPR > - || warning_suppressed_p (t, OPT_Warray_bounds)) > + || warning_suppressed_p (t, OPT_Warray_bounds_)) > return; > > tree tem =3D TREE_OPERAND (TREE_OPERAND (t, 0), 0); > @@ -615,7 +615,7 @@ array_bounds_checker::check_addr_expr (location_t loc= ation, tree t, > dump_generic_expr (MSG_NOTE, TDF_SLIM, t); > fprintf (dump_file, "\n"); > } > - warned =3D warning_at (location, OPT_Warray_bounds, > + warned =3D warning_at (location, OPT_Warray_bounds_, > "array subscript %wi is below " > "array bounds of %qT", > idx.to_shwi (), TREE_TYPE (tem)); > @@ -629,7 +629,7 @@ array_bounds_checker::check_addr_expr (location_t loc= ation, tree t, > dump_generic_expr (MSG_NOTE, TDF_SLIM, t); > fprintf (dump_file, "\n"); > } > - warned =3D warning_at (location, OPT_Warray_bounds, > + warned =3D warning_at (location, OPT_Warray_bounds_, > "array subscript %wu is above " > "array bounds of %qT", > idx.to_uhwi (), TREE_TYPE (tem)); > @@ -640,7 +640,7 @@ array_bounds_checker::check_addr_expr (location_t loc= ation, tree t, > if (DECL_P (t)) > inform (DECL_SOURCE_LOCATION (t), "while referencing %qD", t); > > - suppress_warning (t, OPT_Warray_bounds); > + suppress_warning (t, OPT_Warray_bounds_); > } > } > > @@ -740,7 +740,7 @@ array_bounds_checker::check_array_bounds (tree *tp, i= nt *walk_subtree, > /* Propagate the no-warning bit to the outer statement to avoid also > issuing -Wstringop-overflow/-overread for the out-of-bounds accesse= s. */ > if (warned) > - suppress_warning (wi->stmt, OPT_Warray_bounds); > + suppress_warning (wi->stmt, OPT_Warray_bounds_); > > return NULL_TREE; > } > diff --git a/gcc/gimple-ssa-warn-restrict.cc b/gcc/gimple-ssa-warn-restri= ct.cc > index 832456ba6fc..107ba278798 100644 > --- a/gcc/gimple-ssa-warn-restrict.cc > +++ b/gcc/gimple-ssa-warn-restrict.cc > @@ -1734,7 +1734,7 @@ maybe_diag_access_bounds (gimple *call, tree func, = int strict, > if (!oobref) > return no_warning; > > - const opt_code opt =3D OPT_Warray_bounds; > + const opt_code opt =3D OPT_Warray_bounds_; > /* Return true without issuing a warning. */ > if (!do_warn) > return opt; > diff --git a/gcc/testsuite/gcc.dg/pr107787.c b/gcc/testsuite/gcc.dg/pr107= 787.c > new file mode 100644 > index 00000000000..79112691b63 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr107787.c > @@ -0,0 +1,13 @@ > +/* PR driver/107787 */ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -Werror=3Darray-bounds=3D1" } */ > +/* { dg-message "some warnings being treated as errors" "" {target "*-*-= *"} 0 } */ > + > +int a[10]; /* { dg-note "while referencing" } */ > + > +int* f(void) { > + > + a[-1] =3D 0; /* { dg-error "is below array bounds" } */ > + > + return a; > +} > -- > 2.25.1 >