Skip to content

Commit 86d2eaa

Browse files
authored
JIT: fix non-funclet EH empty finally/fault removal (#109361)
For non-funclet EH we don't use the handler index to constrain the placement of add code descs, but we were still recording the handler index in the ACD. This lead to some errors in ACD maintenance if there was an EH region being removed with an ACD in the try and an equivalent one in the handler. Fixes #108851
1 parent a72cfb0 commit 86d2eaa

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

src/coreclr/jit/fgehopt.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ PhaseStatus Compiler::fgRemoveEmptyFinally()
233233
AddCodeDscMap* const map = fgGetAddCodeDscMap();
234234
for (AddCodeDsc* const add : AddCodeDscMap::ValueIteration(map))
235235
{
236+
JITDUMP("Considering ");
237+
JITDUMPEXEC(add->Dump());
238+
236239
// Remember the old lookup key
237240
//
238241
AddCodeDscKey oldKey(add);
@@ -245,7 +248,7 @@ PhaseStatus Compiler::fgRemoveEmptyFinally()
245248
{
246249
bool const removed = map->Remove(oldKey);
247250
assert(removed);
248-
JITDUMP("ACD%u was in EH#%u handler region: removing\n", XTnum);
251+
JITDUMP("ACD%u was in EH#%u handler region: removing\n", add->acdNum, XTnum);
249252
JITDUMPEXEC(add->Dump());
250253
continue;
251254
}
@@ -258,6 +261,7 @@ PhaseStatus Compiler::fgRemoveEmptyFinally()
258261

259262
if (!inTry || ((unsigned)(add->acdTryIndex - 1) != XTnum))
260263
{
264+
JITDUMP("ACD%u not affected\n", add->acdNum);
261265
continue;
262266
}
263267

src/coreclr/jit/flowgraph.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,9 +3420,12 @@ void Compiler::fgAddCodeRef(BasicBlock* srcBlk, SpecialCodeKind kind)
34203420
add = new (this, CMK_Unknown) AddCodeDsc;
34213421
add->acdDstBlk = nullptr;
34223422
add->acdTryIndex = srcBlk->bbTryIndex;
3423-
add->acdHndIndex = srcBlk->bbHndIndex;
3424-
add->acdKeyDsg = dsg;
3425-
add->acdKind = kind;
3423+
3424+
// For non-funclet EH we don't constrain ACD placement via handler regions
3425+
add->acdHndIndex = UsesFunclets() ? srcBlk->bbHndIndex : 0;
3426+
3427+
add->acdKeyDsg = dsg;
3428+
add->acdKind = kind;
34263429

34273430
// This gets set true in the stack level setter
34283431
// if there's still a need for this helper
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
// Generated by Fuzzlyn v2.4 on 2024-10-14 17:25:44
5+
// Run on X86 Windows
6+
// Seed: 16789241273493732217-vectort,vector128,vector256,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86bmi1,x86bmi2,x86fma,x86lzcnt,x86pclmulqdq,x86popcnt,x86sse,x86sse2,x86sse3,x86sse41,x86sse42,x86ssse3,x86x86base
7+
// Reduced from 49.4 KiB to 0.5 KiB in 00:03:38
8+
// Hits JIT assert in Release:
9+
// Assertion failed '!fgRngChkThrowAdded' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Calculate stack level slots' (IL size 59; hash 0xade6b36b; FullOpts)
10+
//
11+
// File: D:\a\_work\1\s\src\coreclr\jit\flowgraph.cpp Line: 3655
12+
//
13+
using System;
14+
using System.Numerics;
15+
using System.Runtime.Intrinsics;
16+
using System.Runtime.Intrinsics.X86;
17+
using Xunit;
18+
19+
public class Runtime_108851
20+
{
21+
public static int[] s_21 = new int[1];
22+
23+
[Fact]
24+
public static void Problem()
25+
{
26+
if (!Avx512F.IsSupported)
27+
{
28+
return;
29+
}
30+
31+
var vr1 = Vector128.Create<double>(0);
32+
if (Avx512F.ConvertToUInt32WithTruncation(vr1) >= 2894444111893762202L)
33+
{
34+
try
35+
{
36+
s_21[0] = 0;
37+
}
38+
finally
39+
{
40+
s_21[0] = 0;
41+
}
42+
}
43+
44+
s_21[0] = 0;
45+
}
46+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Optimize>True</Optimize>
4+
<NoWarn>0652</NoWarn>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<Compile Include="$(MSBuildProjectName).cs" />
8+
</ItemGroup>
9+
</Project>

0 commit comments

Comments
 (0)