This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix -Wshadow=local warnings in elfos.h
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- Cc: Segher Boessenkool <segher at kernel dot crashing dot org>, Jeff Law <law at redhat dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 7 Oct 2019 22:29:39 +0000
- Subject: Re: [PATCH] Fix -Wshadow=local warnings in elfos.h
- Ironport-sdr: T7k5tJw8+gYwdgIAueFJY8Mk7Or9tlTb/8DTJPr6dpjlgJ5XkO3xwY0ZzkT9VYnZ088vN13FFK pkhdbGgwaBpBpVxfiE87Pxn+sq6lM58vGVTT5woif7glXFNBJD8jSLJoT0dmyvDU5cldoP7x7w CC2oe36/xFIbcimL2fm4zBWKYFTc/laTMgwUizxuHtNlNkrugt67NX+sBnYUoT9P4QKvh5AiO4 MGdtQcI2OHSm5W934qQQ1hL7aMZuN9FapaSnnxjbMthQkf97nMrTwp2+PtO9EqRc6OdUa5NHDU QvI=
- Ironport-sdr: 6Rh/kgBiUUwSYsMkKzrk8uMUNsXdYsk68Csyw7mXzZmqqbHPffyW9BMGLKskH1Zg67eqbWbtFS 1mA0n+pj5uDV8pbYAG3iWdL3NUabPst86HFMJApzPeRUbmXLegpasC04Tpa3Yfgvz2yGRfZzuy Y8JEO4WA2ioSX3l9seHVsah+Ue60iz1jD/FlL+eO2e7Hl0NAPE0l5nqj1QsElfP+kCP1rPWxrv f6V1y1kpLUQdJm80Va9qtadgygM8dYjBVj0HmCOrPxx2KF3XFqWtcmcuOWXDVnH06DWGJTOxIT Wro=
- References: <AM6PR03MB45195C918D4592DF23AEC5B7E49E0@AM6PR03MB4519.eurprd03.prod.outlook.com> <cc941fb2-d54a-95e9-2fda-c025c3cc6593@redhat.com> <20191005072600.GO9749@gate.crashing.org> <VI1PR03MB4528305726AB018015F492F3E4990@VI1PR03MB4528.eurprd03.prod.outlook.com>
On Sat, 5 Oct 2019, Bernd Edlinger wrote:
> > Like
> >
> > #define DEFAULT_SOME_MACRO(PARMS) { lots of code }
> >
> > becomes
> >
> > #define DEFAULT_SOME_MACRO(PARMS) default_some_macro(PARMS)
> >
> > static inline int
> > default_some_macro (int parm, long another)
> > {
> > lots of code;
> > }
> >
> > The point is that all this is completely *local* changes.
> >
>
> Hmm, I tried this but it does not work:
The answer to that is an out-of-line function.
See the default_register_move_cost function in targhooks.c, the
register_move_cost hook and the REGISTER_MOVE_COST target macro, for
example. There is a strategy for incremental conversion of a single
target macro to a hook that goes as follows:
* Define a corresponding target hook. Make the default definition in
targhooks.c be one that tests whether the target macro is defined and
either uses that macro or the existing default as appropriate. Make
tm.texi.in document the hook alongside the macro, saying that the macro is
obsolete and new targets should use the hook.
* Convert all *uses* of the target macro to use the hook instead. There
is no need to change any of the definitions in the various targets with
non-default definitions.
* Remove the default definition of the target macro, as no longer needed
now targhooks.c tests whether the target macro is defined or not.
At that point, you have a partial conversion of that target macro to a
hook (and consequent gains regarding avoiding shadowing) without having
touched any of the target-specific code. Any target can safely convert
its own definition of the macro to a definition of the hook, independently
of all other targets and all other hooks. Once all targets have changed,
the macro can be poisoned and the documentation of the macro and support
in targhooks.c for using the macro removed, in the usual fashion for
removing a target macro - but that might happen a long time afterwards.
It's more work than a pure local conversion to an inline function, or than
just renaming variables, but significantly less than a full conversion of
the macro to a hook (and in particular should not need testing on more
than one target).
--
Joseph S. Myers
joseph@codesourcery.com