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

David Holmes dholmes at openjdk.org
Mon Aug 14 02:37:28 UTC 2023


On Fri, 11 Aug 2023 12:17:18 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:

>> src/hotspot/os/linux/os_linux.cpp line 2991:
>> 
>>> 2989: #endif
>>> 2990: 
>>> 2991:   return (retval == -1) ? checked_cast<int>(retval) : cpu;
>> 
>> If retval is -1 you can just return -1. And if cpu is uint and the function returns int then surely we need a cast on cpu here?
>
> I don't have -Wsign-conversion on.  I'm not that much of a masochist.  Fixed return value though.

So `-Wconversion` is mainly of use in detecting overflow/overflow when dealing with variables of different size, yet unsigned to signed conversion can result in the exact the same problem, but that only gets detected by a separate `-Wsign-conversion` flag? <blegghh>

>> src/hotspot/os/linux/waitBarrier_linux.cpp line 54:
>> 
>>> 52:   assert(_futex_barrier != 0, "Should be armed/non-zero.");
>>> 53:   _futex_barrier = 0;
>>> 54:   intptr_t s = futex(&_futex_barrier,
>> 
>> futex returns an int
>
> src/hotspot/os/linux/waitBarrier_linux.cpp:41:17: warning: conversion from 'long int' to 'int' may change value [-Wconversion]
>    41 |   return syscall(SYS_futex, addr, futex_op, op_arg, nullptr, nullptr, 0);
>       |          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I was again referring to:

SYNOPSIS
       #include <linux/futex.h>
       #include <sys/time.h>

       int futex(int *uaddr, int op, int val, const struct timespec *timeout,
                 int *uaddr2, int val3);

But why `intptr_t` here, but `int64_t` in the earlier syscall case?

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

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


More information about the hotspot-dev mailing list