-
Notifications
You must be signed in to change notification settings - Fork 5.4k
repro #124386
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
Closed
Closed
repro #124386
Changes from all commits
Commits
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
218 changes: 218 additions & 0 deletions
218
src/tests/Loader/classloader/generics/VSD/Struct_UnboxingStubLookup.cs
This file contains hidden or 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,218 @@ | ||||||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||||||
| // The .NET Foundation licenses this file to you under the MIT license. | ||||||||||
|
|
||||||||||
| // | ||||||||||
| // Regression test for debug assertion in FindTightlyBoundWrappedMethodDesc_DEBUG | ||||||||||
| // and FindTightlyBoundUnboxingStub_DEBUG (src/coreclr/vm/genmeth.cpp). | ||||||||||
| // | ||||||||||
| // These debug-only verification functions previously used MethodTable::MethodIterator | ||||||||||
| // (slot-based) with IsVirtual()/!IsVirtual() filters that could miss certain | ||||||||||
| // MethodDescs not reachable through the expected slot range. The production functions | ||||||||||
| // use IntroducedMethodIterator (chunk-based) which correctly enumerates all methods. | ||||||||||
| // This mismatch caused debug assertions when the production function found a method | ||||||||||
| // that the debug function missed. | ||||||||||
| // | ||||||||||
| // For generic value types, the MethodTableBuilder allocates a vtable slot for the | ||||||||||
| // "unboxed copy" of each method (via cVtableSlots++), putting it in the virtual slot | ||||||||||
| // range. The old FindTightlyBoundWrappedMethodDesc_DEBUG only searched non-virtual | ||||||||||
| // slots (!IsVirtual() filter), so it missed the wrapped method and returned NULL. | ||||||||||
| // | ||||||||||
| // This test exercises the code path by calling virtual methods on generic structs. | ||||||||||
| // During JIT compilation, getCallInfo calls FindOrCreateAssociatedMethodDesc with | ||||||||||
| // allowInstParam=TRUE, which triggers FindTightlyBoundWrappedMethodDesc on the | ||||||||||
| // canonical method table. In Debug builds without the fix, this crashes with an | ||||||||||
| // assertion failure. | ||||||||||
| // | ||||||||||
|
|
||||||||||
| using System; | ||||||||||
| using System.Threading.Tasks; | ||||||||||
| using System.Reflection; | ||||||||||
| using System.Runtime.CompilerServices; | ||||||||||
| using TestLibrary; | ||||||||||
| using Xunit; | ||||||||||
|
|
||||||||||
| public interface IProcessor<T> | ||||||||||
| { | ||||||||||
| int Process(T value); | ||||||||||
| bool Check(T value); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public interface IIdentity | ||||||||||
| { | ||||||||||
| string Identify(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public struct Processor<T> : IProcessor<T>, IIdentity | ||||||||||
| { | ||||||||||
| public T Value; | ||||||||||
|
|
||||||||||
| public int Process(T value) | ||||||||||
| { | ||||||||||
| Value = value; | ||||||||||
| return 1; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public bool Check(T value) => value is not null; | ||||||||||
|
|
||||||||||
| public string Identify() => typeof(T).Name; | ||||||||||
|
|
||||||||||
| public override string ToString() => Value?.ToString() ?? ""; | ||||||||||
| public override int GetHashCode() => Value?.GetHashCode() ?? 0; | ||||||||||
| public override bool Equals(object obj) => obj is Processor<T>; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public class Test_Struct_UnboxingStubLookup | ||||||||||
| { | ||||||||||
| // These methods are NoInlining to ensure each is JIT-compiled separately. | ||||||||||
| // During JIT compilation of each method, getCallInfo resolves the virtual | ||||||||||
| // method call on the generic struct, triggering FindOrCreateAssociatedMethodDesc | ||||||||||
| // → FindTightlyBoundWrappedMethodDesc on the canonical method table. | ||||||||||
|
|
||||||||||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||||||||||
| static int CallProcess<T>(Processor<T> p, T val) => p.Process(val); | ||||||||||
|
|
||||||||||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||||||||||
| static bool CallCheck<T>(Processor<T> p, T val) => p.Check(val); | ||||||||||
|
|
||||||||||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||||||||||
| static string CallIdentify<T>(Processor<T> p) => p.Identify(); | ||||||||||
|
|
||||||||||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||||||||||
| static string CallToString<T>(Processor<T> p) => p.ToString(); | ||||||||||
|
|
||||||||||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||||||||||
| static int CallGetHashCode<T>(Processor<T> p) => p.GetHashCode(); | ||||||||||
|
|
||||||||||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||||||||||
| static int BoxAndDispatch<T>(Processor<T> p, T val) | ||||||||||
| { | ||||||||||
| IProcessor<T> iface = p; | ||||||||||
| return iface.Process(val); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /*public static Task<int> Main() | ||||||||||
| { | ||||||||||
| return Task.FromResult(TestEntryPoint()); | ||||||||||
| }*/ | ||||||||||
|
|
||||||||||
|
Comment on lines
+93
to
+97
|
||||||||||
| /*public static Task<int> Main() | |
| { | |
| return Task.FromResult(TestEntryPoint()); | |
| }*/ |
11 changes: 11 additions & 0 deletions
11
src/tests/Loader/classloader/generics/VSD/Struct_UnboxingStubLookup.csproj
This file contains hidden or 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,11 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <CLRTestPriority>0</CLRTestPriority> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="Struct_UnboxingStubLookup.cs" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="$(TestLibraryProjectPath)" /> | ||
| </ItemGroup> | ||
| </Project> |
Oops, something went wrong.
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.
Remove the unused import
using System.Threading.Tasks. The Task type is only referenced in the commented-out Main method which should also be removed.