From 4501e3903cbb04138bb85b4910993c1b660e3f36 Mon Sep 17 00:00:00 2001 From: SingleAccretion <62474226+SingleAccretion@users.noreply.github.com> Date: Wed, 15 Jun 2022 03:41:43 +0300 Subject: [PATCH] Do not change `gtRetClsHnd` in `impNormStructVal` (#70699) * Do not change "gtRetClsHdl" in "impNormStructVal" Doing so leads breaking the proper ABI handling for the call. * Add a test --- src/coreclr/jit/importer.cpp | 14 ++------- .../Directed/StructABI/TypeMismatchedArgs.cs | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 0a774bdfcc7b70..64be5105099f8f 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -1723,21 +1723,14 @@ GenTree* Compiler::impNormStructVal(GenTree* structVal, genTreeOps oper = structVal->OperGet(); switch (oper) { - // GT_RETURN and GT_MKREFANY don't capture the handle. - case GT_RETURN: - break; + // GT_MKREFANY is supported directly by args morphing. case GT_MKREFANY: alreadyNormalized = true; break; case GT_CALL: - structVal->AsCall()->gtRetClsHnd = structHnd; - makeTemp = true; - break; - case GT_RET_EXPR: - structVal->AsRetExpr()->gtRetClsHnd = structHnd; - makeTemp = true; + makeTemp = true; break; case GT_FIELD: @@ -1758,7 +1751,6 @@ GenTree* Compiler::impNormStructVal(GenTree* structVal, case GT_OBJ: case GT_BLK: - case GT_ASG: // These should already have the appropriate type. assert(structVal->gtType == structType); alreadyNormalized = true; @@ -1771,10 +1763,8 @@ GenTree* Compiler::impNormStructVal(GenTree* structVal, break; case GT_CNS_VEC: - { assert(varTypeIsSIMD(structVal) && (structVal->gtType == structType)); break; - } #ifdef FEATURE_SIMD case GT_SIMD: diff --git a/src/tests/JIT/Directed/StructABI/TypeMismatchedArgs.cs b/src/tests/JIT/Directed/StructABI/TypeMismatchedArgs.cs index eb31300a4c320f..c450040daace48 100644 --- a/src/tests/JIT/Directed/StructABI/TypeMismatchedArgs.cs +++ b/src/tests/JIT/Directed/StructABI/TypeMismatchedArgs.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Numerics; +using System.Runtime.Intrinsics; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -10,6 +12,7 @@ public unsafe class TypeMismatchedArgs private static readonly HfaUnion s_hfaDblFlt = new HfaUnion { DblHfa = { FirstDblValue = 1.0, SecondDblValue = 2.0 } }; private static readonly HfaDblLngUnion s_dblLngHfa = new HfaDblLngUnion { DblLng = { FirstLngValue = 10, SecondLngValue = 20 } }; private static readonly FourDblLngUnion s_fourDblLngHfa = new FourDblLngUnion { Lngs = { LongOne = 30 } }; + private static readonly Vtor128Union s_vtor128 = new Vtor128Union { Vtor4 = new Vector4(4, 3, 2, 1) }; public static int Main() { @@ -33,6 +36,11 @@ public static int Main() return 104; } + if (ProblemWithVectorCallArg()) + { + return 105; + } + return 100; } @@ -70,6 +78,20 @@ private static bool ProblemWithSplitStructHfaMismatch(FourDoublesHfaStruct fourD return result != s_fourDblLngHfa.Lngs.LongOne; } + [MethodImpl(MethodImplOptions.NoInlining)] + private static bool ProblemWithVectorCallArg() + { + var result = CallForVector4(GetVector128().AsVector4()); + + return result != s_vtor128.Vtor4.X; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static float CallForVector4(Vector4 value) => value.X; + + [MethodImpl(MethodImplOptions.NoInlining)] + private static Vector128 GetVector128() => s_vtor128.Vtor128; + [MethodImpl(MethodImplOptions.NoInlining)] private static double CallForHfaDblStruct(HfaDblStruct value) => value.FirstDblValue; @@ -77,6 +99,15 @@ private static bool ProblemWithSplitStructHfaMismatch(FourDoublesHfaStruct fourD private static long CallForSplitStructWithFourLongs(int arg0, int arg1, StructWithFourLongs splitArg) => splitArg.LongOne; } +[StructLayout(LayoutKind.Explicit)] +struct Vtor128Union +{ + [FieldOffset(0)] + public Vector4 Vtor4; + [FieldOffset(0)] + public Vector128 Vtor128; +} + [StructLayout(LayoutKind.Explicit)] struct HfaDblLngUnion {