Re: [PATCH] BUG(): CONFIG_BUG=n version of BUG() should be unreachable()

From: Arnd Bergmann
Date: Tue Jan 05 2010 - 13:31:13 EST


On Tuesday 05 January 2010, David Howells wrote:
> Sam Ravnborg <sam@xxxxxxxxxxxx> wrote:
>
> > +#define BUG() do { \
> > + for (;;) \
> > + /* endless loop*/; \
> > + unreachable(); \
> > +} while(0)
>
> Can you not do:
>
> #define BUG() do { \
> unreachable(); \
> } while(1)
>
> instead? If the compiler is interpreting unreachable() to really mean that
> what comes after will not be reached, then the condition/loop at the end of
> the block should be optimised away.

Forcing the loop here is really wrong because it needlessly
causes extra code to be emitted. We don't really want controlled
error handling here (that is the definition of CONFIG_BUG=n),
so this is only about shutting up the compiler warning.

I guess the best would be something like
#if defined (__GNUC__) && (__GNUC_MAJOR__ == 4) && (__GNUC_MINOR__ >= 5)
#define BUG() __builtin_unreachable()
#else
#define BUG() do { } while (0) /* this may cause a warning */
#endif

I still haven't found out how many warnings we are talking about
here, maybe we can just silence them by adding individual
unreachable() statements after BUG();

Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/