warnings when compiling libev with clang

Benjamin Kaduk kaduk at MIT.EDU
Mon Nov 4 22:25:55 CET 2013


Hi all,

I was doing some warning cleanup on a project that ships a bundled version 
of libev (krb5), and figured that I should note the changes I made in my 
working copy here, to see if they held interest for the libev maintainers.

There were four (classes of) things I noticed:

(1) There is a call to fd_change in ev_io_start, that has the expression 
'w->events & EV__IOFDSET | EV_ANFD_REIFY'.  The operator precedence rules 
have this as equivalent to '(w->events & EV__IOFDSET) | EV_ANFD_REIFY', 
but "most of the time", the programmer wants the other ordering, which 
would be OR-ing together a set of flags to make a mask.  Having looked at 
the history of that code, I believe that the current precedence order is 
the intended behavior, but it would probably be worth adding the 
parentheses to make that clear.

(2) There are several places where the EMPTY2 macro is passed as the 
fourth argument to array_needsize(); this results in the local variable 
ocur_ (declared within the macro array_needsize()) is assigned a valud but 
never used.  Clang produces a warning for this unused variable.  The 
smallest code change to fix the warnings seems to be to define EMPTY2 as 
((void)(a), (void)(b)).  This does mean that the arguments of EMPTY2 are 
now evaluated when they were not previously; I did not attempt to verify 
that this would not have a functional effect on the code.

(3) The file-local function fd_rearm_all() is defined but never used.  It 
can safely be removed to eliminate this compiler warning.

(4) ev.c has a lot of statements of the form:
assert(("libev: informational string here", [some condition]));
This use of the comma operator produces a warning from clang, as the 
string is seen as an expression with unused result.  Changing the comma 
operator to logical AND produces the same resulting behavior without the 
warning.

I'll put links to the commits that I used to implement these fixes below.

Thanks,

Ben Kaduk



(1) 
https://github.com/kaduk/krb5/commit/3fd3b4ebe1f7e267c1eb80e0b2d1d7c199efefdd 
(the 'feed_count' variable does not appear in the current version of ev.c)
(2) 
https://github.com/kaduk/krb5/commit/a7ac62a3cb1086cf9a25d5651625ba7f3cdc32b3
(3) 
https://github.com/kaduk/krb5/commit/fece7525b3d305e3e10df74f885bd4168aeba4cd
(4) 
https://github.com/kaduk/krb5/commit/7376a74299d4783dc1868ebb54f128ae4f72a87b



More information about the libev mailing list