Integrated: 8289046: Undefined Behaviour in x86 class Assembler
Andrew Haley
aph at openjdk.org
Mon Aug 1 09:02:13 UTC 2022
On Thu, 23 Jun 2022 14:52:54 GMT, Andrew Haley <aph at openjdk.org> wrote:
> All instances of type Register exhibit UB in the form of wild pointer (including null pointer) dereferences. This isn't very hard to fix: we should make Registers pointers to something rather than aliases of small integers.
>
> Here's an example of what was happening:
>
> ` rax->encoding();`
>
> Where rax is defined as `(Register *)0`.
>
> This patch things so that rax is now defined as a pointer to the start of a static array of RegisterImpl.
>
>
> typedef const RegisterImpl* Register;
> extern RegisterImpl all_Registers[RegisterImpl::number_of_declared_registers + 1] ;
> inline constexpr Register RegisterImpl::first() { return all_Registers + 1; };
> inline constexpr Register as_Register(int encoding) { return RegisterImpl::first() + encoding; }
> constexpr Register rax = as_register(0);
This pull request has now been integrated.
Changeset: 86ef7b20
Author: Andrew Haley <aph at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/86ef7b20eb45899a91cf9ee83f723336c9477694
Stats: 114 lines in 7 files changed: 65 ins; 9 del; 40 mod
8289046: Undefined Behaviour in x86 class Assembler
Reviewed-by: shade, kvn
-------------
PR: https://git.openjdk.org/jdk/pull/9261
More information about the hotspot-compiler-dev
mailing list