-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/8.0] [mono] Disallow casts of bounded arrays to array specia…
…l interfaces (#93617) * [mono] Disallow casts of bounded arrays to array special interfaces Fixes #93597 * exclude lower bound regression test on NativeAOT * try to fix nativaot exclude --------- Co-authored-by: Aleksey Kliger <alklig@microsoft.com>
- Loading branch information
1 parent
74c81be
commit fbd28cb
Showing
4 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/tests/Loader/classloader/regressions/GitHub_93597/GitHub_93597.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
|
||
public class ReproGH93597 { | ||
public static int Main() { | ||
var expected = new int[] {5,4,3,2,1}; | ||
|
||
const int LowerBound = 5; | ||
|
||
var expectedNzlba = NonZeroLowerBoundArray(expected, LowerBound); | ||
|
||
return Helper(expectedNzlba); | ||
return 100; | ||
} | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static int Helper(Array a) { | ||
IEnumerable<int> ie = null; | ||
try { | ||
ie = (IEnumerable<int>)a; | ||
} catch (InvalidCastException) { | ||
Console.WriteLine ("caught ICE, good"); | ||
return 100; | ||
} | ||
ie.GetEnumerator(); // mono crashes here | ||
return 101; | ||
} | ||
|
||
|
||
private static Array NonZeroLowerBoundArray(Array szArrayContents, int lowerBound) | ||
{ | ||
Array array = Array.CreateInstance(szArrayContents.GetType().GetElementType(), new int[] { szArrayContents.Length }, new int[] { lowerBound }); | ||
for (int i = 0; i < szArrayContents.Length; i++) | ||
{ | ||
array.SetValue(szArrayContents.GetValue(i), i + lowerBound); | ||
} | ||
return array; | ||
} | ||
|
||
} | ||
|
5 changes: 5 additions & 0 deletions
5
src/tests/Loader/classloader/regressions/GitHub_93597/GitHub_93597.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<ItemGroup> | ||
<Compile Include="GitHub_93597.cs" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters