This is the mail archive of the
mailing list for the glibc project.
Re: [PATCH B2/2] Use builtin_unreachable in assert
- From: Marek Polacek <polacek at redhat dot com>
- To: Richard Henderson <rth at twiddle dot net>
- Cc: libc-alpha at sourceware dot org, roland at hack dot frob dot com
- Date: Mon, 2 Mar 2015 18:28:36 +0100
- Subject: Re: [PATCH B2/2] Use builtin_unreachable in assert
- Authentication-results: sourceware.org; auth=none
- References: <1420827419-18655-1-git-send-email-rth at twiddle dot net> <1420827419-18655-3-git-send-email-rth at twiddle dot net> <20150302074325 dot GB8519 at vapier> <54F49B67 dot 3060908 at twiddle dot net>
On Mon, Mar 02, 2015 at 09:18:31AM -0800, Richard Henderson wrote:
> On 03/01/2015 11:43 PM, Mike Frysinger wrote:
> > On 09 Jan 2015 10:16, Richard Henderson wrote:
> >> Finally, use __builtin_unreachable to tell the compiler about
> >> impossible paths.
> > i'm not sure this is the way to go. the expectation (as required by POSIX)
> > is that you're guaranteed there are no side-effects when NDEBUG is applied
> > to assert. by using __builtin_unreachable, that is no longer the case.
> I wonder if, during the gcc 6 development cycle, we should experiment with a
> __builtin_side_effects_p, akin to __builtin_constant_p. Then we could still
> follow POSIX re no side effects but even in the external context provide the
> information derivable from __builtin_unreachable. I.e.
> #define assert(X) \
> (__builtin_side_effects_p (X) || !(X) ? 0 : __builtin_unreachable ())
Tom wrote a patch implementing something like that a while back (for C
only) <https://gcc.gnu.org/ml/gcc-patches/2014-04/msg01984.html>, but
the patch never made it in. Maybe I could revive and adjust it during
gcc 6 stage 1 if it would help you.