From 096856d7ad54d28d05212fb320694624df24f89c Mon Sep 17 00:00:00 2001 From: Egor Chesakov Date: Fri, 3 Dec 2021 16:51:01 -0800 Subject: [PATCH 1/3] Add regression test for https://github.com/dotnet/runtime/issues/62249 --- .../JitBlue/Runtime_62249/Runtime_62249.cs | 39 +++++++++++++++++++ .../Runtime_62249/Runtime_62249.csproj | 9 +++++ 2 files changed, 48 insertions(+) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_62249/Runtime_62249.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_62249/Runtime_62249.csproj diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_62249/Runtime_62249.cs b/src/tests/JIT/Regression/JitBlue/Runtime_62249/Runtime_62249.cs new file mode 100644 index 00000000000000..2bdaf33de4dbfc --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_62249/Runtime_62249.cs @@ -0,0 +1,39 @@ +// 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.CompilerServices; + +class Runtime_62249 +{ + public struct CanBeReinterpretedAsDouble + { + public double _0; + } + + // Note that all VFP registers are occupied by d0-d7 arguments, hence the last argument is passed on the stack. + [MethodImpl(MethodImplOptions.NoInlining)] + public static int Callee(double d0, double d1, double d2, double d3, double d4, double d5, double d6, double d7, CanBeReinterpretedAsDouble onStack) + { + return onStack._0 == 62249 ? 100 : 0; + } + + public static int Caller(ref CanBeReinterpretedAsDouble byRef) + { + // Since the last parameter + // 1. Is passed by value + // 2. Has size of power of 2 + // 3. Has a single field + // morph transforms OBJ(struct, byRef) to IND(double, byRef). + // However, lower does not expect such transformation and asserts. + return Callee(0, 0, 0, 6, 2, 2, 4, 9, byRef); + } + + public static int Main(string[] args) + { + var val = new CanBeReinterpretedAsDouble(); + val._0 = 62249; + + return Caller(ref val); + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_62249/Runtime_62249.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_62249/Runtime_62249.csproj new file mode 100644 index 00000000000000..6946bed81bfd5b --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_62249/Runtime_62249.csproj @@ -0,0 +1,9 @@ + + + Exe + True + + + + + From a990e05040004a5a0d71e215960a5da11d3b278d Mon Sep 17 00:00:00 2001 From: Egor Chesakov Date: Fri, 3 Dec 2021 16:53:39 -0800 Subject: [PATCH 2/3] On Arm32 FEATURE_SIMD is not supported, hence varTypeIsSIMD() always returns false. Change the assert, so it checks that the argument type is TYP_DOUBLE in Lowering::NewPutArg() in src/coreclr/jit/lower.cpp --- src/coreclr/jit/lower.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index 1c9febeb131440..992f8b98a8faff 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -1257,7 +1257,12 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* inf } else if (!arg->OperIs(GT_FIELD_LIST)) { +#ifdef TARGET_ARM + assert((info->GetStackSlotsNumber() == 1) || + (arg->TypeGet() == TYP_DOUBLE) && (info->GetStackSlotsNumber() == 2)); +#else assert(varTypeIsSIMD(arg) || (info->GetStackSlotsNumber() == 1)); +#endif } } #endif // FEATURE_PUT_STRUCT_ARG_STK From d7ecdd420549b0f318bc7d16efcd5056d96c11b0 Mon Sep 17 00:00:00 2001 From: Egor Chesakov Date: Fri, 3 Dec 2021 18:03:08 -0800 Subject: [PATCH 3/3] Fix GCC error --- src/coreclr/jit/lower.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index 992f8b98a8faff..2467a00accdaa7 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -1259,7 +1259,7 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* inf { #ifdef TARGET_ARM assert((info->GetStackSlotsNumber() == 1) || - (arg->TypeGet() == TYP_DOUBLE) && (info->GetStackSlotsNumber() == 2)); + ((arg->TypeGet() == TYP_DOUBLE) && (info->GetStackSlotsNumber() == 2))); #else assert(varTypeIsSIMD(arg) || (info->GetStackSlotsNumber() == 1)); #endif