Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
SingleAccretion committed Apr 22, 2022
1 parent 6b69b7e commit ec5f2a8
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/tests/JIT/Methodical/Arrays/misc/IndexingSideEffects.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;
using Xunit;

public class IndexingSideEffects
{
[Fact]
public static int TestEntryPoint()
{
if (!Problem())
{
return 101;
}

return 100;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool Problem()
{
bool result = false;

try
{
TryIndexing(new int[0]);
}
catch (IndexOutOfRangeException)
{
result = true;
}

return result;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void TryIndexing(int[] a)
{
// Make sure that early flowgraph simplification does not remove the side effect of indexing
// when deleting the relop.
if (a[int.MaxValue] == 0)
{
NopInlinedCall();
}
}

private static void NopInlinedCall() { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit ec5f2a8

Please sign in to comment.