-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
On 64 bit platforms, "stelem.ref" and "ldelema" ignore the high bits …
…of a native int index (#71571) Add support for native int indices in stelem.ref and ldelema helper functions. This required changing the abi of these functions, which required bumping the major R2R version number. As we have already done that for .NET 7, this is a minor cost. Note that this is still broken on Mono, and that bug is #71656 Fixes #52817
- Loading branch information
1 parent
f29ae44
commit 0e30a6f
Showing
13 changed files
with
148 additions
and
18 deletions.
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
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
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
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
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
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
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
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
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
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
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,66 @@ | ||
// 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; | ||
|
||
class NintIndexOutOfRangeTest | ||
{ | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static void Stelem_Ref(object[] arr, nint i, Object value) | ||
=> arr[i] = value; | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static void LdElemATestHelper(ref object nothingOfInterest) | ||
{} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static void LdElemA(object[] arr, nint i) | ||
{ | ||
LdElemATestHelper(ref arr[i]); | ||
} | ||
|
||
public static unsafe int Main() | ||
{ | ||
long longIndex = ((long)1) << 32; | ||
nint index = (nint)longIndex; | ||
bool failed = false; | ||
|
||
// On a 32bit platform, just succeed. | ||
if (sizeof(long) != sizeof(nint)) | ||
return 100; | ||
|
||
var arr = new Object[10]; | ||
// Try store to invalid index with null | ||
try | ||
{ | ||
Stelem_Ref(arr, index, null); | ||
failed = true; | ||
Console.WriteLine("Failed to throw IndexOutOfRange when storing null"); | ||
} | ||
catch (IndexOutOfRangeException) {} | ||
|
||
// Try store to invalid index with actual value | ||
try | ||
{ | ||
Stelem_Ref(arr, index, new object()); | ||
failed = true; | ||
Console.WriteLine("Failed to throw IndexOutOfRange when storing object"); | ||
} | ||
catch (IndexOutOfRangeException) {} | ||
|
||
// Try to load element address | ||
try | ||
{ | ||
LdElemA(arr, index); | ||
failed = true; | ||
Console.WriteLine("Failed to throw IndexOutOfRange when accessing element"); | ||
} | ||
catch (IndexOutOfRangeException) {} | ||
|
||
if (failed) | ||
return 1; | ||
else | ||
return 100; | ||
} | ||
} |
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,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<CLRTestPriority>0</CLRTestPriority> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="nintindexoutofrange.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