RFR: JDK-8255544: Create a checked cast

Andrew Haley aph at openjdk.java.net
Wed Oct 28 16:06:46 UTC 2020


On Wed, 28 Oct 2020 15:50:52 GMT, Andrew Haley <aph at openjdk.org> wrote:

> In many places we've added C-style casts to silence compiler warnings, for example when truncating a size_t to an int when we know the size_t is a small struct. Such casts are inherently risky, because they effectively disable useful compiler warnings. We should add a form of cast that checks at runtime that a truncation does not overflow.

One thing I should have said: the need for this was triggered by a recent patch to silence many warnings emitted the MSVC AArch64 compiler. It would have been possible to put the checks into the AArch64 back end, but I think we need a centralized way to do it.

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

PR: https://git.openjdk.java.net/jdk/pull/904


More information about the hotspot-dev mailing list