Browse Source

Fix warnings for ilog (see below) gcc 4.1, and testsuite fixes.
(1) Include ilog.h header first (checks that it doesn't need anything else)
(2) Include ilog.c (only api tests don't need this).

Here are the warnings with gcc 4.1:
Running gcc -O3 -Wall -Wundef -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes
-Wmissing-declarations -Werror -Iccan/ -I. -o ccan/ilog/test/run ccan/ilog/test/run.c ccan/tap/tap.o
In file included from ccan/ilog/test/run.c:2:
ccan/ilog/ilog.h:27:10: error: "LLONG_MAX" is not defined
cc1: warnings being treated as errors
ccan/ilog/test/run.c: In function ‘main’:
ccan/ilog/test/run.c:36: warning: suggest brackets around + or - inside shift
ccan/ilog/test/run.c:55: warning: suggest brackets around + or - inside shift
ccan/ilog/test/run.c:55: warning: suggest brackets around + or - inside shift
ccan/ilog/test/run.c:55: warning: suggest brackets around + or - in operand of &
ccan/ilog/test/run.c:63: warning: suggest brackets around + or - inside shift
ccan/ilog/test/run.c:85: warning: suggest brackets around + or - inside shift
ccan/ilog/test/run.c:85: warning: suggest brackets around + or - inside shift
ccan/ilog/test/run.c:85: warning: suggest brackets around + or - in operand of &

Rusty Russell 17 years ago
parent
commit
2037a90372
2 changed files with 8 additions and 12 deletions
  1. 1 1
      ccan/ilog/ilog.h
  2. 7 11
      ccan/ilog/test/run.c

+ 1 - 1
ccan/ilog/ilog.h

@@ -24,7 +24,7 @@
 #   elif LONG_MAX>=9223372036854775807LL
 #   elif LONG_MAX>=9223372036854775807LL
 #    define CLZ64_OFFS ((int)sizeof(unsigned long)*CHAR_BIT)
 #    define CLZ64_OFFS ((int)sizeof(unsigned long)*CHAR_BIT)
 #    define CLZ64(_x) (__builtin_clzl(_x))
 #    define CLZ64(_x) (__builtin_clzl(_x))
-#   elif LLONG_MAX>=9223372036854775807LL
+#   else /* long long must be >= 64 bits according to ISO C */
 #    define CLZ64_OFFS ((int)sizeof(unsigned long long)*CHAR_BIT)
 #    define CLZ64_OFFS ((int)sizeof(unsigned long long)*CHAR_BIT)
 #    define CLZ64(_x) (__builtin_clzll(_x))
 #    define CLZ64(_x) (__builtin_clzll(_x))
 #   endif
 #   endif

+ 7 - 11
ccan/ilog/test/run.c

@@ -1,11 +1,7 @@
-#include <stdio.h>
 #include "ilog/ilog.h"
 #include "ilog/ilog.h"
+#include "ilog/ilog.c"
+#include <stdio.h>
 #include "tap/tap.h"
 #include "tap/tap.h"
-#if defined(__GNUC_PREREQ)
-# if __GNUC_PREREQ(4,2)
-#  pragma GCC diagnostic ignored "-Wparentheses"
-# endif
-#endif
 
 
 /*Dead simple (but slow) versions to compare against.*/
 /*Dead simple (but slow) versions to compare against.*/
 
 
@@ -33,7 +29,7 @@ int main(int _argc,const char *_argv[]){
   for(i=0;i<=32;i++){
   for(i=0;i<=32;i++){
     uint32_t v;
     uint32_t v;
     /*Test each bit in turn (and 0).*/
     /*Test each bit in turn (and 0).*/
-    v=i?(uint32_t)1U<<i-1:0;
+    v=i?(uint32_t)1U<<(i-1):0;
     for(j=0;j<NTRIALS;j++){
     for(j=0;j<NTRIALS;j++){
       int l;
       int l;
       l=test_ilog32(v);
       l=test_ilog32(v);
@@ -52,7 +48,7 @@ int main(int _argc,const char *_argv[]){
       else nmatches++;
       else nmatches++;
       /*Also try a few more pseudo-random values with at most the same number
       /*Also try a few more pseudo-random values with at most the same number
          of bits.*/
          of bits.*/
-      v=1103515245U*v+12345U&0xFFFFFFFFU>>(33-i>>1)>>(32-i>>1);
+      v=(1103515245U*v+12345U)&0xFFFFFFFFU>>((33-i)>>1)>>((32-i)>>1);
     }
     }
   }
   }
   ok1(nmatches==3*(32+1)*NTRIALS);
   ok1(nmatches==3*(32+1)*NTRIALS);
@@ -60,7 +56,7 @@ int main(int _argc,const char *_argv[]){
   for(i=0;i<=64;i++){
   for(i=0;i<=64;i++){
     uint64_t v;
     uint64_t v;
     /*Test each bit in turn (and 0).*/
     /*Test each bit in turn (and 0).*/
-    v=i?(uint64_t)1U<<i-1:0;
+    v=i?(uint64_t)1U<<(i-1):0;
     for(j=0;j<NTRIALS;j++){
     for(j=0;j<NTRIALS;j++){
       int l;
       int l;
       l=test_ilog64(v);
       l=test_ilog64(v);
@@ -81,8 +77,8 @@ int main(int _argc,const char *_argv[]){
       else nmatches++;
       else nmatches++;
       /*Also try a few more pseudo-random values with at most the same number
       /*Also try a few more pseudo-random values with at most the same number
          of bits.*/
          of bits.*/
-      v=(uint64_t)(2862933555777941757ULL*v+3037000493ULL
-       &0xFFFFFFFFFFFFFFFFULL>>(65-i>>1)>>(64-i>>1));
+      v=(uint64_t)((2862933555777941757ULL*v+3037000493ULL)
+	&0xFFFFFFFFFFFFFFFFULL>>((65-i)>>1)>>((64-i)>>1));
     }
     }
   }
   }
   ok1(nmatches==3*(64+1)*NTRIALS);
   ok1(nmatches==3*(64+1)*NTRIALS);