false 'noreturn' function does return warnings

Chris Lattner clattner@apple.com
Wed Feb 7 01:10:00 GMT 2007


On Feb 6, 2007, at 5:06 PM, Joe Buck wrote:

> On Tue, Feb 06, 2007 at 04:14:30PM -0800, Ian Lance Taylor wrote:
>> I also think it would be good to have one option affecting it: turn
>> __builtin_unreachable() into an abort(), or turn it into a "cannot be
>> reached" marker.  I think the former should be the default at -O0,  
>> the
>> latter at -O1 and above.
>>
>> Note that a "cannot be reached" marker permits further  
>> optimization to
>> delete code which leads up to it.  Actually implementing that further
>> optimization may call for adding appropriate warnings, probably
>> controlled by -Wunreachable-code.

I have experience with this approach, it works well:
http://llvm.org/docs/LangRef.html#i_unreachable

> In the case that motivated this discussion, the instruction that would
> immediately go before the __builtin_unreachable() is a trap  
> instruction,
> but the compiler does not know that it traps.  It would be very bad
> if the compiler eliminated the trap, since it is the presence of the
> trap that keeps the function from returning.

Nothing with side effects before an 'unreachable' can be removed,  
including an asm.  Consider if the asm called a no-return function.

-Chris



More information about the Gcc mailing list