From 1781549688825f72cae344f0ef71c77744b12847 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 28 Jul 2022 00:37:20 +0200 Subject: [PATCH] btrfs-progs: kernel-lib: add stubs for overflow builtins Some older compilers do not support overflow builtins introduced in 5ad2aacd247a ("btrfs-progs: kernel-lib: sync include/overflow.h"). Add stubs to make it compile. This fixes CI build of Centos 7. Signed-off-by: David Sterba --- kernel-lib/overflow.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/kernel-lib/overflow.h b/kernel-lib/overflow.h index a7bb2084..a4cbd7cb 100644 --- a/kernel-lib/overflow.h +++ b/kernel-lib/overflow.h @@ -57,6 +57,22 @@ static inline bool __must_check __must_check_overflow(bool overflow) return overflow; } +/* + * Stubs for compiler without the overflow builtin support, no actual checks + * are done. + */ +#if !HAVE___BUILTIN_ADD_OVERFLOW +#define __builtin_add_overflow(__a, __b, __d) (*(__d) = (__a) + (__b), 0) +#endif + +#if !HAVE___BUILTIN_MUL_OVERFLOW +#define __builtin_mul_overflow(__a, __b, __d) (*(__d) = (__a) * (__b), 0) +#endif + +#if !HAVE___BUILTIN_MUL_OVERFLOW +#define __builtin_sub_overflow(__a, __b, __d) (*(__d) = (__a) - (__b), 0) +#endif + /* * For simplicity and code hygiene, the fallback code below insists on * a, b and *d having the same type (similar to the min() and max()