]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: compiler: implement unreachable for older compilers too
authorWilly Tarreau <w@1wt.eu>
Wed, 8 Jun 2022 10:14:23 +0000 (12:14 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 8 Jun 2022 10:17:22 +0000 (12:17 +0200)
Benoit Dolez reported that gcc-4.4 emits several "may be used
uninitialized" warnings around places where there are BUG_ON()
or ABORT_NOW(). The reason is that __builtin_unreachable() was
introduced in gcc-4.5 thus older ones do not know that the code
after such statements is not reachable.

This patch solves the problem by deplacing the statement with
an infinite loop on older versions. The compiler knows that the
code following it cannot be reached, and this is quite cheap
(2 to 4 bytes depending on architectures). It even reduces the
code size a little bit as the compiler doesn't have to optimize
for branches that do not exist.

This may be backported to older versions.

include/haproxy/compiler.h

index a935ac3b5ad5432e66cbd633f5bee467265bb139..66b5f583572c3aa2491a47c8d18efcac075028b8 100644 (file)
 #if defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
 #define my_unreachable() __builtin_unreachable()
 #else
-#define my_unreachable()
+#define my_unreachable() do { } while (1)
 #endif
 #endif