Skip to contentSkip to conversation

util/size.h: Fix build error for GCC < 10

PATCH In review Vaibhav Jain 2 participants 2 messages Feb 26, 2022 – Mar 2, 2022 libnvdimm: non-volatile memory device

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 util/size.h: Fix build error for GCC < 10

Building with GCC 8.4.1 results in following build error for 'util/size.c':

../util/size.h:57:16: error: missing binary operator before token "("
__has_builtin(__builtin_mul_overflow) && \

This is caused due to missing '__has_builtin' preprocessor operator in GCC versions < 10.0.0. The patch updates the check for CLANG's availability of __builtin_{mul,add}_overflow to prevent preprocessor from evaluating the expression "___has_builtin(__builtin_mul_overflow) && __has_builtin(__builtin_add_overflow)".

Fixes 10653a171bc0("util/size.h: fix build for older compilers")
---
 util/size.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
util/size.h +3 -2
index 1cb06690261b..02baa77fe649 100644
@@ -53,11 +53,12 @@ static inline bool is_power_of_2(unsigned long long v)
 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
 #endif
 
-#if __clang__ && \
-    __has_builtin(__builtin_mul_overflow) && \
+#if __clang__
+#if __has_builtin(__builtin_mul_overflow) && \
     __has_builtin(__builtin_add_overflow)
 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
 #endif
+#endif
 
 #if COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW
 
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Vaibhav Jain

Building with GCC 8.4.1 results in following build error for 'util/size.c':

../util/size.h:57:16: error: missing binary operator before token "("
__has_builtin(__builtin_mul_overflow) && \

This is caused due to missing '__has_builtin' preprocessor operator in GCC versions < 10.0.0. The patch updates the check for CLANG's availability of __builtin_{mul,add}_overflow to prevent preprocessor from evaluating the expression "___has_builtin(__builtin_mul_overflow) && __has_builtin(__builtin_add_overflow)".

Quoted 3 lines
Fixes 10653a171bc0("util/size.h: fix build for older compilers")
Quoted 23 lines
---
 util/size.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
util/size.h +3 -2
index 1cb06690261b..02baa77fe649 100644
@@ -53,11 +53,12 @@ static inline bool is_power_of_2(unsigned long long v)
 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
 #endif
 
-#if __clang__ && \
-    __has_builtin(__builtin_mul_overflow) && \
+#if __clang__
+#if __has_builtin(__builtin_mul_overflow) && \
     __has_builtin(__builtin_add_overflow)
 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
 #endif
+#endif
 
 #if COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW