/ Check-in [f8ebeec2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Use the CLANG_VERSION macro to control clang-specific features.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | gnu-safe-math
Files: files | file ages | folders
SHA1: f8ebeec211483503e135104ef977b3c384a1d789
User & Date: drh 2017-01-03 20:01:24
Context
2017-01-03
21:03
Fix a typo in a comment. check-in: ae087123 user: drh tags: gnu-safe-math
20:01
Use the CLANG_VERSION macro to control clang-specific features. check-in: f8ebeec2 user: drh tags: gnu-safe-math
18:05
Use the GCC built-in __sync_fetch_and_sub() to make the sqlite3StatusDown() routine atomic, and thereby avoid some mutexing. check-in: f69ce75b user: drh tags: gnu-safe-math
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/sqliteInt.h.

   105    105   
   106    106   /* What version of GCC is being used.  0 means GCC is not being used */
   107    107   #ifdef __GNUC__
   108    108   # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__)
   109    109   #else
   110    110   # define GCC_VERSION 0
   111    111   #endif
          112  +
          113  +/* What version of CLANG is being used.  0 means GCC is not being used */
          114  +#ifdef __clang__
          115  +# define CLANG_VERSION \
          116  +            (__clang_major__*1000000+__clang_minor__*1000+__clang_patchlevel__)
          117  +#else
          118  +# define CLANG_VERSION 0
          119  +#endif
   112    120   
   113    121   /* Needed for various definitions... */
   114    122   #if defined(__GNUC__) && !defined(_GNU_SOURCE)
   115    123   # define _GNU_SOURCE
   116    124   #endif
   117    125   
   118    126   #if defined(__OpenBSD__) && !defined(_BSD_SOURCE)
................................................................................
   229    237   #endif
   230    238   
   231    239   /*
   232    240   ** The SQLITE_ATOMIC_STATUS_DOWN macro is defined if and only if
   233    241   ** the sqlite3StatusDown() function is threadsafe.
   234    242   */
   235    243   #if !defined(SQLITE_DISABLE_INTRINSIC) \
   236         -    && defined(__GNUC__) && GCC_VERSION>=4004000
          244  +    && (GCC_VERSION>=4004000 || CLANG_VERSION>=3000000)
   237    245   # define SQLITE_ATOMIC_STATUS_DOWN 1
   238    246   #endif
   239    247   
   240    248   /*
   241    249   ** Make sure that the compiler intrinsics we desire are enabled when
   242    250   ** compiling with an appropriate version of MSVC unless prevented by
   243    251   ** the SQLITE_DISABLE_INTRINSIC define.

Changes to src/status.c.

    98     98     }
    99     99   }
   100    100   void sqlite3StatusDown(int op, int N){
   101    101     wsdStatInit;
   102    102     assert( N>=0 );
   103    103     assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
   104    104   #if !defined(SQLITE_DISABLE_INTRINSIC) \
   105         -    && defined(__GNUC__) && GCC_VERSION>=4004000
          105  +    && (GCC_VERSION>=4004000 || CLANG_VERSION>=3000000)
   106    106     (void)__sync_fetch_and_sub(&wsdStat.nowValue[op], N);
   107    107   #else
   108    108     assert( op>=0 && op<ArraySize(statMutex) );
   109    109     assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex()
   110    110                                              : sqlite3MallocMutex()) );
   111    111     wsdStat.nowValue[op] -= N;
   112    112   #endif

Changes to src/util.c.

  1137   1137   */
  1138   1138   u32 sqlite3Get4byte(const u8 *p){
  1139   1139   #if SQLITE_BYTEORDER==4321
  1140   1140     u32 x;
  1141   1141     memcpy(&x,p,4);
  1142   1142     return x;
  1143   1143   #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
  1144         -    && defined(__GNUC__) && GCC_VERSION>=4003000
         1144  +    && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000)
  1145   1145     u32 x;
  1146   1146     memcpy(&x,p,4);
  1147   1147     return __builtin_bswap32(x);
  1148   1148   #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
  1149   1149       && defined(_MSC_VER) && _MSC_VER>=1300
  1150   1150     u32 x;
  1151   1151     memcpy(&x,p,4);
................................................................................
  1155   1155     return ((unsigned)p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
  1156   1156   #endif
  1157   1157   }
  1158   1158   void sqlite3Put4byte(unsigned char *p, u32 v){
  1159   1159   #if SQLITE_BYTEORDER==4321
  1160   1160     memcpy(p,&v,4);
  1161   1161   #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
  1162         -    && defined(__GNUC__) && GCC_VERSION>=4003000
         1162  +    && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000)
  1163   1163     u32 x = __builtin_bswap32(v);
  1164   1164     memcpy(p,&x,4);
  1165   1165   #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
  1166   1166       && defined(_MSC_VER) && _MSC_VER>=1300
  1167   1167     u32 x = _byteswap_ulong(v);
  1168   1168     memcpy(p,&x,4);
  1169   1169   #else
................................................................................
  1276   1276   ** Attempt to add, substract, or multiply the 64-bit signed value iB against
  1277   1277   ** the other 64-bit signed integer at *pA and store the result in *pA.
  1278   1278   ** Return 0 on success.  Or if the operation would have resulted in an
  1279   1279   ** overflow, leave *pA unchanged and return 1.
  1280   1280   */
  1281   1281   int sqlite3AddInt64(i64 *pA, i64 iB){
  1282   1282   #if !defined(SQLITE_DISABLE_INTRINSIC) \
  1283         -    && defined(__GNUC__) && GCC_VERSION>=5004000
         1283  +    && (GCC_VERSION>=5004000 || CLANG_VERSION>=4000000)
  1284   1284     return __builtin_add_overflow(*pA, iB, pA);
  1285   1285   #else
  1286   1286     i64 iA = *pA;
  1287   1287     testcase( iA==0 ); testcase( iA==1 );
  1288   1288     testcase( iB==-1 ); testcase( iB==0 );
  1289   1289     if( iB>=0 ){
  1290   1290       testcase( iA>0 && LARGEST_INT64 - iA == iB );
................................................................................
  1297   1297     }
  1298   1298     *pA += iB;
  1299   1299     return 0; 
  1300   1300   #endif
  1301   1301   }
  1302   1302   int sqlite3SubInt64(i64 *pA, i64 iB){
  1303   1303   #if !defined(SQLITE_DISABLE_INTRINSIC) \
  1304         -    && defined(__GNUC__) && GCC_VERSION>=5004000
         1304  +    && (GCC_VERSION>=5004000 || CLANG_VERSION>=4000000)
  1305   1305     return __builtin_sub_overflow(*pA, iB, pA);
  1306   1306   #else
  1307   1307     testcase( iB==SMALLEST_INT64+1 );
  1308   1308     if( iB==SMALLEST_INT64 ){
  1309   1309       testcase( (*pA)==(-1) ); testcase( (*pA)==0 );
  1310   1310       if( (*pA)>=0 ) return 1;
  1311   1311       *pA -= iB;
................................................................................
  1313   1313     }else{
  1314   1314       return sqlite3AddInt64(pA, -iB);
  1315   1315     }
  1316   1316   #endif
  1317   1317   }
  1318   1318   int sqlite3MulInt64(i64 *pA, i64 iB){
  1319   1319   #if !defined(SQLITE_DISABLE_INTRINSIC) \
  1320         -    && defined(__GNUC__) && GCC_VERSION>=5004000
         1320  +    && (GCC_VERSION>=5004000 || CLANG_VERSION>=4000000)
  1321   1321     return __builtin_mul_overflow(*pA, iB, pA);
  1322   1322   #else
  1323   1323     i64 iA = *pA;
  1324   1324     if( iB>0 ){
  1325   1325       if( iA>LARGEST_INT64/iB ) return 1;
  1326   1326       if( iA<SMALLEST_INT64/iB ) return 1;
  1327   1327     }else if( iB<0 ){