JDK-8316960 : Fix -Wsign-conversion warnings in log2i and related
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2023-09-26
  • Updated: 2023-09-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 22
22Unresolved
Description
In `powerOfTwo.hpp`, there a few log2 related functions returning `int`. However, some of them always return only unsigned number.

For example, `log2i_exact` essentially calls `count_trailing_zeros`, which returns `unsigned`.
Comments
clang and gcc have diff behavior regarding -Wconversion. In gcc, one needs `-Wsign-conversion` additionally to get what clang does with `-Wconversion` alone. "Warnings about conversions between signed and unsigned integers are disabled by default in C++ unless -Wsign-conversion is explicitly enabled." from https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html If you switch to clang or turns on the additional warning, you will see the uint-to-int warning sites inside that file.
26-09-2023

I don't see these errors when running with -Wconversion. I only get this: src/hotspot/share/gc/g1/g1RemSet.cpp:263:38: warning: conversion from 'int' to 'uint8_t' {aka 'unsigned char'} may change value [-Wconversion] 263 | _log_scan_chunks_per_region(log2i(_scan_chunks_per_region)), | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
26-09-2023