From 70eb1ab0f000aed1ccd3f705933b8d9986cdcd04 Mon Sep 17 00:00:00 2001 From: petris Date: Sun, 11 Jun 2023 01:54:13 +0200 Subject: [PATCH 1/8] Intrinsify Array GetArrayDataReference for SZ arrays --- .../InteropServices/MemoryMarshal.CoreCLR.cs | 1 + src/coreclr/jit/importercalls.cpp | 28 ++++-- .../MemoryMarshal.NativeAot.cs | 1 + src/coreclr/vm/jitinterface.cpp | 4 +- .../MemoryMarshalGetArrayDataReference.cs | 92 +++++++++++++++++++ 5 files changed, 117 insertions(+), 9 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/MemoryMarshal.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/MemoryMarshal.CoreCLR.cs index f4a87e587c55e..fe0fed4a9ecb2 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/MemoryMarshal.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/MemoryMarshal.CoreCLR.cs @@ -33,6 +33,7 @@ public static ref T GetArrayDataReference(T[] array) => /// This technique does not perform array variance checks. The caller must manually perform any array variance checks /// if the caller wishes to write to the returned reference. /// + [Intrinsic] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref byte GetArrayDataReference(Array array) { diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index 43ad185b63e8a..6205a4c14161b 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -2759,14 +2759,28 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, case NI_System_Runtime_InteropService_MemoryMarshal_GetArrayDataReference: { assert(sig->numArgs == 1); - assert(sig->sigInst.methInstCount == 1); - GenTree* array = impPopStack().val; - CORINFO_CLASS_HANDLE elemHnd = sig->sigInst.methInst[0]; - CorInfoType jitType = info.compCompHnd->asCorInfoType(elemHnd); - var_types elemType = JITtype2varType(jitType); + GenTree* array = impPopStack().val + CORINFO_CLASS_HANDLE elemHnd; + CorInfoType jitType; + bool notNull = false; + if (sig->sigInst.methInstCount == 1) + { + elemHnd = sig->sigInst.methInst[0]; + jitType = info.compCompHnd->asCorInfoType(elemHnd); + } + else + { + bool isExact; + CORINFO_CLASS_HANDLE arrayHnd = gtGetClassHandle(array, &isExact, ¬Null); + if (!info.compCompHnd->isSDArray(arrayHnd)) + { + return nullptr; + } + jitType = info.compCompHnd->getChildType(arrayHnd, &elemHnd); + } - if (fgAddrCouldBeNull(array)) + if (!notNull && fgAddrCouldBeNull(array)) { GenTree* arrayClone; array = impCloneExpr(array, &arrayClone, CHECK_SPILL_ALL, @@ -2777,7 +2791,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, } GenTree* index = gtNewIconNode(0, TYP_I_IMPL); - GenTreeIndexAddr* indexAddr = gtNewArrayIndexAddr(array, index, elemType, elemHnd); + GenTreeIndexAddr* indexAddr = gtNewArrayIndexAddr(array, index, JITtype2varType(jitType), elemHnd); indexAddr->gtFlags &= ~GTF_INX_RNGCHK; indexAddr->gtFlags |= GTF_INX_ADDR_NONNULL; retNode = indexAddr; diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/MemoryMarshal.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/MemoryMarshal.NativeAot.cs index 19e4a2a663619..616936963ce4a 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/MemoryMarshal.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/MemoryMarshal.NativeAot.cs @@ -34,6 +34,7 @@ public static ref T GetArrayDataReference(T[] array) => /// This technique does not perform array variance checks. The caller must manually perform any array variance checks /// if the caller wishes to write to the returned reference. /// + [Intrinsic] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref byte GetArrayDataReference(Array array) { diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 15365a90216a8..4cd542a27afce 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -4674,8 +4674,8 @@ bool CEEInfo::satisfiesClassConstraints(CORINFO_CLASS_HANDLE cls) } /*********************************************************************/ -// Check if this is a single dimensional array type -bool CEEInfo::isSDArray(CORINFO_CLASS_HANDLE cls) +// Check if this is a single dimensional, zero based array type +bool CEEInfo::isSDArray(CORINFO_CLASS_HANDLE cls) { CONTRACTL { THROWS; diff --git a/src/tests/JIT/Intrinsics/MemoryMarshalGetArrayDataReference.cs b/src/tests/JIT/Intrinsics/MemoryMarshalGetArrayDataReference.cs index c59af9750a057..03ff082a86116 100644 --- a/src/tests/JIT/Intrinsics/MemoryMarshalGetArrayDataReference.cs +++ b/src/tests/JIT/Intrinsics/MemoryMarshalGetArrayDataReference.cs @@ -114,6 +114,98 @@ unsafe static int Main(string[] args) ThrowsNRE(() => ref ptrByte(NoInline(null))); ThrowsNRE(() => ref ptrString(NoInline(null))); + // use no inline methods to avoid indirect call inlining in the future + [MethodImpl(MethodImplOptions.NoInlining)] + static delegate* GetMdPtr() => &MemoryMarshal.GetArrayDataReference; + delegate* ptrMd = GetMdPtr(); + + IsTrue(Unsafe.AreSame(ref MemoryMarshal.GetArrayDataReference((Array)testByteArray), ref testByteArray[0])); + IsTrue(Unsafe.AreSame(ref ptrMd(testByteArray), ref testByteArray[0])); + + IsTrue(Unsafe.AreSame(ref MemoryMarshal.GetArrayDataReference((Array)NoInline(testByteArray)), ref testByteArray[0])); + IsTrue(Unsafe.AreSame(ref MemoryMarshal.GetArrayDataReference(NoInline(testByteArray)), ref testByteArray[0])); + IsTrue(Unsafe.AreSame(ref ptrMd(NoInline(testByteArray)), ref testByteArray[0])); + + IsTrue(Unsafe.AreSame(ref MemoryMarshal.GetArrayDataReference((Array)testStringArray), ref testStringArray[0])); + IsTrue(Unsafe.AreSame(ref ptrMd(testStringArray), ref testStringArray[0])); + + IsTrue(Unsafe.AreSame(ref MemoryMarshal.GetArrayDataReference((Array)NoInline(testStringArray)), ref testStringArray[0])); + IsTrue(Unsafe.AreSame(ref MemoryMarshal.GetArrayDataReference(NoInline(testStringArray)), ref testStringArray[0])); + IsTrue(Unsafe.AreSame(ref ptrMd(NoInline(testStringArray)), ref testStringArray[0])); + + byte[,] testByteMdArray = new byte[1, 1]; + IsTrue(Unsafe.AreSame(ref MemoryMarshal.GetArrayDataReference(testByteMdArray), ref testByteMdArray[0, 0])); + IsTrue(Unsafe.AreSame(ref ptrMd(testByteMdArray), ref testByteMdArray[0, 0])); + + IsTrue(Unsafe.AreSame(ref MemoryMarshal.GetArrayDataReference(NoInline(testByteMdArray)), ref testByteMdArray[0, 0])); + IsTrue(Unsafe.AreSame(ref ptrMd(NoInline(testByteMdArray)), ref testByteMdArray[0, 0])); + + string[,] testStringMdArray = new string[1, 1]; + IsTrue(Unsafe.AreSame(ref Unsafe.As(refMemoryMarshal.GetArrayDataReference(testStringMdArray)), ref testStringMdArray[0, 0])); + IsTrue(Unsafe.AreSame(ref Unsafe.As(refptrMd(testStringMdArray)), ref testStringMdArray[0, 0])); + + IsTrue(Unsafe.AreSame(ref Unsafe.As(refMemoryMarshal.GetArrayDataReference(NoInline(testStringMdArray))), ref testStringMdArray[0, 0])); + IsTrue(Unsafe.AreSame(ref Unsafe.As(ref ptrMd(NoInline(testStringMdArray))), ref testStringMdArray[0, 0])); + + Array nonZeroArray = Array.CreateInstance(typeof(string), new [] { 1 }, new [] { -1 }); + string test = "test"; + nonZeroArray.SetValue(test, -1); + IsTrue(ReferenceEquals(Unsafe.As(ref MemoryMarshal.GetArrayDataReference(nonZeroArray)), test)); + IsTrue(ReferenceEquals(Unsafe.As(ref ptrMd(nonZeroArray)), test)); + + IsTrue(ReferenceEquals(Unsafe.As(ref MemoryMarshal.GetArrayDataReference(NoInline(nonZeroArray))), test)); + IsTrue(ReferenceEquals(Unsafe.As(ref ptrMd(NoInline(nonZeroArray))), test)); + + IsFalse(Unsafe.IsNullRef(ref MemoryMarshal.GetArrayDataReference((Array)new byte[0]))); + IsFalse(Unsafe.IsNullRef(ref MemoryMarshal.GetArrayDataReference((Array)new string[0]))); + IsFalse(Unsafe.IsNullRef(ref MemoryMarshal.GetArrayDataReference(new byte[0, 0]))); + IsFalse(Unsafe.IsNullRef(ref MemoryMarshal.GetArrayDataReference(new string[0, 0]))); + + IsFalse(Unsafe.IsNullRef(ref ptrMd(new byte[0]))); + IsFalse(Unsafe.IsNullRef(ref ptrMd(new string[0]))); + IsFalse(Unsafe.IsNullRef(ref ptrMd(new byte[0, 0]))); + IsFalse(Unsafe.IsNullRef(ref ptrMd(new string[0, 0]))); + + IsFalse(Unsafe.IsNullRef(ref MemoryMarshal.GetArrayDataReference((Array)NoInline(new byte[0])))); + IsFalse(Unsafe.IsNullRef(ref MemoryMarshal.GetArrayDataReference((Array)NoInline(new string[0])))); + IsFalse(Unsafe.IsNullRef(ref MemoryMarshal.GetArrayDataReference(NoInline(new byte[0, 0])))); + IsFalse(Unsafe.IsNullRef(ref MemoryMarshal.GetArrayDataReference(NoInline(new string[0, 0])))); + IsFalse(Unsafe.IsNullRef(ref MemoryMarshal.GetArrayDataReference(NoInline(new byte[0])))); + IsFalse(Unsafe.IsNullRef(ref MemoryMarshal.GetArrayDataReference(NoInline(new string[0])))); + IsFalse(Unsafe.IsNullRef(ref MemoryMarshal.GetArrayDataReference(NoInline(new byte[0, 0])))); + IsFalse(Unsafe.IsNullRef(ref MemoryMarshal.GetArrayDataReference(NoInline(new string[0, 0])))); + + IsFalse(Unsafe.IsNullRef(ref ptrMd(NoInline(new byte[0])))); + IsFalse(Unsafe.IsNullRef(ref ptrMd(NoInline(new string[0])))); + IsFalse(Unsafe.IsNullRef(ref ptrMd(NoInline(new byte[0, 0])))); + IsFalse(Unsafe.IsNullRef(ref ptrMd(NoInline(new string[0, 0])))); + IsFalse(Unsafe.IsNullRef(ref ptrMd(NoInline(new byte[0])))); + IsFalse(Unsafe.IsNullRef(ref ptrMd(NoInline(new string[0])))); + IsFalse(Unsafe.IsNullRef(ref ptrMd(NoInline(new byte[0, 0])))); + IsFalse(Unsafe.IsNullRef(ref ptrMd(NoInline(new string[0, 0])))); + + ThrowsNRE(() => { _ = ref MemoryMarshal.GetArrayDataReference((Array)null); }); + ThrowsNRE(() => { _ = ref ptrMd(null); }); + + ThrowsNRE(() => { _ = ref MemoryMarshal.GetArrayDataReference((Array)NoInline(null)); }); + ThrowsNRE(() => { _ = ref MemoryMarshal.GetArrayDataReference((Array)NoInline(null)); }); + ThrowsNRE(() => { _ = ref MemoryMarshal.GetArrayDataReference(NoInline(null)); }); + + ThrowsNRE(() => { _ = ref ptrMd(NoInline(null)); }); + ThrowsNRE(() => { _ = ref ptrMd(NoInline(null)); }); + ThrowsNRE(() => { _ = ref ptrMd(NoInline(null)); }); + + ThrowsNRE(() => ref MemoryMarshal.GetArrayDataReference((Array)null)); + ThrowsNRE(() => ref ptrMd(null)); + + ThrowsNRE(() => ref MemoryMarshal.GetArrayDataReference((Array)NoInline(null))); + ThrowsNRE(() => ref MemoryMarshal.GetArrayDataReference((Array)NoInline(null))); + ThrowsNRE(() => ref MemoryMarshal.GetArrayDataReference(NoInline(null))); + + ThrowsNRE(() => ref ptrMd(NoInline(null))); + ThrowsNRE(() => ref ptrMd(NoInline(null))); + ThrowsNRE(() => ref ptrMd(NoInline(null))); + // from https://github.com/dotnet/runtime/issues/58312#issuecomment-993491291 [MethodImpl(MethodImplOptions.NoInlining)] static int Problem1(StructWithByte[] a) From 2822c52d6e021f0ba79facd96e3a71aed731f146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Petryka?= <35800402+MichalPetryka@users.noreply.github.com> Date: Sun, 11 Jun 2023 02:10:59 +0200 Subject: [PATCH 2/8] Update importercalls.cpp --- src/coreclr/jit/importercalls.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index 6205a4c14161b..04d251f693355 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -2760,7 +2760,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, { assert(sig->numArgs == 1); - GenTree* array = impPopStack().val + GenTree* array = impPopStack().val; CORINFO_CLASS_HANDLE elemHnd; CorInfoType jitType; bool notNull = false; From a808e1551d444476257e2c14b6b3bb22f3ca61a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Petryka?= <35800402+MichalPetryka@users.noreply.github.com> Date: Sun, 11 Jun 2023 02:57:09 +0200 Subject: [PATCH 3/8] Update importercalls.cpp --- src/coreclr/jit/importercalls.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index 04d251f693355..3a6761cab9dff 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -2773,7 +2773,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, { bool isExact; CORINFO_CLASS_HANDLE arrayHnd = gtGetClassHandle(array, &isExact, ¬Null); - if (!info.compCompHnd->isSDArray(arrayHnd)) + if ((arrayHnd == NO_CLASS_HANDLE) || !info.compCompHnd->isSDArray(arrayHnd)) { return nullptr; } From a4a646a716a57018b67deb5a872f27511e33b27d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Petryka?= <35800402+MichalPetryka@users.noreply.github.com> Date: Sun, 11 Jun 2023 03:23:21 +0200 Subject: [PATCH 4/8] Update MemoryMarshalGetArrayDataReference.cs --- .../MemoryMarshalGetArrayDataReference.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/tests/JIT/Intrinsics/MemoryMarshalGetArrayDataReference.cs b/src/tests/JIT/Intrinsics/MemoryMarshalGetArrayDataReference.cs index 03ff082a86116..d0d66ee9d60cd 100644 --- a/src/tests/JIT/Intrinsics/MemoryMarshalGetArrayDataReference.cs +++ b/src/tests/JIT/Intrinsics/MemoryMarshalGetArrayDataReference.cs @@ -126,12 +126,12 @@ unsafe static int Main(string[] args) IsTrue(Unsafe.AreSame(ref MemoryMarshal.GetArrayDataReference(NoInline(testByteArray)), ref testByteArray[0])); IsTrue(Unsafe.AreSame(ref ptrMd(NoInline(testByteArray)), ref testByteArray[0])); - IsTrue(Unsafe.AreSame(ref MemoryMarshal.GetArrayDataReference((Array)testStringArray), ref testStringArray[0])); - IsTrue(Unsafe.AreSame(ref ptrMd(testStringArray), ref testStringArray[0])); + IsTrue(Unsafe.AreSame(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference((Array)testStringArray)), ref testStringArray[0])); + IsTrue(Unsafe.AreSame(ref Unsafe.As(ref ptrMd(testStringArray)), ref testStringArray[0])); - IsTrue(Unsafe.AreSame(ref MemoryMarshal.GetArrayDataReference((Array)NoInline(testStringArray)), ref testStringArray[0])); - IsTrue(Unsafe.AreSame(ref MemoryMarshal.GetArrayDataReference(NoInline(testStringArray)), ref testStringArray[0])); - IsTrue(Unsafe.AreSame(ref ptrMd(NoInline(testStringArray)), ref testStringArray[0])); + IsTrue(Unsafe.AreSame(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference((Array)NoInline(testStringArray))), ref testStringArray[0])); + IsTrue(Unsafe.AreSame(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(NoInline(testStringArray))), ref testStringArray[0])); + IsTrue(Unsafe.AreSame(ref Unsafe.As(ref ptrMd(NoInline(testStringArray))), ref testStringArray[0])); byte[,] testByteMdArray = new byte[1, 1]; IsTrue(Unsafe.AreSame(ref MemoryMarshal.GetArrayDataReference(testByteMdArray), ref testByteMdArray[0, 0])); @@ -141,10 +141,10 @@ unsafe static int Main(string[] args) IsTrue(Unsafe.AreSame(ref ptrMd(NoInline(testByteMdArray)), ref testByteMdArray[0, 0])); string[,] testStringMdArray = new string[1, 1]; - IsTrue(Unsafe.AreSame(ref Unsafe.As(refMemoryMarshal.GetArrayDataReference(testStringMdArray)), ref testStringMdArray[0, 0])); - IsTrue(Unsafe.AreSame(ref Unsafe.As(refptrMd(testStringMdArray)), ref testStringMdArray[0, 0])); + IsTrue(Unsafe.AreSame(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(testStringMdArray)), ref testStringMdArray[0, 0])); + IsTrue(Unsafe.AreSame(ref Unsafe.As(ref ptrMd(testStringMdArray)), ref testStringMdArray[0, 0])); - IsTrue(Unsafe.AreSame(ref Unsafe.As(refMemoryMarshal.GetArrayDataReference(NoInline(testStringMdArray))), ref testStringMdArray[0, 0])); + IsTrue(Unsafe.AreSame(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(NoInline(testStringMdArray))), ref testStringMdArray[0, 0])); IsTrue(Unsafe.AreSame(ref Unsafe.As(ref ptrMd(NoInline(testStringMdArray))), ref testStringMdArray[0, 0])); Array nonZeroArray = Array.CreateInstance(typeof(string), new [] { 1 }, new [] { -1 }); From dafed474312ece3869e08082e69f4aa2675d1c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Petryka?= <35800402+MichalPetryka@users.noreply.github.com> Date: Sun, 11 Jun 2023 15:51:37 +0200 Subject: [PATCH 5/8] Update importercalls.cpp --- src/coreclr/jit/importercalls.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index 3a6761cab9dff..413ab0e24268f 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -2760,10 +2760,10 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, { assert(sig->numArgs == 1); - GenTree* array = impPopStack().val; - CORINFO_CLASS_HANDLE elemHnd; - CorInfoType jitType; + GenTree* array = impPopStack().val; bool notNull = false; + CORINFO_CLASS_HANDLE elemHnd = NO_CLASS_HANDLE; + CorInfoType jitType; if (sig->sigInst.methInstCount == 1) { elemHnd = sig->sigInst.methInst[0]; @@ -2771,7 +2771,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, } else { - bool isExact; + bool isExact = false; CORINFO_CLASS_HANDLE arrayHnd = gtGetClassHandle(array, &isExact, ¬Null); if ((arrayHnd == NO_CLASS_HANDLE) || !info.compCompHnd->isSDArray(arrayHnd)) { From b71b13f98952c7a320c6f883191126b1047e463c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Petryka?= <35800402+MichalPetryka@users.noreply.github.com> Date: Sun, 11 Jun 2023 17:00:44 +0200 Subject: [PATCH 6/8] Update importercalls.cpp --- src/coreclr/jit/importercalls.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index 413ab0e24268f..ee138404d61be 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -2779,6 +2779,9 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, } jitType = info.compCompHnd->getChildType(arrayHnd, &elemHnd); } + + assert(jitType != CORINFO_TYPE_UNDEF); + assert((jitType != CORINFO_TYPE_VALUECLASS) || (elemHnd != NO_CLASS_HANDLE)); if (!notNull && fgAddrCouldBeNull(array)) { From 7b9fa851320bf7aa1a4aaed6b7a3bfd19f684be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Petryka?= <35800402+MichalPetryka@users.noreply.github.com> Date: Sun, 11 Jun 2023 19:08:28 +0200 Subject: [PATCH 7/8] Update importercalls.cpp --- src/coreclr/jit/importercalls.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index ee138404d61be..ec8402fa7b623 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -2760,7 +2760,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, { assert(sig->numArgs == 1); - GenTree* array = impPopStack().val; + GenTree* array = impStackTop().val; bool notNull = false; CORINFO_CLASS_HANDLE elemHnd = NO_CLASS_HANDLE; CorInfoType jitType; @@ -2780,6 +2780,8 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, jitType = info.compCompHnd->getChildType(arrayHnd, &elemHnd); } + array = impPopStack().val; + assert(jitType != CORINFO_TYPE_UNDEF); assert((jitType != CORINFO_TYPE_VALUECLASS) || (elemHnd != NO_CLASS_HANDLE)); From 1ab8de8aa98272116b28fa5b7b8ae797b553638b Mon Sep 17 00:00:00 2001 From: petris Date: Sun, 11 Jun 2023 19:46:34 +0200 Subject: [PATCH 8/8] Format code --- src/coreclr/jit/importercalls.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index ec8402fa7b623..00f827ff0fb01 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -2779,7 +2779,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, } jitType = info.compCompHnd->getChildType(arrayHnd, &elemHnd); } - + array = impPopStack().val; assert(jitType != CORINFO_TYPE_UNDEF);