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

Andrew Morton
2007-05-02T06:52:52Z

On Tue, 1 May 2007 23:41:34 -0700 (PDT) David Rientjes <rientjes@google.com> wrote:

> compiler: define __maybe_unused
>
> Define __maybe_unused to apply to both functions or variables as
> __attribute__((unused)). This will not emit a compile-time warning when
> a function or variable is declared but unreferenced.
>
> We eventually want to change the name of __attribute_used__ to __used.
>
> Signed-off-by: David Rientjes <rientjes@google.com>
> ---
> include/linux/compiler-gcc.h | 1 +
> 1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
> --- a/include/linux/compiler-gcc.h
> +++ b/include/linux/compiler-gcc.h
> @@ -37,3 +37,4 @@
> #define noinline __attribute__((noinline))
> #define __attribute_pure__ __attribute__((pure))
> #define __attribute_const__ __attribute__((__const__))
> +#define __maybe_unused __attribute__((unused))

Seems sane to me. We'd need a definition in compiler-intel.h too. I don't
know if ICC implements __attribute__((unused)) - probably it does.

I guess we can get by without any commentary describing __maybe_unused, but
I think __used would need one - it's pretty obscure.

+@cindex @code{used} attribute.
+@item used
+This attribute, attached to a function, means that code must be emitted
+for the function even if it appears that the function is not referenced.
+This is useful, for example, when the function is referenced only in
+inline assembly.