未验证 提交 f8a1a6c1 编写于 作者: A Aaron Robinson 提交者: GitHub

Fix up `InlineArray` tests (#90192)

* Convert invalid C# to IL project
上级 6f40dbb8
......@@ -10,14 +10,6 @@
unsafe class Validate
{
[InlineArray(1)]
[StructLayout(LayoutKind.Explicit)]
private struct Explicit
{
[FieldOffset(0)]
public Guid Guid;
}
[Fact]
public static void Explicit_Fails()
{
......@@ -30,12 +22,6 @@ public static void Explicit_Fails()
});
}
[InlineArray(0)]
private struct ZeroLength
{
public int field;
}
[Fact]
public static void ZeroLength_Fails()
{
......@@ -74,12 +60,6 @@ public static void TooLarge_Fails()
});
}
[InlineArray(-1)]
private struct NegativeLength
{
public long field;
}
[Fact]
public static void NegativeLength_Fails()
{
......@@ -96,13 +76,6 @@ public static void NegativeLength_Fails()
});
}
[InlineArray(123)]
private struct NoFields
{
public static int x;
}
[Fact]
public static void NoFields_Fails()
{
......@@ -115,13 +88,6 @@ public static void NoFields_Fails()
});
}
[InlineArray(1)]
private struct TwoFields
{
int a;
int b;
}
[Fact]
public static void TwoFields_Fails()
{
......
......@@ -2,13 +2,12 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputType>Exe</OutputType>
<!-- Issue: https://github.com/dotnet/runtime/issues/88861 -->
<DisableProjectBuild>true</DisableProjectBuild>
</PropertyGroup>
<ItemGroup>
<Compile Include="InlineArrayInvalid.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="InvalidCSharp.ilproj" />
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
</Project>
......@@ -22,18 +22,6 @@ struct MyArray<T> : IEnumerable<T>
public int Length => LengthConst;
[UnscopedRef]
public ref T this[int i]
{
get
{
if ((uint)i >= (uint)Length)
throw new IndexOutOfRangeException(nameof(i));
return ref Unsafe.Add(ref _element, i);
}
}
[UnscopedRef]
public Span<T> AsSpan() => MemoryMarshal.CreateSpan<T>(ref _element, Length);
......@@ -107,9 +95,6 @@ struct Arr1
{
public const int Length = 42;
public E e;
[UnscopedRef]
public ref E this[int i] => ref Unsafe.Add(ref e, i);
}
static object s;
......@@ -168,10 +153,7 @@ public static void UseOnStack()
struct ObjShortArr
{
public const int Length = 100;
public (object, short) element;
[UnscopedRef]
public ref (object o, short s) this[int i] => ref Unsafe.Add(ref element, i);
public (object o, short s) element;
[MethodImpl(MethodImplOptions.NoInlining)]
public static ObjShortArr CreateArray(int recCount) {
......@@ -219,7 +201,7 @@ public static void MixObjectsAndValuetypes()
public (object, short) element;
[UnscopedRef]
public ref (object o, short s) this[int i] => ref Unsafe.Add(ref element, i);
public ref (object o, short s) At(int i) => ref Unsafe.Add(ref element, i);
}
[MethodImpl(MethodImplOptions.NoInlining)]
......@@ -229,8 +211,8 @@ static void TestRefLikeOuterMethodArg(ObjShortArrRef arr)
for (short i = 0; i < ObjShortArrRef.Length; i++)
{
Assert.Equal(i * 2, arr[i].o);
Assert.Equal(i * 2 + 1, arr[i].s);
Assert.Equal(i * 2, arr.At(i).o);
Assert.Equal(i * 2 + 1, arr.At(i).s);
}
}
......@@ -242,48 +224,28 @@ public static void RefLikeOuter()
var arr = new ObjShortArrRef();
for (short i = 0; i < ObjShortArrRef.Length; i++)
{
arr[i].o = i;
arr[i].s = (short)(i + 1);
arr.At(i).o = i;
arr.At(i).s = (short)(i + 1);
}
GC.Collect(2, GCCollectionMode.Forced, true, true);
for (short i = 0; i < ObjShortArrRef.Length; i++)
{
Assert.Equal(i, arr[i].o);
Assert.Equal(i + 1, arr[i].s);
Assert.Equal(i, arr.At(i).o);
Assert.Equal(i + 1, arr.At(i).s);
}
for (short i = 0; i < ObjShortArrRef.Length; i++)
{
arr[i].o = i * 2;
arr[i].s = (short)(i * 2 + 1);
arr.At(i).o = i * 2;
arr.At(i).s = (short)(i * 2 + 1);
}
TestRefLikeOuterMethodArg(arr);
}
// ====================== RefLikeInner ========================================================
[InlineArray(LengthConst)]
ref struct SpanArr
{
private const int LengthConst = 100;
public Span<object> element;
public Span<object>* this[int i]
{
get
{
fixed (Span<object>* p = &element)
{
return p + i;
}
}
}
public int Length => LengthConst;
}
[MethodImpl(MethodImplOptions.NoInlining)]
static void TestRefLikeInnerMethodArg(SpanArr arr)
{
......@@ -291,8 +253,8 @@ static void TestRefLikeInnerMethodArg(SpanArr arr)
for (int i = 1; i < arr.Length; i++)
{
Assert.Equal(i, arr[i]->Length);
Assert.Equal(i, (*arr[i])[0]);
Assert.Equal(i, arr.At(i)->Length);
Assert.Equal(i, (*arr.At(i))[0]);
}
}
......@@ -306,7 +268,7 @@ public static void RefLikeInner()
{
var objArr = new object[i];
objArr[0] = i;
*arr[i] = objArr;
*arr.At(i) = objArr;
}
TestRefLikeInnerMethodArg(arr);
......
......@@ -2,13 +2,12 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputType>Exe</OutputType>
<!-- Issue: https://github.com/dotnet/runtime/issues/88861 -->
<DisableProjectBuild>true</DisableProjectBuild>
</PropertyGroup>
<ItemGroup>
<Compile Include="InlineArrayValid.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="InvalidCSharp.ilproj" />
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
</Project>
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
.assembly extern System.Runtime { .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) }
.assembly InvalidCSharp { }
.class public explicit ansi sealed beforefieldinit Explicit
extends [System.Runtime]System.ValueType
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.InlineArrayAttribute::.ctor(int32) = (
01 00 01 00 00 00 00 00
)
.field [0] public valuetype [System.Runtime]System.Guid Guid
}
.class public sequential ansi sealed beforefieldinit ZeroLength
extends [System.Runtime]System.ValueType
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.InlineArrayAttribute::.ctor(int32) = (
01 00 00 00 00 00 00 00
)
.field public int32 'field'
}
.class public sequential ansi sealed beforefieldinit TooLarge
extends [System.Runtime]System.ValueType
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.InlineArrayAttribute::.ctor(int32) = (
01 00 00 00 00 20 00 00
)
.field public int64 'field'
}
.class public sequential ansi sealed beforefieldinit NegativeLength
extends [System.Runtime]System.ValueType
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.InlineArrayAttribute::.ctor(int32) = (
01 00 ff ff ff ff 00 00
)
.field public int64 'field'
}
.class public sequential ansi sealed beforefieldinit NoFields
extends [System.Runtime]System.ValueType
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.InlineArrayAttribute::.ctor(int32) = (
01 00 7b 00 00 00 00 00
)
.pack 0
.size 1
.field public static int32 x
}
.class public sequential ansi sealed beforefieldinit TwoFields
extends [System.Runtime]System.ValueType
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.InlineArrayAttribute::.ctor(int32) = (
01 00 01 00 00 00 00 00
)
.field private int32 a
.field private int32 b
}
.class public sequential ansi sealed beforefieldinit SpanArr
extends [System.Runtime]System.ValueType
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.IsByRefLikeAttribute::.ctor() = (
01 00 00 00
)
.custom instance void [System.Runtime]System.Runtime.CompilerServices.InlineArrayAttribute::.ctor(int32) = (
01 00 64 00 00 00 00 00
)
.field private static literal int32 LengthConst = int32(100)
.field public valuetype [System.Runtime]System.Span`1<object> element
.method public hidebysig
instance valuetype [System.Runtime]System.Span`1<object>* At (
int32
) cil managed
{
.locals init (
[0] valuetype [System.Runtime]System.Span`1<object>& pinned
)
ldarg.0
ldflda valuetype [System.Runtime]System.Span`1<object> SpanArr::element
stloc.0
ldloc.0
conv.u
ldarg.1
conv.i
sizeof valuetype [System.Runtime]System.Span`1<object>
mul
add
ret
}
.method public hidebysig specialname
instance int32 get_Length () cil managed
{
ldc.i4.s 100
ret
}
.property instance int32 Length()
{
.get instance int32 SpanArr::get_Length()
}
}
<Project Sdk="Microsoft.NET.Sdk.IL">
<PropertyGroup>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>
<Compile Include="InvalidCSharp.il" />
</ItemGroup>
</Project>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册