[ovs-dev] [PATCH] sat-math: Do not use __builtin_s*_overflow() with sparse.

Ben Pfaff blp at ovn.org
Wed Aug 21 17:17:21 UTC 2019


Some versions of sparse do not understand __builtin_saddll_overflow() and
related GCC builtins for calculations with overflow detection.  This patch
avoids using them when sparse is in use.

Reported-by: Justin Pettit <jpettit at ovn.org>
Tested-by: Justin Pettit <jpettit at ovn.org>
Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 lib/sat-math.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/sat-math.h b/lib/sat-math.h
index 8dda1515fdd0..d668723878db 100644
--- a/lib/sat-math.h
+++ b/lib/sat-math.h
@@ -41,7 +41,7 @@ llsat_add__(long long int x, long long int y)
 static inline long long int
 llsat_add(long long int x, long long int y)
 {
-#if __GNUC__ >= 5 || __has_builtin(__builtin_saddll_overflow)
+#if (__GNUC__ >= 5 || __has_builtin(__builtin_saddll_overflow)) && !__CHECKER__
     long long int sum;
     return (!__builtin_saddll_overflow(x, y, &sum) ? sum
             : x > 0 ? LLONG_MAX : LLONG_MIN);
@@ -67,7 +67,7 @@ llsat_sub__(long long int x, long long int y)
 static inline long long int
 llsat_sub(long long int x, long long int y)
 {
-#if __GNUC__ >= 5 || __has_builtin(__builtin_ssubll_overflow)
+#if (__GNUC__ >= 5 || __has_builtin(__builtin_ssubll_overflow)) && !__CHECKER__
     long long int difference;
     return (!__builtin_ssubll_overflow(x, y, &difference) ? difference
             : x >= 0 ? LLONG_MAX : LLONG_MIN);
@@ -97,7 +97,7 @@ llsat_mul__(long long int x, long long int y)
 static inline long long int
 llsat_mul(long long int x, long long int y)
 {
-#if __GNUC__ >= 5 || __has_builtin(__builtin_smulll_overflow)
+#if (__GNUC__ >= 5 || __has_builtin(__builtin_smulll_overflow)) && !__CHECKER__
     long long int product;
     return (!__builtin_smulll_overflow(x, y, &product) ? product
             : (x > 0) == (y > 0) ? LLONG_MAX : LLONG_MIN);
-- 
2.20.1



More information about the dev mailing list