<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div style="word-wrap:break-word"><div><div class="h5">Ahh.. yes, I misunderstood your example.  Here are the source comments, which best explain the use of llvm_unreachable:</div>
</div><div><br></div><div><span style="font-family:monospace;white-space:pre-wrap"><pre><i><b>/// Marks that the current location is not supposed to be reachable.
</b></i><i><b>/// In !NDEBUG builds, prints the message and location info to stderr.
</b></i><i><b>/// In NDEBUG builds, becomes an optimizer hint that the current location
</b></i><i><b>/// is not supposed to be reachable.  On compilers that don't support
</b></i><i><b>/// such hints, prints a reduced message instead.
</b></i><i><b>///
</b></i><i><b>/// Use this instead of assert(0).  It conveys intent more clearly and
</b></i><i><b>/// allows compilers to omit some unnecessary code.</b></i></pre></span><div>In the case of a release build an unreachable hint is emitted.  The compiler then uses this hint to transform:</div></div><div><br>
</div><div><div class="im"><div><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px">      } else if (Operands[i].isFP()) {<br>        OS << "ConstantFP *f" << i;<br>      } else {<br>
        llvm_unreachable("Unknown operand kind!");<br>      }</span></div><div><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px"><br></span></div></div><div><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px">to:</span></div>
<div class="im"><div><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px"><br></span></div><div><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px">      } else </span><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px">if (Operands[i].isFP()) {</span></div>
<div><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px">        OS << "ConstantFP *f" << i;<br>      }</span></div></div></div><div><font face="arial, sans-serif" size="3"><span style="border-collapse:collapse;font-size:13px"><br>
</span></font></div><div><font face="arial, sans-serif" size="3"><span style="border-collapse:collapse;font-size:13px">I hope this helps answer your question.  In the end the compiler is being smart about removing the unreachable code.  For more details you could also checkout: <a href="http://www.nondot.org/sabre/LLVMNotes/UnreachableInstruction.txt" target="_blank">http://www.nondot.org/sabre/LLVMNotes/UnreachableInstruction.txt</a></span></font></div>
</div></blockquote><div><br></div><div>Ah, ok - thanks for the explanation. I didn't realize llvm_unreachable was that advanced/involved (though I suppose I Should've expected as much). </div><div><br></div><div>So both versions (the assert & the unreachable) seem to have similar semantics (performance & correctness) given a sufficiently advanced compiler (that uses the unreachable to remove the isFP() call) - makes sense.</div>
<div><br></div><div>[is there any policy/recommendations on which way to go in this case? I guess it's not a problem to leave this up to the author of any particular piece of LLVM code about which expression they prefer/find more clear in a given situation]</div>
<div><br></div><div>Thanks again for the help,</div><div>- David </div></div><br>