From 7d7024044976711483d238fd0ce8ba4114faa018 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Fri, 20 Feb 2015 00:06:09 -0500 Subject: [PATCH] general: First pass cast qualifier warning fixes. --- configure | 2 +- include/gcc/x86_64/ck_pr.h | 6 +++--- regressions/ck_hs/validate/serial.c | 6 +++--- regressions/ck_ht/validate/serial.c | 2 +- src/Makefile.in | 5 ++--- src/ck_hs.c | 32 +++++++++++++++++------------ src/ck_ht_hash.h | 10 ++++----- src/ck_rhs.c | 27 ++++++++++++++---------- 8 files changed, 50 insertions(+), 40 deletions(-) diff --git a/configure b/configure index 57da1bb..9cb1560 100755 --- a/configure +++ b/configure @@ -599,7 +599,7 @@ elif test "$COMPILER" = "gcc" || test "$COMPILER" = "clang" || test "$COMPILER" INSTALL_LIBS="install-lib" fi - CFLAGS="-D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_DEFAULT_SOURCE -std=gnu99 -pedantic -Wall -W -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wdisabled-optimization -fstrict-aliasing -O2 -pipe -Wno-parentheses $CFLAGS" + CFLAGS="-D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_DEFAULT_SOURCE -std=gnu99 -pedantic -Wall -W -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wcast-align -Wcast-qual -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wdisabled-optimization -fstrict-aliasing -O2 -pipe -Wno-parentheses $CFLAGS" PTHREAD_CFLAGS="-pthread" if test "$COMPILER" = "mingw64"; then ENVIRONMENT=64 diff --git a/include/gcc/x86_64/ck_pr.h b/include/gcc/x86_64/ck_pr.h index 4d57e80..22ba76a 100644 --- a/include/gcc/x86_64/ck_pr.h +++ b/include/gcc/x86_64/ck_pr.h @@ -131,9 +131,9 @@ CK_PR_FAS_S(8, uint8_t, "xchgb") { \ T r; \ __asm__ __volatile__(I " %1, %0" \ - : "=q" (r) \ - : "m" (*(C *)target) \ - : "memory"); \ + : "=q" (r) \ + : "m" (*(const C *)target) \ + : "memory"); \ return (r); \ } diff --git a/regressions/ck_hs/validate/serial.c b/regressions/ck_hs/validate/serial.c index d6f6c0a..a16fc82 100644 --- a/regressions/ck_hs/validate/serial.c +++ b/regressions/ck_hs/validate/serial.c @@ -150,7 +150,7 @@ run_test(unsigned int is, unsigned int ad) if (i & 1) { if (ck_hs_put_unique(&hs[j], h, test[i]) == false) ck_error("ERROR [%zu]: Failed to insert unique (%s)\n", j, test[i]); - } else if (ck_hs_apply(&hs[j], h, test[i], test_unique, (char *)test[i]) == false) { + } else if (ck_hs_apply(&hs[j], h, test[i], test_unique, (void *)(uintptr_t)test[i]) == false) { ck_error("ERROR: Failed to apply for insertion.\n"); } @@ -161,7 +161,7 @@ run_test(unsigned int is, unsigned int ad) ck_error("ERROR: Failed to remove apply.\n"); } - if (ck_hs_apply(&hs[j], h, test[i], test_negative, (char *)test[i]) == false) + if (ck_hs_apply(&hs[j], h, test[i], test_negative, (char *)(uintptr_t)test[i]) == false) ck_error("ERROR: Failed to apply.\n"); break; @@ -272,7 +272,7 @@ run_test(unsigned int is, unsigned int ad) } /* Attempt in-place mutation. */ - if (ck_hs_apply(&hs[j], h, test[i], test_ip, (void *)test[i]) == false) + if (ck_hs_apply(&hs[j], h, test[i], test_ip, (void *)(uintptr_t)test[i]) == false) ck_error("ERROR [%u]: Failed to apply: %s != %s\n", is, (char *)r, test[i]); d = ck_hs_get(&hs[j], h, test[i]) != NULL; diff --git a/regressions/ck_ht/validate/serial.c b/regressions/ck_ht/validate/serial.c index e8a6f6c..3e85a61 100644 --- a/regressions/ck_ht/validate/serial.c +++ b/regressions/ck_ht/validate/serial.c @@ -83,7 +83,7 @@ main(void) mode |= CK_HT_WORKLOAD_DELETE; #endif - if (ck_ht_init(&ht, mode, NULL, &my_allocator, 16, 6602834) == false) { + if (ck_ht_init(&ht, mode, NULL, &my_allocator, 2, 6602834) == false) { perror("ck_ht_init"); exit(EXIT_FAILURE); } diff --git a/src/Makefile.in b/src/Makefile.in index 367b25e..0d84e76 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -29,7 +29,7 @@ libck.a: $(OBJECTS) ck_array.o: $(INCLUDE_DIR)/ck_array.h $(SDIR)/ck_array.c $(CC) $(CFLAGS) -c -o $(TARGET_DIR)/ck_array.o $(SDIR)/ck_array.c -ck_epoch.o: $(INCLUDE_DIR)/ck_epoch.h $(SDIR)/ck_epoch.c +ck_epoch.o: $(INCLUDE_DIR)/ck_epoch.h $(SDIR)/ck_epoch.c $(INCLUDE_DIR)/ck_stack.h $(CC) $(CFLAGS) -c -o $(TARGET_DIR)/ck_epoch.o $(SDIR)/ck_epoch.c ck_hs.o: $(INCLUDE_DIR)/ck_hs.h $(SDIR)/ck_hs.c @@ -41,7 +41,7 @@ ck_rhs.o: $(INCLUDE_DIR)/ck_rhs.h $(SDIR)/ck_rhs.c ck_ht.o: $(INCLUDE_DIR)/ck_ht.h $(SDIR)/ck_ht.c $(CC) $(CFLAGS) -c -o $(TARGET_DIR)/ck_ht.o $(SDIR)/ck_ht.c -ck_hp.o: $(SDIR)/ck_hp.c +ck_hp.o: $(SDIR)/ck_hp.c $(INCLUDE_DIR)/ck_hp.h $(INCLUDE_DIR)/ck_stack.h $(CC) $(CFLAGS) -c -o $(TARGET_DIR)/ck_hp.o $(SDIR)/ck_hp.c ck_barrier_centralized.o: $(SDIR)/ck_barrier_centralized.c @@ -62,4 +62,3 @@ ck_barrier_mcs.o: $(SDIR)/ck_barrier_mcs.c clean: rm -rf $(TARGET_DIR)/*.dSYM $(TARGET_DIR)/*~ $(TARGET_DIR)/*.o \ $(OBJECTS) $(TARGET_DIR)/libck.a $(TARGET_DIR)/libck.so - diff --git a/src/ck_hs.c b/src/ck_hs.c index 5808876..09191c7 100644 --- a/src/ck_hs.c +++ b/src/ck_hs.c @@ -498,24 +498,26 @@ leave: return cursor; } -static inline void * +static inline const void * ck_hs_marshal(unsigned int mode, const void *key, unsigned long h) { - void *insert; - #ifdef CK_HS_PP + const void *insert; + if (mode & CK_HS_MODE_OBJECT) { - insert = (void *)((uintptr_t)CK_HS_VMA(key) | ((h >> 25) << CK_MD_VMA_BITS)); + insert = (void *)((uintptr_t)CK_HS_VMA(key) | + ((h >> 25) << CK_MD_VMA_BITS)); } else { - insert = (void *)key; + insert = key; } + + return insert; #else (void)mode; (void)h; - insert = (void *)key; -#endif - return insert; + return key; +#endif } bool @@ -570,7 +572,7 @@ ck_hs_gc(struct ck_hs *hs, unsigned long cycles, unsigned long seed) ck_hs_map_bound_get(map, h), CK_HS_PROBE); if (first != NULL) { - void *insert = ck_hs_marshal(hs->mode, entry, h); + const void *insert = ck_hs_marshal(hs->mode, entry, h); ck_pr_store_ptr(first, insert); ck_pr_inc_uint(&map->generation[h & CK_HS_G_MASK]); @@ -614,7 +616,8 @@ ck_hs_fas(struct ck_hs *hs, const void *key, void **previous) { - void **slot, **first, *object, *insert; + const void *insert; + void **slot, **first, *object; unsigned long n_probes; struct ck_hs_map *map = hs->map; @@ -660,7 +663,8 @@ ck_hs_apply(struct ck_hs *hs, ck_hs_apply_fn_t *fn, void *cl) { - void **slot, **first, *object, *insert, *delta; + const void *insert; + void **slot, **first, *object, *delta; unsigned long n_probes; struct ck_hs_map *map; @@ -731,7 +735,8 @@ ck_hs_set(struct ck_hs *hs, const void *key, void **previous) { - void **slot, **first, *object, *insert; + const void *insert; + void **slot, **first, *object; unsigned long n_probes; struct ck_hs_map *map; @@ -788,7 +793,8 @@ ck_hs_put_internal(struct ck_hs *hs, const void *key, enum ck_hs_probe_behavior behavior) { - void **slot, **first, *object, *insert; + const void *insert; + void **slot, **first, *object; unsigned long n_probes; struct ck_hs_map *map; diff --git a/src/ck_ht_hash.h b/src/ck_ht_hash.h index 075c2c1..5f0f604 100644 --- a/src/ck_ht_hash.h +++ b/src/ck_ht_hash.h @@ -122,7 +122,7 @@ static inline void MurmurHash3_x86_32 ( const void * key, int len, //---------- // body - const uint32_t * blocks = (const uint32_t *)(void *)(data + nblocks*4); + const uint32_t * blocks = (const uint32_t *)(const void *)(data + nblocks*4); for(i = -nblocks; i; i++) { @@ -179,7 +179,7 @@ static inline uint64_t MurmurHash64A ( const void * key, int len, uint64_t seed if (!((uintptr_t)data & 0x7)) k = *data++; else { - memcpy(&k, (void *)data, sizeof(k)); + memcpy(&k, data, sizeof(k)); data++; } @@ -248,9 +248,9 @@ static inline uint64_t MurmurHash64B ( const void * key, int len, uint64_t seed switch(len) { - case 3: h2 ^= ((unsigned char*)data)[2] << 16; - case 2: h2 ^= ((unsigned char*)data)[1] << 8; - case 1: h2 ^= ((unsigned char*)data)[0]; + case 3: h2 ^= ((const unsigned char*)data)[2] << 16; + case 2: h2 ^= ((const unsigned char*)data)[1] << 8; + case 1: h2 ^= ((const unsigned char*)data)[0]; h2 *= m; }; diff --git a/src/ck_rhs.c b/src/ck_rhs.c index 657ee20..966f575 100644 --- a/src/ck_rhs.c +++ b/src/ck_rhs.c @@ -782,24 +782,25 @@ leave: return offset; } -static inline void * +static inline const void * ck_rhs_marshal(unsigned int mode, const void *key, unsigned long h) { - void *insert; - #ifdef CK_RHS_PP + const void *insert; + if (mode & CK_RHS_MODE_OBJECT) { insert = (void *)((uintptr_t)CK_RHS_VMA(key) | ((h >> 25) << CK_MD_VMA_BITS)); } else { - insert = (void *)key; + insert = key; } + + return insert; #else (void)mode; (void)h; - insert = (void *)key; -#endif - return insert; + return key; +#endif } bool @@ -1047,7 +1048,8 @@ ck_rhs_fas(struct ck_rhs *hs, void **previous) { long slot, first; - void *object, *insert; + void *object; + const void *insert; unsigned long n_probes; struct ck_rhs_map *map = hs->map; struct ck_rhs_entry_desc *desc, *desc2; @@ -1108,7 +1110,8 @@ ck_rhs_apply(struct ck_rhs *hs, ck_rhs_apply_fn_t *fn, void *cl) { - void *object, *insert, *delta = false; + const void *insert; + void *object, *delta = false; unsigned long n_probes; long slot, first; struct ck_rhs_map *map; @@ -1211,7 +1214,8 @@ ck_rhs_set(struct ck_rhs *hs, void **previous) { long slot, first; - void *object, *insert; + void *object; + const void *insert; unsigned long n_probes; struct ck_rhs_map *map; @@ -1290,7 +1294,8 @@ ck_rhs_put_internal(struct ck_rhs *hs, enum ck_rhs_probe_behavior behavior) { long slot, first; - void *object, *insert; + void *object; + const void *insert; unsigned long n_probes; struct ck_rhs_map *map;