From: Willy Tarreau Date: Tue, 17 Dec 2024 08:19:20 +0000 (+0100) Subject: MINOR: compiler: also enable __builtin_assume() for ASSUME() X-Git-Tag: v3.2-dev2~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ce63b7b17c45e31ef8c3dec33b9b54aea656154;p=thirdparty%2Fhaproxy.git MINOR: compiler: also enable __builtin_assume() for ASSUME() Clang apparently has __builtin_assume() which does exactly the same as our macro, since at least v3.8. Let's enable it, in case it may even better detect assumptions vs unreachable code. --- diff --git a/include/haproxy/compiler.h b/include/haproxy/compiler.h index dbafdac59e..c3a610aed9 100644 --- a/include/haproxy/compiler.h +++ b/include/haproxy/compiler.h @@ -219,9 +219,11 @@ * know that some conditions are not supposed to happen. This can only be used * with compilers that support it, and we do not want to emit any static code * for other ones, so we use a construct that the compiler should easily be - * able to optimize away. + * able to optimize away. Clang also has __builtin_assume() since at least 3.x. */ -#if __has_builtin(__builtin_unreachable) +#if __has_builtin(__builtin_assume) +# define ASSUME(expr) __builtin_assume(expr) +#elif __has_builtin(__builtin_unreachable) # define ASSUME(expr) do { if (!(expr)) __builtin_unreachable(); } while (0) #else # define ASSUME(expr) do { if (!(expr)) break; } while (0)