public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: David Howells <dhowells@redhat.com>
Cc: Sam Ravnborg <sam@ravnborg.org>,
	Alexander Beregalov <a.beregalov@gmail.com>,
	linux-kernel@vger.kernel.org, David Miller <davem@davemloft.net>,
	David Daney <ddaney@caviumnetworks.com>
Subject: Re: [PATCH] BUG(): CONFIG_BUG=n version of BUG() should be unreachable()
Date: Tue, 5 Jan 2010 19:30:23 +0100	[thread overview]
Message-ID: <201001051930.23532.arnd@arndb.de> (raw)
In-Reply-To: <9664.1262714298@redhat.com>

On Tuesday 05 January 2010, David Howells wrote:
> Sam Ravnborg <sam@ravnborg.org> 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

      reply	other threads:[~2010-01-05 18:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-23  1:17 [PATCH] BUG(): CONFIG_BUG=n version of BUG() should be unreachable() Alexander Beregalov
2009-12-23  1:26 ` David Daney
2009-12-23  1:37   ` David Daney
2009-12-30 19:12     ` Arnd Bergmann
2010-01-04 18:06       ` David Daney
2010-01-05 11:35         ` Arnd Bergmann
2009-12-26 18:47 ` Sam Ravnborg
2010-01-05 17:58   ` David Howells
2010-01-05 18:30     ` Arnd Bergmann [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201001051930.23532.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=a.beregalov@gmail.com \
    --cc=davem@davemloft.net \
    --cc=ddaney@caviumnetworks.com \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sam@ravnborg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox