[release/6.0] Remove benign assert (#59044)
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Tue, 14 Sep 2021 23:32:23 +0000 (16:32 -0700)
committerGitHub <noreply@github.com>
Tue, 14 Sep 2021 23:32:23 +0000 (16:32 -0700)
* Remove benign assert

It is perfectly possible for us to replace a promoted struct by its only
field where that field is marked do-not-enregister. Since this path does
handle the proper retyping when normalization is required this assertion
is benign.

Fix #58972

* Fix test

Co-authored-by: Jakob Botsch Nielsen <jakob.botsch.nielsen@gmail.com>
src/coreclr/jit/lower.cpp
src/tests/JIT/Regression/JitBlue/Runtime_58972/Runtime_58972.cs [new file with mode: 0644]
src/tests/JIT/Regression/JitBlue/Runtime_58972/Runtime_58972.csproj [new file with mode: 0644]

index 178217f..ed269cc 100644 (file)
@@ -3433,7 +3433,6 @@ void Lowering::LowerRetSingleRegStructLclVar(GenTreeUnOp* ret)
 
     if (varDsc->lvDoNotEnregister)
     {
-        assert(!replacedInLowering);
         lclVar->ChangeOper(GT_LCL_FLD);
         lclVar->AsLclFld()->SetLclOffs(0);
 
diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_58972/Runtime_58972.cs b/src/tests/JIT/Regression/JitBlue/Runtime_58972/Runtime_58972.cs
new file mode 100644 (file)
index 0000000..b63c1d9
--- /dev/null
@@ -0,0 +1,37 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+
+public class Runtime_58972
+{
+    public static int Main()
+    {
+        GetItem(new MyStruct[1], 0);
+        return 100;
+    }
+
+       // This code results in a struct returned in register where we replace the local
+       // of type MyStruct by its only field, and where that field cannot be enregistered.
+       // We would potentially miss normalization if the struct was returned as an integer
+       // type and hit a defensive assertion because of it.
+    static MyStruct GetItem(MyStruct[] a, int i)
+    {
+        try
+        {
+            return a[i];
+        }
+        catch (IndexOutOfRangeException)
+        {
+            ThrowHelper();
+            return default;
+        }
+    }
+
+    static void ThrowHelper() => throw new Exception();
+
+    struct MyStruct
+    {
+        byte b;
+    }
+}
diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_58972/Runtime_58972.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_58972/Runtime_58972.csproj
new file mode 100644 (file)
index 0000000..f3e1cbd
--- /dev/null
@@ -0,0 +1,12 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+  </PropertyGroup>
+  <PropertyGroup>
+    <DebugType>None</DebugType>
+    <Optimize>True</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="$(MSBuildProjectName).cs" />
+  </ItemGroup>
+</Project>