Fossil SCM
Cherrypick [http://www.sqlite.org/src/info/810d29320b853b3a|810d29320b]: Remove the CLANG_VERSION macro, since we have learned that version numbers in clang are "marketing" and are inconsistent and unreliable. Builds using clang will still use the GCC_VERSION macro since clang works hard to be gcc compatible.
Commit
c453a916069a84e8da1aad2a6480349befd47ac7
Parent
17a33275f02c7f6…
1 file changed
+23
-28
+23
-28
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -202,27 +202,28 @@ | ||
| 202 | 202 | # define _FILE_OFFSET_BITS 64 |
| 203 | 203 | # endif |
| 204 | 204 | # define _LARGEFILE_SOURCE 1 |
| 205 | 205 | #endif |
| 206 | 206 | |
| 207 | -/* The GCC_VERSION, CLANG_VERSION, and MSVC_VERSION macros are used to | |
| 207 | +/* The GCC_VERSION and MSVC_VERSION macros are used to | |
| 208 | 208 | ** conditionally include optimizations for each of these compilers. A |
| 209 | 209 | ** value of 0 means that compiler is not being used. The |
| 210 | 210 | ** SQLITE_DISABLE_INTRINSIC macro means do not use any compiler-specific |
| 211 | 211 | ** optimizations, and hence set all compiler macros to 0 |
| 212 | +** | |
| 213 | +** There was once also a CLANG_VERSION macro. However, we learn that the | |
| 214 | +** version numbers in clang are for "marketing" only and are inconsistent | |
| 215 | +** and unreliable. Fortunately, all versions of clang also recognize the | |
| 216 | +** gcc version numbers and have reasonable settings for gcc version numbers, | |
| 217 | +** so the GCC_VERSION macro will be set to a correct non-zero value even | |
| 218 | +** when compiling with clang. | |
| 212 | 219 | */ |
| 213 | 220 | #if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 214 | 221 | # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) |
| 215 | 222 | #else |
| 216 | 223 | # define GCC_VERSION 0 |
| 217 | 224 | #endif |
| 218 | -#if defined(__clang__) && !defined(_WIN32) && !defined(SQLITE_DISABLE_INTRINSIC) | |
| 219 | -# define CLANG_VERSION \ | |
| 220 | - (__clang_major__*1000000+__clang_minor__*1000+__clang_patchlevel__) | |
| 221 | -#else | |
| 222 | -# define CLANG_VERSION 0 | |
| 223 | -#endif | |
| 224 | 225 | #if defined(_MSC_VER) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 225 | 226 | # define MSVC_VERSION _MSC_VER |
| 226 | 227 | #else |
| 227 | 228 | # define MSVC_VERSION 0 |
| 228 | 229 | #endif |
| @@ -28695,11 +28696,11 @@ | ||
| 28695 | 28696 | SQLITE_PRIVATE u32 sqlite3Get4byte(const u8 *p){ |
| 28696 | 28697 | #if SQLITE_BYTEORDER==4321 |
| 28697 | 28698 | u32 x; |
| 28698 | 28699 | memcpy(&x,p,4); |
| 28699 | 28700 | return x; |
| 28700 | -#elif SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) | |
| 28701 | +#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000 | |
| 28701 | 28702 | u32 x; |
| 28702 | 28703 | memcpy(&x,p,4); |
| 28703 | 28704 | return __builtin_bswap32(x); |
| 28704 | 28705 | #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 28705 | 28706 | u32 x; |
| @@ -28711,11 +28712,11 @@ | ||
| 28711 | 28712 | #endif |
| 28712 | 28713 | } |
| 28713 | 28714 | SQLITE_PRIVATE void sqlite3Put4byte(unsigned char *p, u32 v){ |
| 28714 | 28715 | #if SQLITE_BYTEORDER==4321 |
| 28715 | 28716 | memcpy(p,&v,4); |
| 28716 | -#elif SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) | |
| 28717 | +#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000 | |
| 28717 | 28718 | u32 x = __builtin_bswap32(v); |
| 28718 | 28719 | memcpy(p,&x,4); |
| 28719 | 28720 | #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 28720 | 28721 | u32 x = _byteswap_ulong(v); |
| 28721 | 28722 | memcpy(p,&x,4); |
| @@ -28830,11 +28831,11 @@ | ||
| 28830 | 28831 | ** the other 64-bit signed integer at *pA and store the result in *pA. |
| 28831 | 28832 | ** Return 0 on success. Or if the operation would have resulted in an |
| 28832 | 28833 | ** overflow, leave *pA unchanged and return 1. |
| 28833 | 28834 | */ |
| 28834 | 28835 | SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){ |
| 28835 | -#if GCC_VERSION>=5004000 || CLANG_VERSION>=4000000 | |
| 28836 | +#if GCC_VERSION>=5004000 | |
| 28836 | 28837 | return __builtin_add_overflow(*pA, iB, pA); |
| 28837 | 28838 | #else |
| 28838 | 28839 | i64 iA = *pA; |
| 28839 | 28840 | testcase( iA==0 ); testcase( iA==1 ); |
| 28840 | 28841 | testcase( iB==-1 ); testcase( iB==0 ); |
| @@ -28850,11 +28851,11 @@ | ||
| 28850 | 28851 | *pA += iB; |
| 28851 | 28852 | return 0; |
| 28852 | 28853 | #endif |
| 28853 | 28854 | } |
| 28854 | 28855 | SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){ |
| 28855 | -#if GCC_VERSION>=5004000 || CLANG_VERSION>=4000000 | |
| 28856 | +#if GCC_VERSION>=5004000 | |
| 28856 | 28857 | return __builtin_sub_overflow(*pA, iB, pA); |
| 28857 | 28858 | #else |
| 28858 | 28859 | testcase( iB==SMALLEST_INT64+1 ); |
| 28859 | 28860 | if( iB==SMALLEST_INT64 ){ |
| 28860 | 28861 | testcase( (*pA)==(-1) ); testcase( (*pA)==0 ); |
| @@ -28865,11 +28866,11 @@ | ||
| 28865 | 28866 | return sqlite3AddInt64(pA, -iB); |
| 28866 | 28867 | } |
| 28867 | 28868 | #endif |
| 28868 | 28869 | } |
| 28869 | 28870 | SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){ |
| 28870 | -#if GCC_VERSION>=5004000 || CLANG_VERSION>=4000000 | |
| 28871 | +#if GCC_VERSION>=5004000 | |
| 28871 | 28872 | return __builtin_mul_overflow(*pA, iB, pA); |
| 28872 | 28873 | #else |
| 28873 | 28874 | i64 iA = *pA; |
| 28874 | 28875 | if( iB>0 ){ |
| 28875 | 28876 | if( iA>LARGEST_INT64/iB ) return 1; |
| @@ -163302,27 +163303,21 @@ | ||
| 163302 | 163303 | #endif |
| 163303 | 163304 | #ifndef MIN |
| 163304 | 163305 | # define MIN(x,y) ((x) > (y) ? (y) : (x)) |
| 163305 | 163306 | #endif |
| 163306 | 163307 | |
| 163307 | -/* What version of GCC is being used. 0 means GCC is not being used */ | |
| 163308 | +/* What version of GCC is being used. 0 means GCC is not being used . | |
| 163309 | +** Note that the GCC_VERSION macro will also be set correctly when using | |
| 163310 | +** clang, since clang works hard to be gcc compatible. So the gcc | |
| 163311 | +** optimizations will also work when compiling with clang. | |
| 163312 | +*/ | |
| 163308 | 163313 | #ifndef GCC_VERSION |
| 163309 | 163314 | #if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 163310 | 163315 | # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) |
| 163311 | 163316 | #else |
| 163312 | 163317 | # define GCC_VERSION 0 |
| 163313 | 163318 | #endif |
| 163314 | -#endif | |
| 163315 | - | |
| 163316 | -/* What version of CLANG is being used. 0 means CLANG is not being used */ | |
| 163317 | -#ifndef CLANG_VERSION | |
| 163318 | -#if defined(__clang__) && !defined(_WIN32) && !defined(SQLITE_DISABLE_INTRINSIC) | |
| 163319 | -# define CLANG_VERSION \ | |
| 163320 | - (__clang_major__*1000000+__clang_minor__*1000+__clang_patchlevel__) | |
| 163321 | -#else | |
| 163322 | -# define CLANG_VERSION 0 | |
| 163323 | -#endif | |
| 163324 | 163319 | #endif |
| 163325 | 163320 | |
| 163326 | 163321 | /* The testcase() macro should already be defined in the amalgamation. If |
| 163327 | 163322 | ** it is not, make it a no-op. |
| 163328 | 163323 | */ |
| @@ -163371,11 +163366,11 @@ | ||
| 163371 | 163366 | } |
| 163372 | 163367 | static void readCoord(u8 *p, RtreeCoord *pCoord){ |
| 163373 | 163368 | assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */ |
| 163374 | 163369 | #if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163375 | 163370 | pCoord->u = _byteswap_ulong(*(u32*)p); |
| 163376 | -#elif SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) | |
| 163371 | +#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000 | |
| 163377 | 163372 | pCoord->u = __builtin_bswap32(*(u32*)p); |
| 163378 | 163373 | #elif SQLITE_BYTEORDER==4321 |
| 163379 | 163374 | pCoord->u = *(u32*)p; |
| 163380 | 163375 | #else |
| 163381 | 163376 | pCoord->u = ( |
| @@ -163389,11 +163384,11 @@ | ||
| 163389 | 163384 | static i64 readInt64(u8 *p){ |
| 163390 | 163385 | #if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163391 | 163386 | u64 x; |
| 163392 | 163387 | memcpy(&x, p, 8); |
| 163393 | 163388 | return (i64)_byteswap_uint64(x); |
| 163394 | -#elif SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) | |
| 163389 | +#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000 | |
| 163395 | 163390 | u64 x; |
| 163396 | 163391 | memcpy(&x, p, 8); |
| 163397 | 163392 | return (i64)__builtin_bswap64(x); |
| 163398 | 163393 | #elif SQLITE_BYTEORDER==4321 |
| 163399 | 163394 | i64 x; |
| @@ -163425,11 +163420,11 @@ | ||
| 163425 | 163420 | static int writeCoord(u8 *p, RtreeCoord *pCoord){ |
| 163426 | 163421 | u32 i; |
| 163427 | 163422 | assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */ |
| 163428 | 163423 | assert( sizeof(RtreeCoord)==4 ); |
| 163429 | 163424 | assert( sizeof(u32)==4 ); |
| 163430 | -#if SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) | |
| 163425 | +#if SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000 | |
| 163431 | 163426 | i = __builtin_bswap32(pCoord->u); |
| 163432 | 163427 | memcpy(p, &i, 4); |
| 163433 | 163428 | #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163434 | 163429 | i = _byteswap_ulong(pCoord->u); |
| 163435 | 163430 | memcpy(p, &i, 4); |
| @@ -163444,11 +163439,11 @@ | ||
| 163444 | 163439 | p[3] = (i>> 0)&0xFF; |
| 163445 | 163440 | #endif |
| 163446 | 163441 | return 4; |
| 163447 | 163442 | } |
| 163448 | 163443 | static int writeInt64(u8 *p, i64 i){ |
| 163449 | -#if SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) | |
| 163444 | +#if SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000 | |
| 163450 | 163445 | i = (i64)__builtin_bswap64((u64)i); |
| 163451 | 163446 | memcpy(p, &i, 8); |
| 163452 | 163447 | #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163453 | 163448 | i = (i64)_byteswap_uint64((u64)i); |
| 163454 | 163449 | memcpy(p, &i, 8); |
| @@ -164000,11 +163995,11 @@ | ||
| 164000 | 163995 | #define RTREE_DECODE_COORD(eInt, a, r) { \ |
| 164001 | 163996 | RtreeCoord c; /* Coordinate decoded */ \ |
| 164002 | 163997 | c.u = _byteswap_ulong(*(u32*)a); \ |
| 164003 | 163998 | r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ |
| 164004 | 163999 | } |
| 164005 | -#elif SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) | |
| 164000 | +#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000 | |
| 164006 | 164001 | #define RTREE_DECODE_COORD(eInt, a, r) { \ |
| 164007 | 164002 | RtreeCoord c; /* Coordinate decoded */ \ |
| 164008 | 164003 | c.u = __builtin_bswap32(*(u32*)a); \ |
| 164009 | 164004 | r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ |
| 164010 | 164005 | } |
| 164011 | 164006 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -202,27 +202,28 @@ | |
| 202 | # define _FILE_OFFSET_BITS 64 |
| 203 | # endif |
| 204 | # define _LARGEFILE_SOURCE 1 |
| 205 | #endif |
| 206 | |
| 207 | /* The GCC_VERSION, CLANG_VERSION, and MSVC_VERSION macros are used to |
| 208 | ** conditionally include optimizations for each of these compilers. A |
| 209 | ** value of 0 means that compiler is not being used. The |
| 210 | ** SQLITE_DISABLE_INTRINSIC macro means do not use any compiler-specific |
| 211 | ** optimizations, and hence set all compiler macros to 0 |
| 212 | */ |
| 213 | #if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 214 | # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) |
| 215 | #else |
| 216 | # define GCC_VERSION 0 |
| 217 | #endif |
| 218 | #if defined(__clang__) && !defined(_WIN32) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 219 | # define CLANG_VERSION \ |
| 220 | (__clang_major__*1000000+__clang_minor__*1000+__clang_patchlevel__) |
| 221 | #else |
| 222 | # define CLANG_VERSION 0 |
| 223 | #endif |
| 224 | #if defined(_MSC_VER) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 225 | # define MSVC_VERSION _MSC_VER |
| 226 | #else |
| 227 | # define MSVC_VERSION 0 |
| 228 | #endif |
| @@ -28695,11 +28696,11 @@ | |
| 28695 | SQLITE_PRIVATE u32 sqlite3Get4byte(const u8 *p){ |
| 28696 | #if SQLITE_BYTEORDER==4321 |
| 28697 | u32 x; |
| 28698 | memcpy(&x,p,4); |
| 28699 | return x; |
| 28700 | #elif SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) |
| 28701 | u32 x; |
| 28702 | memcpy(&x,p,4); |
| 28703 | return __builtin_bswap32(x); |
| 28704 | #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 28705 | u32 x; |
| @@ -28711,11 +28712,11 @@ | |
| 28711 | #endif |
| 28712 | } |
| 28713 | SQLITE_PRIVATE void sqlite3Put4byte(unsigned char *p, u32 v){ |
| 28714 | #if SQLITE_BYTEORDER==4321 |
| 28715 | memcpy(p,&v,4); |
| 28716 | #elif SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) |
| 28717 | u32 x = __builtin_bswap32(v); |
| 28718 | memcpy(p,&x,4); |
| 28719 | #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 28720 | u32 x = _byteswap_ulong(v); |
| 28721 | memcpy(p,&x,4); |
| @@ -28830,11 +28831,11 @@ | |
| 28830 | ** the other 64-bit signed integer at *pA and store the result in *pA. |
| 28831 | ** Return 0 on success. Or if the operation would have resulted in an |
| 28832 | ** overflow, leave *pA unchanged and return 1. |
| 28833 | */ |
| 28834 | SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){ |
| 28835 | #if GCC_VERSION>=5004000 || CLANG_VERSION>=4000000 |
| 28836 | return __builtin_add_overflow(*pA, iB, pA); |
| 28837 | #else |
| 28838 | i64 iA = *pA; |
| 28839 | testcase( iA==0 ); testcase( iA==1 ); |
| 28840 | testcase( iB==-1 ); testcase( iB==0 ); |
| @@ -28850,11 +28851,11 @@ | |
| 28850 | *pA += iB; |
| 28851 | return 0; |
| 28852 | #endif |
| 28853 | } |
| 28854 | SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){ |
| 28855 | #if GCC_VERSION>=5004000 || CLANG_VERSION>=4000000 |
| 28856 | return __builtin_sub_overflow(*pA, iB, pA); |
| 28857 | #else |
| 28858 | testcase( iB==SMALLEST_INT64+1 ); |
| 28859 | if( iB==SMALLEST_INT64 ){ |
| 28860 | testcase( (*pA)==(-1) ); testcase( (*pA)==0 ); |
| @@ -28865,11 +28866,11 @@ | |
| 28865 | return sqlite3AddInt64(pA, -iB); |
| 28866 | } |
| 28867 | #endif |
| 28868 | } |
| 28869 | SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){ |
| 28870 | #if GCC_VERSION>=5004000 || CLANG_VERSION>=4000000 |
| 28871 | return __builtin_mul_overflow(*pA, iB, pA); |
| 28872 | #else |
| 28873 | i64 iA = *pA; |
| 28874 | if( iB>0 ){ |
| 28875 | if( iA>LARGEST_INT64/iB ) return 1; |
| @@ -163302,27 +163303,21 @@ | |
| 163302 | #endif |
| 163303 | #ifndef MIN |
| 163304 | # define MIN(x,y) ((x) > (y) ? (y) : (x)) |
| 163305 | #endif |
| 163306 | |
| 163307 | /* What version of GCC is being used. 0 means GCC is not being used */ |
| 163308 | #ifndef GCC_VERSION |
| 163309 | #if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 163310 | # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) |
| 163311 | #else |
| 163312 | # define GCC_VERSION 0 |
| 163313 | #endif |
| 163314 | #endif |
| 163315 | |
| 163316 | /* What version of CLANG is being used. 0 means CLANG is not being used */ |
| 163317 | #ifndef CLANG_VERSION |
| 163318 | #if defined(__clang__) && !defined(_WIN32) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 163319 | # define CLANG_VERSION \ |
| 163320 | (__clang_major__*1000000+__clang_minor__*1000+__clang_patchlevel__) |
| 163321 | #else |
| 163322 | # define CLANG_VERSION 0 |
| 163323 | #endif |
| 163324 | #endif |
| 163325 | |
| 163326 | /* The testcase() macro should already be defined in the amalgamation. If |
| 163327 | ** it is not, make it a no-op. |
| 163328 | */ |
| @@ -163371,11 +163366,11 @@ | |
| 163371 | } |
| 163372 | static void readCoord(u8 *p, RtreeCoord *pCoord){ |
| 163373 | assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */ |
| 163374 | #if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163375 | pCoord->u = _byteswap_ulong(*(u32*)p); |
| 163376 | #elif SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) |
| 163377 | pCoord->u = __builtin_bswap32(*(u32*)p); |
| 163378 | #elif SQLITE_BYTEORDER==4321 |
| 163379 | pCoord->u = *(u32*)p; |
| 163380 | #else |
| 163381 | pCoord->u = ( |
| @@ -163389,11 +163384,11 @@ | |
| 163389 | static i64 readInt64(u8 *p){ |
| 163390 | #if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163391 | u64 x; |
| 163392 | memcpy(&x, p, 8); |
| 163393 | return (i64)_byteswap_uint64(x); |
| 163394 | #elif SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) |
| 163395 | u64 x; |
| 163396 | memcpy(&x, p, 8); |
| 163397 | return (i64)__builtin_bswap64(x); |
| 163398 | #elif SQLITE_BYTEORDER==4321 |
| 163399 | i64 x; |
| @@ -163425,11 +163420,11 @@ | |
| 163425 | static int writeCoord(u8 *p, RtreeCoord *pCoord){ |
| 163426 | u32 i; |
| 163427 | assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */ |
| 163428 | assert( sizeof(RtreeCoord)==4 ); |
| 163429 | assert( sizeof(u32)==4 ); |
| 163430 | #if SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) |
| 163431 | i = __builtin_bswap32(pCoord->u); |
| 163432 | memcpy(p, &i, 4); |
| 163433 | #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163434 | i = _byteswap_ulong(pCoord->u); |
| 163435 | memcpy(p, &i, 4); |
| @@ -163444,11 +163439,11 @@ | |
| 163444 | p[3] = (i>> 0)&0xFF; |
| 163445 | #endif |
| 163446 | return 4; |
| 163447 | } |
| 163448 | static int writeInt64(u8 *p, i64 i){ |
| 163449 | #if SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) |
| 163450 | i = (i64)__builtin_bswap64((u64)i); |
| 163451 | memcpy(p, &i, 8); |
| 163452 | #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163453 | i = (i64)_byteswap_uint64((u64)i); |
| 163454 | memcpy(p, &i, 8); |
| @@ -164000,11 +163995,11 @@ | |
| 164000 | #define RTREE_DECODE_COORD(eInt, a, r) { \ |
| 164001 | RtreeCoord c; /* Coordinate decoded */ \ |
| 164002 | c.u = _byteswap_ulong(*(u32*)a); \ |
| 164003 | r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ |
| 164004 | } |
| 164005 | #elif SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) |
| 164006 | #define RTREE_DECODE_COORD(eInt, a, r) { \ |
| 164007 | RtreeCoord c; /* Coordinate decoded */ \ |
| 164008 | c.u = __builtin_bswap32(*(u32*)a); \ |
| 164009 | r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ |
| 164010 | } |
| 164011 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -202,27 +202,28 @@ | |
| 202 | # define _FILE_OFFSET_BITS 64 |
| 203 | # endif |
| 204 | # define _LARGEFILE_SOURCE 1 |
| 205 | #endif |
| 206 | |
| 207 | /* The GCC_VERSION and MSVC_VERSION macros are used to |
| 208 | ** conditionally include optimizations for each of these compilers. A |
| 209 | ** value of 0 means that compiler is not being used. The |
| 210 | ** SQLITE_DISABLE_INTRINSIC macro means do not use any compiler-specific |
| 211 | ** optimizations, and hence set all compiler macros to 0 |
| 212 | ** |
| 213 | ** There was once also a CLANG_VERSION macro. However, we learn that the |
| 214 | ** version numbers in clang are for "marketing" only and are inconsistent |
| 215 | ** and unreliable. Fortunately, all versions of clang also recognize the |
| 216 | ** gcc version numbers and have reasonable settings for gcc version numbers, |
| 217 | ** so the GCC_VERSION macro will be set to a correct non-zero value even |
| 218 | ** when compiling with clang. |
| 219 | */ |
| 220 | #if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 221 | # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) |
| 222 | #else |
| 223 | # define GCC_VERSION 0 |
| 224 | #endif |
| 225 | #if defined(_MSC_VER) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 226 | # define MSVC_VERSION _MSC_VER |
| 227 | #else |
| 228 | # define MSVC_VERSION 0 |
| 229 | #endif |
| @@ -28695,11 +28696,11 @@ | |
| 28696 | SQLITE_PRIVATE u32 sqlite3Get4byte(const u8 *p){ |
| 28697 | #if SQLITE_BYTEORDER==4321 |
| 28698 | u32 x; |
| 28699 | memcpy(&x,p,4); |
| 28700 | return x; |
| 28701 | #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000 |
| 28702 | u32 x; |
| 28703 | memcpy(&x,p,4); |
| 28704 | return __builtin_bswap32(x); |
| 28705 | #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 28706 | u32 x; |
| @@ -28711,11 +28712,11 @@ | |
| 28712 | #endif |
| 28713 | } |
| 28714 | SQLITE_PRIVATE void sqlite3Put4byte(unsigned char *p, u32 v){ |
| 28715 | #if SQLITE_BYTEORDER==4321 |
| 28716 | memcpy(p,&v,4); |
| 28717 | #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000 |
| 28718 | u32 x = __builtin_bswap32(v); |
| 28719 | memcpy(p,&x,4); |
| 28720 | #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 28721 | u32 x = _byteswap_ulong(v); |
| 28722 | memcpy(p,&x,4); |
| @@ -28830,11 +28831,11 @@ | |
| 28831 | ** the other 64-bit signed integer at *pA and store the result in *pA. |
| 28832 | ** Return 0 on success. Or if the operation would have resulted in an |
| 28833 | ** overflow, leave *pA unchanged and return 1. |
| 28834 | */ |
| 28835 | SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){ |
| 28836 | #if GCC_VERSION>=5004000 |
| 28837 | return __builtin_add_overflow(*pA, iB, pA); |
| 28838 | #else |
| 28839 | i64 iA = *pA; |
| 28840 | testcase( iA==0 ); testcase( iA==1 ); |
| 28841 | testcase( iB==-1 ); testcase( iB==0 ); |
| @@ -28850,11 +28851,11 @@ | |
| 28851 | *pA += iB; |
| 28852 | return 0; |
| 28853 | #endif |
| 28854 | } |
| 28855 | SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){ |
| 28856 | #if GCC_VERSION>=5004000 |
| 28857 | return __builtin_sub_overflow(*pA, iB, pA); |
| 28858 | #else |
| 28859 | testcase( iB==SMALLEST_INT64+1 ); |
| 28860 | if( iB==SMALLEST_INT64 ){ |
| 28861 | testcase( (*pA)==(-1) ); testcase( (*pA)==0 ); |
| @@ -28865,11 +28866,11 @@ | |
| 28866 | return sqlite3AddInt64(pA, -iB); |
| 28867 | } |
| 28868 | #endif |
| 28869 | } |
| 28870 | SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){ |
| 28871 | #if GCC_VERSION>=5004000 |
| 28872 | return __builtin_mul_overflow(*pA, iB, pA); |
| 28873 | #else |
| 28874 | i64 iA = *pA; |
| 28875 | if( iB>0 ){ |
| 28876 | if( iA>LARGEST_INT64/iB ) return 1; |
| @@ -163302,27 +163303,21 @@ | |
| 163303 | #endif |
| 163304 | #ifndef MIN |
| 163305 | # define MIN(x,y) ((x) > (y) ? (y) : (x)) |
| 163306 | #endif |
| 163307 | |
| 163308 | /* What version of GCC is being used. 0 means GCC is not being used . |
| 163309 | ** Note that the GCC_VERSION macro will also be set correctly when using |
| 163310 | ** clang, since clang works hard to be gcc compatible. So the gcc |
| 163311 | ** optimizations will also work when compiling with clang. |
| 163312 | */ |
| 163313 | #ifndef GCC_VERSION |
| 163314 | #if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 163315 | # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) |
| 163316 | #else |
| 163317 | # define GCC_VERSION 0 |
| 163318 | #endif |
| 163319 | #endif |
| 163320 | |
| 163321 | /* The testcase() macro should already be defined in the amalgamation. If |
| 163322 | ** it is not, make it a no-op. |
| 163323 | */ |
| @@ -163371,11 +163366,11 @@ | |
| 163366 | } |
| 163367 | static void readCoord(u8 *p, RtreeCoord *pCoord){ |
| 163368 | assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */ |
| 163369 | #if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163370 | pCoord->u = _byteswap_ulong(*(u32*)p); |
| 163371 | #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000 |
| 163372 | pCoord->u = __builtin_bswap32(*(u32*)p); |
| 163373 | #elif SQLITE_BYTEORDER==4321 |
| 163374 | pCoord->u = *(u32*)p; |
| 163375 | #else |
| 163376 | pCoord->u = ( |
| @@ -163389,11 +163384,11 @@ | |
| 163384 | static i64 readInt64(u8 *p){ |
| 163385 | #if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163386 | u64 x; |
| 163387 | memcpy(&x, p, 8); |
| 163388 | return (i64)_byteswap_uint64(x); |
| 163389 | #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000 |
| 163390 | u64 x; |
| 163391 | memcpy(&x, p, 8); |
| 163392 | return (i64)__builtin_bswap64(x); |
| 163393 | #elif SQLITE_BYTEORDER==4321 |
| 163394 | i64 x; |
| @@ -163425,11 +163420,11 @@ | |
| 163420 | static int writeCoord(u8 *p, RtreeCoord *pCoord){ |
| 163421 | u32 i; |
| 163422 | assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */ |
| 163423 | assert( sizeof(RtreeCoord)==4 ); |
| 163424 | assert( sizeof(u32)==4 ); |
| 163425 | #if SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000 |
| 163426 | i = __builtin_bswap32(pCoord->u); |
| 163427 | memcpy(p, &i, 4); |
| 163428 | #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163429 | i = _byteswap_ulong(pCoord->u); |
| 163430 | memcpy(p, &i, 4); |
| @@ -163444,11 +163439,11 @@ | |
| 163439 | p[3] = (i>> 0)&0xFF; |
| 163440 | #endif |
| 163441 | return 4; |
| 163442 | } |
| 163443 | static int writeInt64(u8 *p, i64 i){ |
| 163444 | #if SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000 |
| 163445 | i = (i64)__builtin_bswap64((u64)i); |
| 163446 | memcpy(p, &i, 8); |
| 163447 | #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163448 | i = (i64)_byteswap_uint64((u64)i); |
| 163449 | memcpy(p, &i, 8); |
| @@ -164000,11 +163995,11 @@ | |
| 163995 | #define RTREE_DECODE_COORD(eInt, a, r) { \ |
| 163996 | RtreeCoord c; /* Coordinate decoded */ \ |
| 163997 | c.u = _byteswap_ulong(*(u32*)a); \ |
| 163998 | r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ |
| 163999 | } |
| 164000 | #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000 |
| 164001 | #define RTREE_DECODE_COORD(eInt, a, r) { \ |
| 164002 | RtreeCoord c; /* Coordinate decoded */ \ |
| 164003 | c.u = __builtin_bswap32(*(u32*)a); \ |
| 164004 | r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ |
| 164005 | } |
| 164006 |