RFR: 8324833: Signed integer overflows in ABS [v5]

Dean Long dlong at openjdk.org
Fri Feb 23 03:14:54 UTC 2024


On Fri, 2 Feb 2024 09:44:00 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

>> src/hotspot/share/jvmci/jvmciCompilerToVM.cpp line 1054:
>> 
>>> 1052:     int64_t off_low = (int64_t)target_addr - ((int64_t)CodeCache::low_bound() + sizeof(int));
>>> 1053:     int64_t off_high = (int64_t)target_addr - ((int64_t)CodeCache::high_bound() + sizeof(int));
>>> 1054:     return MAX2(ABS(off_low), ABS(off_high));
>> 
>> Wouldn't this trigger a warning with -Wsign-conversion enabled?
>
> Maybe? I added `checked_cast` in this place in new commit.

checked_cast isn't really helping here.  It doesn't work when the input is the same size as the output.  We need a better way to check for bad input or bad outputs.  I suggested before doing those checks in the abs/ABS implementation, but we could also have something like u2i() (or u2s?) for unsigned to signed conversions instead of checked_cast.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17617#discussion_r1500172936


More information about the graal-dev mailing list