RFR: 8344026: Ubsan: prevent potential integer overflow in c1_LIRGenerator_<arch>.cpp file [v8]

Andrew Haley aph at openjdk.org
Wed Dec 4 10:14:42 UTC 2024


On Wed, 4 Dec 2024 10:03:38 GMT, Amit Kumar <amitkumar at openjdk.org> wrote:

>>> What happens if this underflows? Is this not undefined behaviour? Could we use `java_add`?
>> 
>> Unsigned subtraction is never undefined. "wrap around" behavior is used. Using `java_add` / `java_subtract` sounds like a good idea.
>
>>And do you have some sort of tests for this, to make sure we check with all possible c values?
> 
> No, as of now I only ran tier1 test cases with c1 compiler. Nothing else.

All that `java_add` does is cast to unsigned and then add. That's equivalent to what we're doing here, but explicit casts make the arithmetic clearer, IMO.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22144#discussion_r1869127617


More information about the hotspot-compiler-dev mailing list