Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 May 2015 09:34:17 +0200
From:      Ed Schouten <ed@nuxi.nl>
To:        David Chisnall <David.Chisnall@cl.cam.ac.uk>
Cc:        Pedro Giffuni <pfg@freebsd.org>, FreeBSD Current <freebsd-current@freebsd.org>
Subject:   Re: CFR: a new __unreachable() builtin
Message-ID:  <CABh_MKn=EHccc2S0E0iWmN6dZk1xRwUvY8Q6hK_6QxUwXvhxEQ@mail.gmail.com>
In-Reply-To: <B452A3E8-DCC6-46B4-8066-17E8799072C3@cl.cam.ac.uk>
References:  <5553764A.9010202@FreeBSD.org> <B452A3E8-DCC6-46B4-8066-17E8799072C3@cl.cam.ac.uk>

index | next in thread | previous in thread | raw e-mail

2015-05-13 18:09 GMT+02:00 David Chisnall <David.Chisnall@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@nuxi.nl>


help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CABh_MKn=EHccc2S0E0iWmN6dZk1xRwUvY8Q6hK_6QxUwXvhxEQ>