未验证 提交 a19585dd 编写于 作者: Z Zoltan Varga 提交者: GitHub

[mono][arm64] Fixed passing/receiving hfa structures with fixed buffers. (#90502)

Fixes https://github.com/dotnet/runtime/issues/90423.
上级 09af1614
......@@ -28,6 +28,7 @@
#include <mono/utils/mono-hwcap.h>
#include <mono/metadata/abi-details.h>
#include <mono/metadata/tokentype.h>
#include <mono/metadata/marshal-shared.h>
#include "llvm-intrinsics-types.h"
#include "interp/interp.h"
......@@ -1483,7 +1484,7 @@ is_hfa (MonoType *t, int *out_nfields, int *out_esize, int *field_offsets)
gpointer iter;
MonoClassField *field;
MonoType *ftype, *prev_ftype = NULL;
int i, nfields = 0;
int nfields = 0;
klass = mono_class_from_mono_type_internal (t);
iter = NULL;
......@@ -1497,8 +1498,22 @@ is_hfa (MonoType *t, int *out_nfields, int *out_esize, int *field_offsets)
int nested_nfields, nested_esize;
int nested_field_offsets [16];
if (!is_hfa (ftype, &nested_nfields, &nested_esize, nested_field_offsets))
return FALSE;
MonoType *fixed_etype;
int fixed_len;
if (mono_marshal_shared_get_fixed_buffer_attr (field, &fixed_etype, &fixed_len)) {
if (fixed_etype->type != MONO_TYPE_R4 && fixed_etype->type != MONO_TYPE_R8)
return FALSE;
if (fixed_len > 16)
return FALSE;
nested_nfields = fixed_len;
nested_esize = fixed_etype->type == MONO_TYPE_R4 ? 4 : 8;
for (int i = 0; i < nested_nfields; ++i)
nested_field_offsets [i] = i * nested_esize;
} else {
if (!is_hfa (ftype, &nested_nfields, &nested_esize, nested_field_offsets))
return FALSE;
}
if (nested_esize == 4)
ftype = m_class_get_byval_arg (mono_defaults.single_class);
else
......@@ -1506,7 +1521,7 @@ is_hfa (MonoType *t, int *out_nfields, int *out_esize, int *field_offsets)
if (prev_ftype && prev_ftype->type != ftype->type)
return FALSE;
prev_ftype = ftype;
for (i = 0; i < nested_nfields; ++i) {
for (int i = 0; i < nested_nfields; ++i) {
if (nfields + i < 4)
field_offsets [nfields + i] = field->offset - MONO_ABI_SIZEOF (MonoObject) + nested_field_offsets [i];
}
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
using Xunit;
using System;
public class Runtime_90423
{
public static BaconClass.BaconStruct foo;
[Fact]
public unsafe static int EntryPoint()
{
foo = BaconClass.GetBacon();
for (int i = 0; i < BaconClass.BaconStruct.RESOLUTION; i++)
{
if (Math.Abs(foo.table[i] - BaconClass.foo.table[i]) > float.Epsilon)
return 101;
}
return 100;
}
public class BaconClass
{
public unsafe struct BaconStruct
{
public float length;
public const int RESOLUTION = 5;
public fixed float table[RESOLUTION];
}
public static BaconStruct foo;
public unsafe static BaconStruct GetBacon()
{
const int resolution = BaconStruct.RESOLUTION;
var length = 1;
BaconStruct lut = new BaconStruct()
{
length = length
};
foo = new BaconStruct(){length = length};
float[] bacon = new float[] { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f };
for (int x = 0; x < BaconStruct.RESOLUTION; x++)
{
lut.table[x] = bacon[x];
foo.table[x] = bacon[x];
}
return lut;
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册