From: Ivan Maidanski Date: Thu, 4 Aug 2011 18:49:51 +0000 (+0400) Subject: Fix compiler extra warnings. X-Git-Tag: libatomic_ops-7_3alpha2~118 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9b32643f567b6d65fff59c60fae7346374ef7970;p=libatomic_ops Fix compiler extra warnings. * src/atomic_ops_stack.c (AO_stack_pop_explicit_aux_acquire): Remove non-negative-value test for an unsigned value. * src/atomic_ops_stack.h (AO_STACK_INITIALIZER): Add {} to match type definition. * tests/test_atomic.c (acqrel_thr): Fix code indentation. * tests/test_atomic.c (test_and_set_thr): Print thread Id in case of error. * tests/test_malloc.c (cons): Declare "i" local variable as unsigned (as it is compared to another unsigned value). * tests/test_malloc.c (check_list): Test upper bound as well, abort with the appropriate message in case of mismatch. * tests/test_malloc.c (run_one_test): Return "arg" parameter (to suppress "unused parameter" compiler warning). --- diff --git a/TODO b/TODO index e56567a..d7d2aa9 100644 --- a/TODO +++ b/TODO @@ -9,5 +9,3 @@ Review build process: make invokes configure unnecessarily. Don't create autom4te.cache (or, at least, remove it on make distclean). Add equivalent of __sync_val_compare_and_swap. Add tests. - -Review and fix warnings displayed with -Wall -Wextra. diff --git a/src/atomic_ops_stack.c b/src/atomic_ops_stack.c index 2f03145..7cbee9a 100644 --- a/src/atomic_ops_stack.c +++ b/src/atomic_ops_stack.c @@ -184,7 +184,7 @@ AO_stack_pop_explicit_aux_acquire(volatile AO_t *list, AO_stack_aux * a) AO_pause(++j); } } - assert(i >= 0 && i < AO_BL_SIZE); + assert(i < AO_BL_SIZE); assert(a -> AO_stack_bl[i] == first); /* First is on the auxiliary black list. It may be removed by */ /* another thread before we get to it, but a new insertion of x */ diff --git a/src/atomic_ops_stack.h b/src/atomic_ops_stack.h index 6c8b5bb..0945ddb 100644 --- a/src/atomic_ops_stack.h +++ b/src/atomic_ops_stack.h @@ -119,7 +119,7 @@ typedef struct AO__stack { AO_stack_aux AO_aux; } AO_stack_t; -#define AO_STACK_INITIALIZER {0} +#define AO_STACK_INITIALIZER {0,{{0}}} AO_INLINE void AO_stack_init(AO_stack_t *list) { diff --git a/tests/test_atomic.c b/tests/test_atomic.c index 7d59393..01a9714 100644 --- a/tests/test_atomic.c +++ b/tests/test_atomic.c @@ -76,36 +76,36 @@ void * acqrel_thr(void *id) if (me & 1) { AO_t my_counter1; - if (me != 1) - fprintf(stderr, "acqrel test: too many threads\n"); - my_counter1 = AO_load(&counter1); - AO_store(&counter1, my_counter1 + 1); - AO_store_release_write(&counter2, my_counter1 + 1); + if (me != 1) + fprintf(stderr, "acqrel test: too many threads\n"); + my_counter1 = AO_load(&counter1); + AO_store(&counter1, my_counter1 + 1); + AO_store_release_write(&counter2, my_counter1 + 1); } else { - AO_t my_counter1a, my_counter2a; - AO_t my_counter1b, my_counter2b; - - my_counter2a = AO_load_acquire_read(&counter2); - my_counter1a = AO_load(&counter1); - /* Redo this, to make sure that the second load of counter1 */ - /* is not viewed as a common subexpression. */ - my_counter2b = AO_load_acquire_read(&counter2); - my_counter1b = AO_load(&counter1); - if (my_counter1a < my_counter2a) - { - fprintf(stderr, "Saw release store out of order: %lu < %lu\n", - (unsigned long)my_counter1a, (unsigned long)my_counter2a); - abort(); - } - if (my_counter1b < my_counter2b) - { - fprintf(stderr, - "Saw release store out of order (bad CSE?): %lu < %lu\n", - (unsigned long)my_counter1b, (unsigned long)my_counter2b); - abort(); - } + AO_t my_counter1a, my_counter2a; + AO_t my_counter1b, my_counter2b; + + my_counter2a = AO_load_acquire_read(&counter2); + my_counter1a = AO_load(&counter1); + /* Redo this, to make sure that the second load of counter1 */ + /* is not viewed as a common subexpression. */ + my_counter2b = AO_load_acquire_read(&counter2); + my_counter1b = AO_load(&counter1); + if (my_counter1a < my_counter2a) + { + fprintf(stderr, "Saw release store out of order: %lu < %lu\n", + (unsigned long)my_counter1a, (unsigned long)my_counter2a); + abort(); + } + if (my_counter1b < my_counter2b) + { + fprintf(stderr, + "Saw release store out of order (bad CSE?): %lu < %lu\n", + (unsigned long)my_counter1b, (unsigned long)my_counter2b); + abort(); + } } return 0; @@ -135,8 +135,8 @@ void * test_and_set_thr(void * id) ++locked_counter; if (locked_counter != 1) { - fprintf(stderr, "Test and set failure 1, counter = %ld\n", - locked_counter); + fprintf(stderr, "Test and set failure 1, counter = %ld, id = %d\n", + locked_counter, (int)(AO_PTRDIFF_T)id); abort(); } locked_counter *= 2; @@ -145,8 +145,8 @@ void * test_and_set_thr(void * id) locked_counter -= 4; if (locked_counter != 1) { - fprintf(stderr, "Test and set failure 2, counter = %ld\n", - locked_counter); + fprintf(stderr, "Test and set failure 2, counter = %ld, id = %d\n", + locked_counter, (int)(AO_PTRDIFF_T)id); abort(); } --locked_counter; diff --git a/tests/test_malloc.c b/tests/test_malloc.c index 4bf6e6c..6341942 100644 --- a/tests/test_malloc.c +++ b/tests/test_malloc.c @@ -63,7 +63,7 @@ ln *cons(int d, ln *tail) size_t my_extra = extra; ln *result; int * extras; - int i; + unsigned i; if (my_extra > 100) extra = my_extra = 0; @@ -101,7 +101,7 @@ void check_list(ln *l, int m, int n) ln *p; int i; - for (p = l, i = m; p != 0; p = p -> next, ++i) + for (p = l, i = m; p != 0 && i <= n; p = p -> next, ++i) { if (i != p -> data) { @@ -109,6 +109,16 @@ void check_list(ln *l, int m, int n) abort(); } } + if (i <= n) + { + fprintf(stderr, "Number not found: %d\n", i); + abort(); + } + if (p != 0) + { + fprintf(stderr, "Found unexpected number: %d\n", i); + abort(); + } } /* Create a list of integers from m to n */ @@ -180,7 +190,7 @@ void * run_one_test(void * arg) { x = reverse(x, 0); } check_list(x, 1, LIST_LENGTH); - return 0; + return arg; /* use arg to suppress compiler warning */ } int main(int argc, char **argv) {