[exim-dev] Clang warnings for RC2

Góra strony
Delete this message
Reply to this message
Autor: Richard Clayton
Data:  
Dla: exim-dev
Temat: [exim-dev] Clang warnings for RC2

Once upon a time Exim used to compile without any warnings... I always
felt that was a mark of its quality.

However, these days I compile it using clang and it gets quite excited.

I don't think it's actually spotting any bugs, but it would be far
better to recast a few things to avoid the specious warnings so that
when something matters, you can see the wood for the trees.

First (and I'll split my remarks into multiple emails for ease of use)
there's a whole pile of warnings about return codes relating to the
(lack of) use of return code in valgrind.h.

The current documentation

        http://valgrind.org/docs/manual/mc-manual.html


now says of these macros

        They return -1, when run on Valgrind and 0 otherwise.


I believe, because this topic has come up before, that these return
codes were not documented in the past (but it was true anyway).

Hence or otherwise the way to deal with these warnings:

cc -DCOMPILE_UTILITY store.c
store.c:180:3: warning: expression result unused [-Wunused-value]
  VALGRIND_MAKE_MEM_NOACCESS(next_yield[store_pool],
yield_length[store_pool]);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~
./memcheck.h:110:37: note: expanded from macro
'VALGRIND_MAKE_MEM_NOACCESS'
    VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */,      \
                                    ^
./valgrind.h:217:8: note: expanded from macro 'VALGRIND_DO_CLIENT_REQUES
T_EXPR'
      (_zzq_default)
       ^
store.c:205:1: warning: expression result unused [-Wunused-value]
VALGRIND_MAKE_MEM_UNDEFINED(store_last_get[store_pool], size);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./memcheck.h:117:37: note: expanded from macro
'VALGRIND_MAKE_MEM_UNDEFINED'
    VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */,      \
                                    ^
./valgrind.h:217:8: note: expanded from macro 'VALGRIND_DO_CLIENT_REQUES
T_EXPR'
      (_zzq_default)
       ^
store.c:300:1: warning: expression result unused [-Wunused-value]
VALGRIND_MAKE_MEM_UNDEFINED(ptr + oldsize, inc);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./memcheck.h:117:37: note: expanded from macro
'VALGRIND_MAKE_MEM_UNDEFINED'
    VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */,      \
                                    ^
./valgrind.h:217:8: note: expanded from macro 'VALGRIND_DO_CLIENT_REQUES
T_EXPR'
      (_zzq_default)
       ^
store.c:373:3: warning: expression result unused [-Wunused-value]
  VALGRIND_MAKE_MEM_NOACCESS((char *)b + ALIGNED_SIZEOF_STOREBLOCK, b-

>length - ALIGNED_SIZEOF_STOREBLOCK);

  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./memcheck.h:110:37: note: expanded from macro
'VALGRIND_MAKE_MEM_NOACCESS'
    VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */,      \
                                    ^
./valgrind.h:217:8: note: expanded from macro 'VALGRIND_DO_CLIENT_REQUES
T_EXPR'
      (_zzq_default)
       ^
store.c:359:1: warning: expression result unused [-Wunused-value]
VALGRIND_MAKE_MEM_NOACCESS(ptr, newlength);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./memcheck.h:110:37: note: expanded from macro
'VALGRIND_MAKE_MEM_NOACCESS'
    VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */,      \
                                    ^
./valgrind.h:217:8: note: expanded from macro 'VALGRIND_DO_CLIENT_REQUES
T_EXPR'
      (_zzq_default)
       ^
5 warnings generated.


is to cast the results to null for the 5 calls -- like this perhaps:

# diff store.c store.was
180c180
< (void)VALGRIND_MAKE_MEM_NOACCESS(next_yield[store_pool],
yield_length[store_pool]);
---
> VALGRIND_MAKE_MEM_NOACCESS(next_yield[store_pool],

yield_length[store_pool]);
205c205
< (void)VALGRIND_MAKE_MEM_UNDEFINED(store_last_get[store_pool], size);
---
> VALGRIND_MAKE_MEM_UNDEFINED(store_last_get[store_pool], size);

300c300
< (void)VALGRIND_MAKE_MEM_UNDEFINED(ptr + oldsize, inc);
---
> VALGRIND_MAKE_MEM_UNDEFINED(ptr + oldsize, inc);

359c359
< (void)VALGRIND_MAKE_MEM_NOACCESS(ptr, newlength);
---
> VALGRIND_MAKE_MEM_NOACCESS(ptr, newlength);

373c373
< (void)VALGRIND_MAKE_MEM_NOACCESS((char *)b +
ALIGNED_SIZEOF_STOREBLOCK, b->length - ALIGNED_SIZEOF_STOREBLOCK);
---
> VALGRIND_MAKE_MEM_NOACCESS((char *)b + ALIGNED_SIZEOF_STOREBLOCK, b-
>length - ALIGNED_SIZEOF_STOREBLOCK);


and that's 5 or the 37 warnings dealt with :-)

-- 
richard                                                   Richard Clayton


Those who would give up essential Liberty, to purchase a little temporary
Safety, deserve neither Liberty nor Safety. Benjamin Franklin 11 Nov 1755