This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, OBVIOUS] Fix -Wshadow=local warnings in gcc/[a-c]*.c
- From: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: Segher Boessenkool <segher at kernel dot crashing dot org>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 7 Oct 2019 12:44:04 +0000
- Subject: Re: [PATCH, OBVIOUS] Fix -Wshadow=local warnings in gcc/[a-c]*.c
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jf9Ypn39hLw10i6W+O/2kghmMF2I4RQeWlkr8lslz7w=; b=DR5IDsc4Usl2jUtY/kr3bkXYMb3/t85PrLlzelmYoxycfd9tCHLvsKEwP08Lz7eTgc0XrhoSnJ7ugh+fMK+CmkPzzltZl7fHR0D35rPBc0ezzVhQ4W1NncZWZ/G63Gr3jQurnFXtRVWcmlUDcGOMQyRpfsPJmLnbunG0mBzEZCGl862GwhoxOg1OxqtbydUPzXLryejM8qEXchVt5FY7jkjnErMfgRdrW8gcIraQd1pYS1LrCrl84N2xU5SDKPKbJf6rewx0i503RUu/4Ba8L0pIlM79FaxsC7EQY2CeWYMVVAnE+GW3DAHxT7kb1hBRZLUWaDRmbirpV0dwuJYhJw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ixwAMk+GJIqJWebpPzK6chG0HIQQ+nXHUZS8jdGT0chP2n6k+8oV1ttIybrb4w6qFfs1sYX5j5GWf+Muy8FX/MbLIu+bD9O+z/qf/Fl2Rf3WxTB//D7omfKB0iuGP7QdRdFWt9cgrU4De5moM8gJqiwLSQyFNktPj8xYSupD1O6wSGw+8ywhantfxQgo4r3M5h74YTxbJtJxBY/KgkvMmGw9A3D1u6vZ88qRQj0PC9cPqPiHZFpJy8MTFPs9vEFbo2zvIjTJfAkMY8+jNFB2ow4JqR/CFwdXmfmCXNoNBBDmgGtdI1US77wx/kivscpi2bDX/pEVw32lqYqUz4W/hw==
- References: <VI1PR03MB45288ED34970DA0A794EDFF9E4990@VI1PR03MB4528.eurprd03.prod.outlook.com> <20191005080831.GP9749@gate.crashing.org> <VI1PR03MB4528BF2CF41FF6E5CFD5FBF6E4990@VI1PR03MB4528.eurprd03.prod.outlook.com> <20191005182456.GT9749@gate.crashing.org> <VI1PR03MB45281102A6D3371FABEA018DE4980@VI1PR03MB4528.eurprd03.prod.outlook.com> <CAFiYyc33RtHpsHcCok=Pn_GykCrgx1XDwhN=nZEdf0tRQjm_WA@mail.gmail.com>
On 10/7/19 8:56 AM, Richard Biener wrote:
> On Sun, Oct 6, 2019 at 1:24 PM Bernd Edlinger <bernd.edlinger@hotmail.de> wrote:
>>
>> On 10/5/19 8:24 PM, Segher Boessenkool wrote:
>>>
>>> I am maintainer of combine, I know all about its many problems (it has much
>>> deeper problems than this unfortunately). Thanks for your help though, this
>>> is much appreciated, but I do think your current patch is not a step in the
>>> right direction.
>>>
>>
>> Hmm, thanks for your open words these are of course important. I will not
>> commit this under obvious rules since you objected to the patch in general.
>>
>> What I want to achieve is to make sure that new code is not introducing more
>> variable shadowing. New shadowing variables are introduced by new code, unless
>> we have a warning enabled. And the warning need to be enabled together with
>> -Werror otherwise it will be overlooked.
>>
>> For instance I believe MISRA has even stronger coding rules with respect
>> to shadowing.
>>
>> What I tried to do was adding -Wshadow=local to the -Werror warnings set
>> and do a more or less mechanical change over the whole code base.
>> How that mechanical change is done - if at all -, needs to be agreed upon.
>>
>> Currently I have the impression that we do not agree if this warning is to be
>> enabled at all.
>
> I think if the current code-base was clean then enabling it would be a
> no-brainer.
> But I agree that mechanically "fixing" the current code-base, while ending up
> with no new introductions of local shadowing, is worse if it makes the current
> code-base worse. Consider your
>
> for (int i = ....)
> {
> ...
> {
> int i = ...;
> ... (*)
> }
> }
>
> when editing (*) using 'i' will usually be picking up the correct one. If you
> change the inner do 'i1' then fat-fingering 'i' is easy and bound to happen
> and will be silently accepted. It's also not any more obvious _which_
> of the i's is intended since 'i1' is not any more descriptive than 'i'.
>
> If only it will confuse developers familiar with the code then such change is
> making things worse.
>
> But yes, this means that the quest to enable -Werror=shadow=local becomes
> much harder. Would it be possible to enable it selectively for "clean"
> files in the Makefile rules? White-listing with -Wno-error=... doesn't work
> because older host compilers treat unknown options as error there. More
> configury around this might help (like simply not enabling it during stage1
> and using a configure macro in the while-listing makefile rules).
>
I think the easiest way would be to add something like this to all files that
are too difficult to fix right now:
Index: combine.c
===================================================================
--- combine.c (revision 276634)
+++ combine.c (working copy)
@@ -107,6 +107,10 @@
#include "print-rtl.h"
#include "function-abi.h"
+#if __GNUC__ >= 7
+#pragma GCC diagnostic ignored "-Wshadow=local"
+#endif
+
/* Number of attempts to combine instructions in this function. */
static int combine_attempts;
I have modified
192 of 453 *.c files in gcc/*.c
and
59 out of 241 files in the frontends, c*/*.c fortran/*.c lto/*.c etc.
Many of them have only 1-2 changes, so might be possible to fix at
least some of them, but OTOH more than 50% don't have any issues.
> This probably means fixing the header file issues first though.
>
Yes.
Bernd.
> Richard.
>
>>
>> Bernd.
>>