RFR: 8314114: Fix -Wconversion warnings in os code, primarily linux [v2]

Dean Long dlong at openjdk.org
Mon Aug 14 19:49:26 UTC 2023


On Mon, 14 Aug 2023 02:10:31 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> The AIX code is a copy of the linux code.  I got a sign conversion warning on the linux code. 
>> 
>> src/hotspot/os/linux/attachListener_linux.cpp:275:14: warning: comparison of integer expressions of different signedness: 'ssize_t' {aka 'long int'} and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
>>   275 |     assert(n <= left, "buffer was too small, impossible!");
>>       |            ~~^~~~~~~
>
> This is an example of how the basic integer type system is broken. You define size variables as `size_t` but then get `ssize_t` back from functions like `read`, and then you get warnings if you combine them in particular ways. In this particular case I don't even understand the conversion warning as semantically a maximum `ssize_t` must be < the maximum `size_t` so where is the loss? It also seems to me that the strictly correct way to address this would be to ensure the `ssize_t` variable is not -1 and then cast it to `size_t`, rather than downcasting the `size_t` variable to `ssize_t`.

Isn't the compiler complaining because the comparison will be done as unsigned, and a negative value turns into a huge unsigned value?  To do a loss-less compare, both sides would need to be widened to a common signed type that can represent either side, like __int128_t.  There's probably an equivalent way to do it with 64-bit values, but I think it would involve more than one compare.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15229#discussion_r1293901494


More information about the hotspot-dev mailing list