public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Daney <ddaney.cavm@gmail.com>
To: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-kernel@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
	David Howells <dhowells@redhat.com>,
	Markos Chandras <Markos.Chandras@imgtec.com>,
	linux-mips@linux-mips.org,
	Andrew Pinski <Andrew.Pinski@caviumnetworks.com>,
	John Crispin <blogic@openwrt.org>
Subject: Re: Issue with BUG() in asm-gemeric/bug.h if CONFIG_BUG=n
Date: Mon, 30 Sep 2013 08:53:47 -0700	[thread overview]
Message-ID: <52499E8B.6000702@gmail.com> (raw)
In-Reply-To: <20130930145630.GA14672@linux-mips.org>

On 09/30/2013 07:56 AM, Ralf Baechle wrote:
> Lately I received several patches for build issues that only strike if
> CONFIG_BUG is disabled.  Here's a test case extracted from one of them:
>
> /*
>   * Definition of BUG taken from asm-generic/bug.h for the CONFIG_BUG=n case
>   */
> #define BUG() 	do {} while(0)
>
> int foo(int arg)
> {
> 	int res;
>
> 	if (arg == 1)
> 		res = 23;
> 	else if (arg == 2)
> 		res = 42;
> 	else
> 		BUG();
>
> 	return res;
> }
>
> [ralf@h7 ~]$ gcc -O2 -Wall -c bug.c
> bug.c: In function ‘foo’:
> bug.c:17:2: warning: ‘res’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>    return res;
>    ^
>
> It's fairly obvious to see what's happening here - GCC doesn't know that
> the else case can not be reached, thus razorsharply concludes that res
> may be used uninitialized.
>
> There several locations where MIPS - possibly other architectures as well -
> is affected by this.
>
> I think the definition of BUG should be changed to something like
>
> #define BUG()	unreachable()
> 16304
> unreachable() will depending on the compiler being used, expand either
> into a call to __builtin_unreachable() or where that function is
> unavailable, into do {} while (1).

The *only* reason we have CONFIG_BUG=n is to reduce code size.

Sticking in that empty loop, negates the entire point.

IMHO: We should do one of:
  o Make CONFIG_BUG=y mandatory
  o Ignore the warnings.
  o Fix the warning sites so they quit Warning.

So I don't think the patch is really an improvement over the status quo.

David Daney

>
> __builtin_unreachable() was introduce for GCC 4.5.0.
>
> This means there'd be minor bloat for antique compilers - but probably
> even better code generation for compilers supporting __builtin_unreachable().
>
>    Ralf
>
> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
>
>   include/asm-generic/bug.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
> index 7d10f96..6f78771 100644
> --- a/include/asm-generic/bug.h
> +++ b/include/asm-generic/bug.h
> @@ -108,7 +108,7 @@ extern void warn_slowpath_null(const char *file, const int line);
>
>   #else /* !CONFIG_BUG */
>   #ifndef HAVE_ARCH_BUG
> -#define BUG() do {} while(0)
> +#define BUG() unreachable()
>   #endif
>
>   #ifndef HAVE_ARCH_BUG_ON
>
> ----- End forwarded message -----
>
>    Ralf
>


  reply	other threads:[~2013-09-30 15:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-30 14:56 Issue with BUG() in asm-gemeric/bug.h if CONFIG_BUG=n Ralf Baechle
2013-09-30 15:53 ` David Daney [this message]
2013-09-30 17:15   ` Pinski, Andrew
2013-09-30 17:45     ` David Daney
2013-09-30 19:03       ` Geert Uytterhoeven
2013-09-30 19:17         ` David Daney

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=52499E8B.6000702@gmail.com \
    --to=ddaney.cavm@gmail.com \
    --cc=Andrew.Pinski@caviumnetworks.com \
    --cc=Markos.Chandras@imgtec.com \
    --cc=arnd@arndb.de \
    --cc=blogic@openwrt.org \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=ralf@linux-mips.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