Re: [patch 01/10] compiler: define __attribute_unused__

David Rientjes
2007-05-03T19:28:04Z

On Thu, 3 May 2007, Adrian Bunk wrote:

> > static external variables are certainly still static code and gcc issues
> > the proper warnings if I do:
> >
> > static struct bootnode nodes[MAX_NUMNODES];
> >
> > and I never reference nodes.
>
> No disagreement.
>
> But you said:
> What about automatic or static external variables that are declared but ...
>

Ahh, I see the problem. I was talking about "automatic variables" and
"static external variables" implicitly, both of which emit compiler
warnings if they are unreferenced as we saw in the arch/i386/pci/init.c
case and the example above, respectively.

The only advantage this gives us as opposed to just removing an
unreferenced variable completely is the case when its usage depends on
multiple preprocessor macros. Like in the arch/i386/pci/init.c example,
the use of 'type' depends on CONFIG_PCI_DIRECT or CONFIG_PCI_MMCONFIG. It
gets sloppy pretty quickly when we're adding

#if defined(CONFIG_PCI_DIRECT) || defined(CONFIG_PCI_MMCONFIG)

around the variable declarations. Unfortunately we still have the
drawback of perhaps leaving abandoned declarations in the code but now
there will be an easy way to detect it: defining __maybe_unused and __used
to be empty. Then we won't have hardcoded __attribute__ ((unused)) text
sprinkled around the tree that would require examination on an individual
basis.

David