Skip to content

Commit bf6cfef

Browse files
authored
Don't update side-effects in a statement that doesn't exist (#113351)
1 parent f565711 commit bf6cfef

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

Diff for: src/coreclr/jit/rangecheckcloning.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,12 @@ static BasicBlock* optRangeCheckCloning_DoClone(Compiler* comp,
345345
// it happens when we emit BBJ_COND(0 >= 0) fake block (for simplicity)
346346
comp->gtUpdateStmtSideEffects(lowerBndBb->lastStmt());
347347
}
348-
comp->gtUpdateStmtSideEffects(upperBndBb->lastStmt());
348+
if (upperBndBb->lastStmt() != nullptr)
349+
{
350+
// In rare cases, upperBndBb can also be folded into an empty block
351+
// by fgMorphBlockStmt
352+
comp->gtUpdateStmtSideEffects(upperBndBb->lastStmt());
353+
}
349354

350355
// All blocks must be in the same EH region
351356
assert(BasicBlock::sameEHRegion(prevBb, lowerBndBb));
@@ -395,7 +400,8 @@ class BoundsChecksVisitor final : public GenTreeVisitor<BoundsChecksVisitor>
395400

396401
fgWalkResult PostOrderVisit(GenTree** use, GenTree* user)
397402
{
398-
if ((*use)->OperIs(GT_BOUNDS_CHECK))
403+
// For now, we only handle SCK_RNGCHK_FAIL
404+
if ((*use)->OperIs(GT_BOUNDS_CHECK) && ((*use)->AsBoundsChk()->gtThrowKind == SCK_RNGCHK_FAIL))
399405
{
400406
m_boundsChks->Push(BoundCheckLocation(m_stmt, use, m_stmtIdx));
401407
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 2025-03-09 18:07:26
5+
// Run on X86 Windows
6+
// Seed: 1821229397629005810-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 126.0 KiB to 0.5 KiB in 00:02:28
8+
// Hits JIT assert in Release:
9+
// Assertion failed 'use != nullptr' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Clone blocks with range checks' (IL size 62; hash 0xade6b36b; FullOpts)
10+
11+
using System.Runtime.Intrinsics;
12+
using System.Runtime.Intrinsics.X86;
13+
using Xunit;
14+
15+
public class Runtime_113334
16+
{
17+
[Fact]
18+
public static void Problem()
19+
{
20+
if (Fma.IsSupported)
21+
{
22+
float[] vr8 = new float[]
23+
{
24+
0
25+
};
26+
var vr9 = Vector128.Create<float>(0);
27+
Fma.MultiplyAddNegatedScalar(vr9, Vector128.Create(vr8[0], vr8[0], vr8[0], vr8[0]), Sse.CompareScalarEqual(Vector128.Create<float>(vr8[0]), Vector128.CreateScalar(vr8[0])));
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Optimize>True</Optimize>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<Compile Include="$(MSBuildProjectName).cs" />
7+
</ItemGroup>
8+
</Project>

0 commit comments

Comments
 (0)