-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
On 64 bit platforms, "stelem.ref" and "ldelema" ignore the high bits of a native int index #71571
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
47eba9a
On 64 bit platforms, "stelem.ref" and "ldelema" ignore the high bits …
davidwrighton a812bd6
Revert "On 64 bit platforms, "stelem.ref" and "ldelema" ignore the hi…
davidwrighton 2f2e5ff
Rewrite as updating the existing header and pushing forward the R2R band
davidwrighton dccfef2
Update issues.targets for mono, and run jit formatting tool
davidwrighton 2b75a33
Fix NativeAOT
davidwrighton 0d20b6b
Update src/tests/issues.targets
davidwrighton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is
Unsafe.Add
overload that takesIntPtr
. It should not be necessary to cast theindex
toint
here. It just going to add an extra unnecessary instruction.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the problem is that the "minimal runtime" does not compile without the cast, just add the necessary method to the minimal Unsafe used by the minimal runtime.