[mono] Disable gsharing when Unsafe.ReadUnaligned/WriteUnaligned () is used with...
authorZoltan Varga <vargaz@gmail.com>
Tue, 25 Jul 2023 21:26:43 +0000 (17:26 -0400)
committerGitHub <noreply@github.com>
Tue, 25 Jul 2023 21:26:43 +0000 (16:26 -0500)
commit0be3889fd32ecc43c3111bddecd765b6da1ad993
treecd6c8c7b40a7a1ee6faa6bb9463b211b478896c3
parent2300d0e70cdb78f9f7a3236894b6c87691216d30
[mono] Disable gsharing when Unsafe.ReadUnaligned/WriteUnaligned () is used with generic structures. (#89417)

Fixes https://github.com/dotnet/runtime/issues/89398.

For a method like
```
    static void Write<T>(ref byte b, T value) => Unsafe.WriteUnaligned<T>(ref b, value);
```
And an instance ```Write<GStruct<string>>```, generic sharing will create a ```Write<T_INST>```
instance where T_INST is constrained to GStruct<T_REF>. The JIT currently calls
```mini_get_underlying_type ()``` in many places which transform T_INST into GStruct<T_REF>.
This causes problems at runtime in the generic sharing code, which expects to find T_INST.
I.e. ```inflate_info ()``` can inflate ```T_INST``` to ```GStruct<string>```, but it can't inflate
```GStruct<T_REF>``` to ```GStruct<string>```.

As a workaround, disable gsharing in (some) of these cases.
src/mono/mono/mini/intrinsics.c