Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Use correct cast_class for IntPtr[] #103841

Merged
merged 7 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/mono/mono/metadata/class-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1039,18 +1039,14 @@ class_composite_fixup_cast_class (MonoClass *klass, gboolean for_ptr)
case MONO_TYPE_U2:
klass->cast_class = mono_defaults.int16_class;
break;
case MONO_TYPE_U4:
#if TARGET_SIZEOF_VOID_P == 4
case MONO_TYPE_I:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MONO_TYPE_BOOLEAN -> byte_class normalization above looks suspect as well. I do not think regular CoreCLR does normalization like that anywhere.

Copy link
Member

@lambdageek lambdageek Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkotas I think the bool -> int8 fixup comes from when I misread I.8.7.2:

A location type T is compatible-with a location type U if and only if one of the following holds.

  1. T and U are not managed pointer types and T is compatible-with U according to the definition in §I.8.7.1.
  2. T and U are both managed pointer types and T is pointer-element-compatible-with U.
    A managed pointer type T is pointer-element-compatible-with a managed pointer type U if and
    only if T has verification type V and U has verification type W and V is identical to W.

The verification type of a bool is defined in I.8.7 as

  1. If the reduced type of T is:
    a. int8 or bool, then its verification type is int8.

The problem is I think I applied the verification type rules to unmanaged pointer types (ie bool*) rather than to managed pointer types (ie bool&)

case MONO_TYPE_U:
#endif
klass->cast_class = mono_defaults.int_class;
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
break;
case MONO_TYPE_U4:
klass->cast_class = mono_defaults.int32_class;
break;
case MONO_TYPE_U8:
#if TARGET_SIZEOF_VOID_P == 8
case MONO_TYPE_I:
case MONO_TYPE_U:
#endif
klass->cast_class = mono_defaults.int64_class;
break;
default:
Expand Down
20 changes: 20 additions & 0 deletions src/tests/Loader/classloader/Casting/Normalization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.InteropServices;

using Xunit;

public class NormalizationTests
{
[Fact]
public static void IntPtrArrayNormalization()
{
object x0 = new long[1];
object x1 = new ulong[1];

Assert.False(x0 is IntPtr[]);
Assert.False(x1 is IntPtr[]);
}
}
5 changes: 5 additions & 0 deletions src/tests/Loader/classloader/Casting/Normalization.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<Compile Include="Normalization.cs" />
</ItemGroup>
</Project>
Loading