RFR: 8309685: Fix -Wconversion warnings in assembler and register code [v2]
Gui Cao
gcao at openjdk.org
Wed Jun 14 11:49:57 UTC 2023
On Wed, 14 Jun 2023 00:21:14 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:
>> This change widens some int arguments, narrows some int returns and adds some casts and checked_casts where the compiler was doing the implicit conversion. I maintained existing types - ie if the parameter was short, I used a cast to short. Also int is used in places that might be better served as unsigned int but I didn't fix that because it would be too large and risky. The registers encode an offset in an array, so it's safe to checked_cast<> to get their encoding. This fix is limited so that the types changed and casts added are intentional.
>> See CR for counts of -Wconversion warnings this resolves.
>> Tested with tier1-7, also tested with tier1 on all Oracle supported platforms.
>
> Coleen Phillimore has updated the pull request incrementally with one additional commit since the last revision:
>
> Improve checked_cast to tolerate sign extension so it can be used in assembler.hpp emit code.
Hi, may I ask if it's OK to add fix for RISC-V please? I checked and found that this port has similar issue.
```diff
diff --git a/src/hotspot/cpu/riscv/register_riscv.hpp b/src/hotspot/cpu/riscv/register_riscv.hpp
index 7b547335cd0..7d25875fedd 100644
--- a/src/hotspot/cpu/riscv/register_riscv.hpp
+++ b/src/hotspot/cpu/riscv/register_riscv.hpp
@@ -70,7 +70,7 @@ class Register {
public:
// accessors
- constexpr int raw_encoding() const { return this - first(); }
+ constexpr int raw_encoding() const { return checked_cast<int>(this - first()); }
constexpr int encoding() const { assert(is_valid(), "invalid register"); return raw_encoding(); }
constexpr bool is_valid() const { return 0 <= raw_encoding() && raw_encoding() < number_of_registers; }
@@ -187,7 +187,7 @@ class FloatRegister {
public:
// accessors
- constexpr int raw_encoding() const { return this - first(); }
+ constexpr int raw_encoding() const { return checked_cast<int>(this - first()); }
constexpr int encoding() const { assert(is_valid(), "invalid register"); return raw_encoding(); }
constexpr bool is_valid() const { return 0 <= raw_encoding() && raw_encoding() < number_of_registers; }
@@ -297,7 +297,7 @@ class VectorRegister {
public:
// accessors
- constexpr int raw_encoding() const { return this - first(); }
+ constexpr int raw_encoding() const { return checked_cast<int>(this - first()); }
constexpr int encoding() const { assert(is_valid(), "invalid register"); return raw_encoding(); }
constexpr bool is_valid() const { return 0 <= raw_encoding() && raw_encoding() < number_of_registers; }
-------------
PR Comment: https://git.openjdk.org/jdk/pull/14396#issuecomment-1591037816
More information about the hotspot-dev
mailing list