From 96cfcb1df36fdf8fb963371ad5e167c733d842b1 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 17 Dec 2024 08:54:23 +0100 Subject: [PATCH] MINOR: compiler: add a __has_builtin() macro to detect features more easily We already have a __has_attribute() macro to detect when the compiler supports a specific attribute, but we didn't have the equivalent for builtins. clang-3 and gcc-10 have __has_builtin() for this. Let's just bring it using the same mechanism as __has_attribute(), which will allow us to simply define the macro's value for older compilers. It will save us from keeping that many compiler-specific tests that are incomplete (e.g. the __builtin_unreachable() test currently doesn't cover clang). --- include/haproxy/compiler.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/haproxy/compiler.h b/include/haproxy/compiler.h index ba4b12ddc..4fcf94c03 100644 --- a/include/haproxy/compiler.h +++ b/include/haproxy/compiler.h @@ -66,6 +66,14 @@ #define __has_attribute(x) __equals_1(__has_attribute_ ## x) #endif +/* gcc 10 and clang 3 brought __has_builtin() to test if a builtin exists. + * Just like above, if it doesn't exist, we remap it to a macro allowing us + * to define these ourselves by defining __has_builtin_ to 1. + */ +#ifndef __has_builtin +#define __has_builtin(x) __equals_1(__has_builtin_ ## x) +#endif + /* The fallthrough attribute arrived with gcc 7, the same version that started * to emit the fallthrough warnings and to parse the comments. Comments do not * manage to stop the warning when preprocessing is split from compiling (e.g.