Add builtin likely to assertions

Zack Weinberg zackw@panix.com
Wed Jul 29 14:06:38 GMT 2020


On Tue, Jul 28, 2020 at 10:19 PM Aditya K via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> > This is not needed for GCC to do the correct thing as __assert_fail is
> > marked as noreturn and GCC heuristics for branch prediction already
> > predicts it correctly and has done since at least 4.4 (or even
> > beforehand).
> > Can you explain more on which compiler this helps with?
>
> I saw this pattern in 'MacOSX.sdk/usr/include/assert.h', so added here. I don't have any test case to show a different layout with this patch.

That suggests that some versions of clang might not have the "noreturn
paths are cold" heuristic.  Can you test whether anything changes with
your patch on Linux with clang?  Try several different versions if
possible.

I want to be clear that we're _not_ rejecting your patch out of hand.
It's just that we don't want to add annotations that don't make any
difference for code generation.  If there is a compiler that's
commonly used with glibc, that either doesn't have the "noreturn paths
are cold" heuristic or doesn't understand that __assert_fail etc never
return, then we would take changes to assert.h to improve code
generation with that compiler.

zw


More information about the Libc-alpha mailing list