public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Daney <ddaney@caviumnetworks.com>
To: Jamie Lokier <jamie@shareable.org>, "gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ARM: Convert BUG() to use unreachable()
Date: Thu, 17 Dec 2009 09:09:26 -0800	[thread overview]
Message-ID: <4B2A65C6.7080009@caviumnetworks.com> (raw)
In-Reply-To: <20091217150120.GD24967@shareable.org>

Jamie Lokier wrote:
> Uwe Kleine-König wrote:
>> Use the new unreachable() macro instead of for(;;);
>>  	*(int *)0 = 0;
>>  
>>  	/* Avoid "noreturn function does return" */
>> -	for (;;);
>> +	unreachable();
> 
> Will GCC-4.5 remove ("optimise away") the *(int *)0 = 0 because it
> knows the branch of the code leading to unreachable can never be reached?
> 

I don't know the definitive answer, so I am sending to gcc@...

FYI: #define unreachable() __builtin_unreachable()


> If GCC-4.5 does not, are you sure a future version of GCC will never
> remove it?  In other words, is __builtin_unreachable() _defined_ in
> such a way that it cannot remove the previous assignment?
> 
> We have seen problems with GCC optimising away important tests for
> NULL pointers in the kernel, due to similar propagation of "impossible
> to occur" conditions, so it's worth checking with GCC people what the
> effect of this one would be.
> 
> In C, there is a general theoretical problem with back-propagation of
> optimisations from code with undefined behaviour.  In the case of
> __builtin_unreachable(), it would depend on all sorts of unclearly
> defined semantics whether it can remove a preceding *(int *)0 = 0.
> 
> I'd strongly suggest asking on the GCC list.  (I'd have mentioned this
> earlier, if I'd known about the patch for other architectures).
> 
> The documentation for __builtin_unreachable() only says the program is
> undefined if control flow reaches it.  In other words, it does not say
> what effect it can have on previous instructions, and I think it's
> quite likely that it has not been analysed in a case like this.
> 
> One thing that would give me a lot more confidence, because the GCC
> documentation does mention asm(), is this:
> 
>>       *(int *)0 = 0;
>>       /* Ensure unreachableness optimisations cannot propagate back. *I/
>>       __asm__ volatile("");
>>       /* Avoid "noreturn function does return" */
>>       unreachable();
> 
> -- Jamie


  reply	other threads:[~2009-12-17 17:12 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-08  9:55 [PATCH] ARM: Convert BUG() to use unreachable() Uwe Kleine-König
2009-12-08 17:07 ` David Daney
2009-12-10 17:50 ` Russell King - ARM Linux
2009-12-10 17:55   ` David Daney
2009-12-16 13:58     ` Uwe Kleine-König
2009-12-17 15:01 ` Jamie Lokier
2009-12-17 17:09   ` David Daney [this message]
2009-12-17 17:17     ` Richard Guenther
2009-12-17 18:17       ` Russell King - ARM Linux
2009-12-17 18:35         ` Joe Buck
2009-12-17 19:06           ` Russell King - ARM Linux
2009-12-17 19:14             ` Joe Buck
2009-12-17 19:33               ` David Daney
2009-12-17 19:33               ` Russell King - ARM Linux
2009-12-17 19:38               ` Jamie Lokier
2009-12-17 19:48                 ` Russell King - ARM Linux
2009-12-17 19:58                   ` Russell King - ARM Linux
2009-12-17 19:04         ` Jamie Lokier
2009-12-21 19:30         ` Richard Henderson
2009-12-21 20:10           ` Russell King - ARM Linux
2009-12-22 14:09             ` Dave Korn
2009-12-22 14:12               ` Russell King - ARM Linux
2009-12-22 14:49                 ` Dave Korn
2009-12-22 11:33       ` Paolo Bonzini

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=4B2A65C6.7080009@caviumnetworks.com \
    --to=ddaney@caviumnetworks.com \
    --cc=gcc@gcc.gnu.org \
    --cc=jamie@shareable.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=u.kleine-koenig@pengutronix.de \
    /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