Index: src/sqliteInt.h ================================================================== --- src/sqliteInt.h +++ src/sqliteInt.h @@ -107,10 +107,18 @@ #ifdef __GNUC__ # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) #else # define GCC_VERSION 0 #endif + +/* What version of CLANG is being used. 0 means GCC is not being used */ +#ifdef __clang__ +# define CLANG_VERSION \ + (__clang_major__*1000000+__clang_minor__*1000+__clang_patchlevel__) +#else +# define CLANG_VERSION 0 +#endif /* Needed for various definitions... */ #if defined(__GNUC__) && !defined(_GNU_SOURCE) # define _GNU_SOURCE #endif @@ -231,11 +239,11 @@ /* ** The SQLITE_ATOMIC_STATUS_DOWN macro is defined if and only if ** the sqlite3StatusDown() function is threadsafe. */ #if !defined(SQLITE_DISABLE_INTRINSIC) \ - && defined(__GNUC__) && GCC_VERSION>=4004000 + && (GCC_VERSION>=4004000 || CLANG_VERSION>=3000000) # define SQLITE_ATOMIC_STATUS_DOWN 1 #endif /* ** Make sure that the compiler intrinsics we desire are enabled when Index: src/status.c ================================================================== --- src/status.c +++ src/status.c @@ -100,11 +100,11 @@ void sqlite3StatusDown(int op, int N){ wsdStatInit; assert( N>=0 ); assert( op>=0 && op=4004000 + && (GCC_VERSION>=4004000 || CLANG_VERSION>=3000000) (void)__sync_fetch_and_sub(&wsdStat.nowValue[op], N); #else assert( op>=0 && op=4003000 + && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) u32 x; memcpy(&x,p,4); return __builtin_bswap32(x); #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ && defined(_MSC_VER) && _MSC_VER>=1300 @@ -1157,11 +1157,11 @@ } void sqlite3Put4byte(unsigned char *p, u32 v){ #if SQLITE_BYTEORDER==4321 memcpy(p,&v,4); #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ - && defined(__GNUC__) && GCC_VERSION>=4003000 + && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) u32 x = __builtin_bswap32(v); memcpy(p,&x,4); #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ && defined(_MSC_VER) && _MSC_VER>=1300 u32 x = _byteswap_ulong(v); @@ -1278,11 +1278,11 @@ ** Return 0 on success. Or if the operation would have resulted in an ** overflow, leave *pA unchanged and return 1. */ int sqlite3AddInt64(i64 *pA, i64 iB){ #if !defined(SQLITE_DISABLE_INTRINSIC) \ - && defined(__GNUC__) && GCC_VERSION>=5004000 + && (GCC_VERSION>=5004000 || CLANG_VERSION>=4000000) return __builtin_add_overflow(*pA, iB, pA); #else i64 iA = *pA; testcase( iA==0 ); testcase( iA==1 ); testcase( iB==-1 ); testcase( iB==0 ); @@ -1299,11 +1299,11 @@ return 0; #endif } int sqlite3SubInt64(i64 *pA, i64 iB){ #if !defined(SQLITE_DISABLE_INTRINSIC) \ - && defined(__GNUC__) && GCC_VERSION>=5004000 + && (GCC_VERSION>=5004000 || CLANG_VERSION>=4000000) return __builtin_sub_overflow(*pA, iB, pA); #else testcase( iB==SMALLEST_INT64+1 ); if( iB==SMALLEST_INT64 ){ testcase( (*pA)==(-1) ); testcase( (*pA)==0 ); @@ -1315,11 +1315,11 @@ } #endif } int sqlite3MulInt64(i64 *pA, i64 iB){ #if !defined(SQLITE_DISABLE_INTRINSIC) \ - && defined(__GNUC__) && GCC_VERSION>=5004000 + && (GCC_VERSION>=5004000 || CLANG_VERSION>=4000000) return __builtin_mul_overflow(*pA, iB, pA); #else i64 iA = *pA; if( iB>0 ){ if( iA>LARGEST_INT64/iB ) return 1;