Skip to content

Commit b3a9b0b

Browse files
[release/6.0] Remove benign assert (#59044)
* 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 <[email protected]>
1 parent bf2a7d0 commit b3a9b0b

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/coreclr/jit/lower.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3433,7 +3433,6 @@ void Lowering::LowerRetSingleRegStructLclVar(GenTreeUnOp* ret)
34333433

34343434
if (varDsc->lvDoNotEnregister)
34353435
{
3436-
assert(!replacedInLowering);
34373436
lclVar->ChangeOper(GT_LCL_FLD);
34383437
lclVar->AsLclFld()->SetLclOffs(0);
34393438

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
6+
public class Runtime_58972
7+
{
8+
public static int Main()
9+
{
10+
GetItem(new MyStruct[1], 0);
11+
return 100;
12+
}
13+
14+
// This code results in a struct returned in register where we replace the local
15+
// of type MyStruct by its only field, and where that field cannot be enregistered.
16+
// We would potentially miss normalization if the struct was returned as an integer
17+
// type and hit a defensive assertion because of it.
18+
static MyStruct GetItem(MyStruct[] a, int i)
19+
{
20+
try
21+
{
22+
return a[i];
23+
}
24+
catch (IndexOutOfRangeException)
25+
{
26+
ThrowHelper();
27+
return default;
28+
}
29+
}
30+
31+
static void ThrowHelper() => throw new Exception();
32+
33+
struct MyStruct
34+
{
35+
byte b;
36+
}
37+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
</PropertyGroup>
5+
<PropertyGroup>
6+
<DebugType>None</DebugType>
7+
<Optimize>True</Optimize>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<Compile Include="$(MSBuildProjectName).cs" />
11+
</ItemGroup>
12+
</Project>

0 commit comments

Comments
 (0)