http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32074
--- Comment #8 from Siarhei Siamashka <siarhei.siamashka at gmail dot com> 2012-03-29 10:11:39 UTC --- (In reply to comment #5) > (In reply to comment #4) > > We have __builtin_unreachable() now which should allow for this > > optimization. > > I've been using __builtin_unreachable() for some time now, and it's very nice > for its intended purpose (telling gcc when it's safe to produce better code). > I've noticed, though, that the ``x'' passed to assert(x) in already-existing > code is often too expensive (or side effect-ful) to optimize away when > converted to ``if(!(x)) { __builtin_unreachable(); }'' Based on your comment, looks like asserts are just a superset of __builtin_unreachable() because asserts give more freedom to the compiler to either evaluate the expression or optimize it out. It's easy to replace __builtin_unreachable() with assert(0), but not the other way around as you have clearly demonstrated. Hence this enhancement request does not look to be fully resolved yet.