Re: CFR: a new __unreachable() builtin

From: Ed Schouten <ed_at_nuxi.nl>
Date: Sun, 17 May 2015 09:34:17 +0200
2015-05-13 18:09 GMT+02:00 David Chisnall <David.Chisnall_at_cl.cam.ac.uk>:
> LLVM uses this quite heavily, in a macro that expands to something equivalent to assert(0 && "unreachable reached!”) in debug mode and __builtin_unreachable() in release mode.  When you’re debugging, you get errors if you reach unreachable code and in deployment the compiler gets a useful hint for optimisation.

Too bad we can't use this trick in our own assert(). You'd need to
define assert() like this:

#define assert(expr) do { \
  if (!(expr)) \
    __builtin_unreachable(); \
} while (0)

Unfortunately, this would cause the expression to be evaluated, which
is not allowed.

-- 
Ed Schouten <ed_at_nuxi.nl>
Received on Sun May 17 2015 - 05:41:49 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:57 UTC