Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/coreclr/jit/ifconversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,22 @@ bool OptIfConversionDsc::IfConvertCheckFlow()
return false;
}

// The Then/Else blocks will be removed by if-conversion, so they must be in the same
// EH region as m_startBlock. Otherwise they may be the start of a try/handler region
// (and thus marked BBF_DONT_REMOVE), or removing them could leave dangling EH state.
if (!BasicBlock::sameEHRegion(falseBb, m_startBlock))
{
return false;
}

m_doElseConversion = trueBb->GetUniquePred(m_compiler) != nullptr;
m_finalBlock = m_doElseConversion ? trueBb->GetUniqueSucc() : trueBb;

if (m_doElseConversion && !BasicBlock::sameEHRegion(trueBb, m_startBlock))
{
return false;
}

// m_finalBlock is only allowed to be null if both return.
// E.g: Then block exits by throwing an exception => we bail here.
if (m_finalBlock == nullptr && (!falseBb->KindIs(BBJ_RETURN) || !trueBb->KindIs(BBJ_RETURN)))
Expand Down
53 changes: 53 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_127446/Runtime_127446.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Runtime_127446;

using System;
using Xunit;

public class Runtime_127446
{
// Regression test: the JIT's if-conversion phase used to assert when the
// "Then" block was the start of an EH region (and therefore marked
// BBF_DONT_REMOVE). Compilation should succeed without hitting the assert.
[Fact]
public static void TestEntryPoint()
{
try
{
M0();
}
catch (NullReferenceException)
{
}
catch (DivideByZeroException)
{
}
}

private static void M0()
{
int var1 = default(int);
bool[,] var4 = default(bool[,]);
if (var4[0, 0])
{
try
{
var1 = 0;
}
catch (System.Exception)
{
try
{
var4[0, 0] = var4[0, 0];
}
catch (System.Exception)
{
}
}
}

var1 = (0 / var1);
}
}
1 change: 1 addition & 0 deletions src/tests/JIT/Regression/Regression_o_3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<Compile Include="JitBlue\Runtime_97625\Runtime_97625.cs" />
<Compile Include="JitBlue\Runtime_98068\Runtime_98068.cs" />
<Compile Include="JitBlue\Runtime_99391\Runtime_99391.cs" />
<Compile Include="JitBlue\Runtime_127446\Runtime_127446.cs" />
<Compile Include="JitBlue\WPF_3226\CSharpRepro\WPF_3226.cs" />
</ItemGroup>
<Import Project="$(TestSourceDir)MergedTestRunner.targets" />
Expand Down
Loading