Integrated: 8341178: TypeRawPtr::add_offset may be "miscompiled" due to UB

Kim Barrett kbarrett at openjdk.org
Fri Oct 11 21:15:27 UTC 2024


On Thu, 3 Oct 2024 12:50:55 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

> Please review this change to TypeRawPtr::add_offset to prevent a compiler from
> inferring things based on prior pointer arithmetic not invoking UB.  As noted in
> the bug report, clang is actually doing this.
> 
> To accomplish this, changed to integral arithmetic.  Also added over/underflow
> checks.
> 
> Also made a couple of minor touchups.  Replaced an implicit conversion to bool
> with an explicit compare to nullptr (per style guide).  Removed a no longer
> needed dummy return after a (now) noreturn function.
> 
> Testing: mach5 tier1-7
> That testing was with calls to "fatal" for the over/underflow cases and the
> sum==0 case.  There were no hits.  I'm not sure how to construct a test that
> would hit those.

This pull request has now been integrated.

Changeset: 0a57fe1d
Author:    Kim Barrett <kbarrett at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/0a57fe1df6f3431cfb2d5d868597c61ef6af3806
Stats:     15 lines in 1 file changed: 8 ins; 2 del; 5 mod

8341178: TypeRawPtr::add_offset may be "miscompiled" due to UB

Reviewed-by: dlong, kvn

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

PR: https://git.openjdk.org/jdk/pull/21324


More information about the hotspot-compiler-dev mailing list