Skip to content

Commit a1c61fd

Browse files
Treat INDEX as a potentially throwing operation (#68381)
* Treat INDEX as potentially throwing Not doing so will lead to the side-effect extraction routine dropping it. * Add a test
1 parent 10012c4 commit a1c61fd

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

src/coreclr/jit/gentree.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6464,6 +6464,7 @@ bool GenTree::OperMayThrow(Compiler* comp)
64646464
case GT_ARR_OFFSET:
64656465
case GT_LCLHEAP:
64666466
case GT_CKFINITE:
6467+
case GT_INDEX:
64676468
case GT_INDEX_ADDR:
64686469
return true;
64696470

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
using System.Runtime.CompilerServices;
6+
using Xunit;
7+
8+
public class IndexingSideEffects
9+
{
10+
[Fact]
11+
public static int TestEntryPoint()
12+
{
13+
if (!Problem())
14+
{
15+
return 101;
16+
}
17+
18+
return 100;
19+
}
20+
21+
[MethodImpl(MethodImplOptions.NoInlining)]
22+
private static bool Problem()
23+
{
24+
bool result = false;
25+
26+
try
27+
{
28+
TryIndexing(new int[0]);
29+
}
30+
catch (IndexOutOfRangeException)
31+
{
32+
result = true;
33+
}
34+
35+
return result;
36+
}
37+
38+
[MethodImpl(MethodImplOptions.NoInlining)]
39+
private static void TryIndexing(int[] a)
40+
{
41+
// Make sure that early flowgraph simplification does not remove the side effect of indexing
42+
// when deleting the relop.
43+
if (a[int.MaxValue] == 0)
44+
{
45+
NopInlinedCall();
46+
}
47+
}
48+
49+
private static void NopInlinedCall() { }
50+
}
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+
<DebugType>None</DebugType>
4+
<Optimize>True</Optimize>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<Compile Include="$(MSBuildProjectName).cs" />
8+
</ItemGroup>
9+
</Project>

0 commit comments

Comments
 (0)