Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 2 Aug 2020 21:43:56 +0200
From: Petr Skocik <pskocik@...il.com>
To: Alexander Monakov <amonakov@...ras.ru>, musl@...ts.openwall.com
Subject: Re: Musl's FD_{SET,ISSET,CLR} macros from sys/select.h trigger
 gcc's -Wsign-conversion warnings

Yeah, you're right. The signedness does make the codegen worse because of the signed division (glibc still does the (int) cast of sizeof).

A direct size_t cast of (d) could potentially do some type-unsafe things (like convert a pointer), but I guess you could
do something like `(size_t)(int){d}` or use an inline function to silence the warnings without worsening the codegen and without worsening the typesafety of the macro.

I don't super care about this in Musl as it's quite easily silencable with an `unsigned` cast from the user-side but Cygwin had the macros written in such a way that the `unsigned` cast on the descriptor argument wouldn't help, so I reported it there and also sent one bug report to Musl while I was at it, but I will the -Wsystem-headers problem to gcc.

Thanks for the suggestion, Alexander Monakov.

Regards,
Petr Skocik


On 8/2/20 8:53 PM, Alexander Monakov wrote:
> On Sun, 2 Aug 2020, Petr Skocik wrote:
>
>>     #define FD_SET(d, s)   ((s)->fds_bits[(d)/(8*(int)sizeof(long))] |=
>> (1UL<<((d)%(8*(int)sizeof(long)))))
>>     #define FD_CLR(d, s)   ((s)->fds_bits[(d)/(8*(int)sizeof(long))] &=
>> ~(1UL<<((d)%(8*(int)sizeof(long)))))
>>     #define FD_ISSET(d, s) !!((s)->fds_bits[(d)/(8*(int)sizeof(long))] &
>> (1UL<<((d)%(8*(int)sizeof(long)))))
>>
>> You might want to add them.
> (casting 'd' to size_t would have been more appropriate, as there's no need
> to perform signed division and modulus here)
>
> This is one of the cases where the warning should have been suppressed by
> GCC unless -Wsystem-headers is also given: the problem appears when expanding
> a macro defined in a system header, so the user can't cleanly avoid it.
>
> Would you care to open an issue in the GCC Bugzilla about it?
>
> Alexander
>
>
>

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.