[llvm-commits] [llvm] r132732 - /llvm/trunk/utils/TableGen/FastISelEmitter.cpp

Chad Rosier mcrosier at apple.com
Fri Jun 10 10:37:31 PDT 2011


On Jun 10, 2011, at 1:16 AM, David Blaikie wrote:

>       } else if (Operands[i].isFP()) {
>         OS << "f" << i;
>       } else {
> -        assert("Unknown operand kind!");
> -        abort();
> +        llvm_unreachable("Unknown operand kind!");
>       }
>       if (i + 1 != e)
>         OS << ", ";
> 
> Just wondering about coding conventions - would it be more appropriate to change this from:
>   else if (cond) { ... } else { /* unreachable */ }
> to:
>   else { assert(cond); ... };
> This would be marginally more efficient in release builds, potentially. 
> 

You're correct in pointing out that most sanity checks should be written with asserts (e.g., assert (cond && "msg")).  However, in the case of unreachable code we know that doom and gloom are sure to follow and thus we should gracefully abort and notify the user accordingly.  There's no performance to be gained because if we've reached this state the game is already over.

In general, if you see something like assert(0 && "I should have never gotten here.."); it should be replaced with llvm_unreachable("I should have never gotten here..").  Notice that the condition is hardcoded to zero and thus the assert will always fire.

 Chad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110610/c48278b8/attachment.html>


More information about the llvm-commits mailing list