Skip to content

Commit 4a17f04

Browse files
Fix a case in MethodImpl overriding which wasn't handled as expected in ilc.exe for native aot (#106716)
* Fix a case in MethodImpl overriding which wasn't handled as expected in ilc.exe for native aot - This was causing real C# applications to fail to behave correctly on NativeAOT builds - Enable testing for covariant byref returns on nativeaot (split testing up so that the tests do not expect TypeLoadException, which NativeAOT doesn't reliably generate) - Put copy of attributetesting.il test into the managed type system unit test suite - Add regression test of issue noted in #96175 into managed type system unit test suite - Update workflow documentation to include a better path to finding details on how to run CoreCLR and Libraries tests for Native AOT Fixes #96175
1 parent 36e6b42 commit 4a17f04

19 files changed

+3923
-649
lines changed

docs/workflow/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,14 @@ Now you know about configurations and how we use them, so now you will want to r
7878

7979
* [Building CoreCLR runtime](/docs/workflow/building/coreclr/README.md)
8080
* [Building Mono runtime](/docs/workflow/building/mono/README.md)
81+
* [Building NativeAOT runtime](/docs/workflow/building/coreclr/nativeaot.md)
8182
* [Building Libraries](/docs/workflow/building/libraries/README.md)
8283

8384
After that, here's information about how to run tests:
8485

8586
* [Testing CoreCLR runtime](/docs/workflow/testing/coreclr/testing.md)
8687
* [Testing Mono runtime](/docs/workflow/testing/mono/testing.md)
88+
* [Testing NativeAOT runtime](/docs/workflow/building/coreclr/nativeaot.md#running-tests)
8789
* [Testing Libraries](/docs/workflow/testing/libraries/testing.md)
8890

8991
And how to measure performance:

docs/workflow/building/coreclr/nativeaot.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ If you haven't built the tests yet, run `src\tests\build.cmd nativeaot [Debug|Re
8787

8888
To run all the tests that got built, run `src\tests\run.cmd runnativeaottests [Debug|Release]` on Windows, or `src/tests/run.sh --runnativeaottests [Debug|Release]` on Linux. The `Debug`/`Release` flag should match the flag that was passed to `build.cmd` in the previous step.
8989

90+
To build an individual test, follow the instructions for compiling a individual test project located in [Building an Individual Test](/docs/workflow/testing/coreclr/testing.md#building-an-individual-test), but add `/t:BuildNativeAot /p:TestBuildMode=nativeaot` to the build command.
91+
9092
To run an individual test (after it was built), navigate to the `artifacts\tests\coreclr\[windows|linux|osx[.x64.[Debug|Release]\$path_to_test` directory. `$path_to_test` matches the subtree of `src\tests`. You should see a `[.cmd|.sh]` file there. This file is a script that will compile and launch the individual test for you. Before invoking the script, set the following environment variables:
9193

9294
* CORE_ROOT=$repo_root\artifacts\tests\coreclr\[windows|linux|osx].x64.[Debug|Release]\Tests\Core_Root

src/coreclr/tools/Common/TypeSystem/Common/MetadataVirtualMethodAlgorithm.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,26 @@ private static void FindBaseUnificationGroup(MetadataType currentType, Unificati
461461
// Unless the current type has a name/sig match for the group, look to the base type to define the unification group further
462462
if ((nameSigMatchMethod == null) && (baseType != null))
463463
{
464+
// TODO! Consider if we should do this check even if the virtual name/sig match finds something.
465+
// We may want to build up a unification group for the base just to check the further MethodImpl case here.
464466
FindBaseUnificationGroup(baseType, unificationGroup);
467+
468+
// We should check to see if a the DefiningMethod on the base unification group is overriden via MethodImpl
469+
// TODO! check to see if we need to check for MethodImpls affecting other members of the unification group
470+
// other than the defining method
471+
if (unificationGroup.DefiningMethod != null)
472+
{
473+
methodImpl = FindImplFromDeclFromMethodImpls(currentType, unificationGroup.DefiningMethod);
474+
if (methodImpl != null)
475+
{
476+
if (methodImpl.RequiresSlotUnification())
477+
{
478+
unificationGroup.AddMethodRequiringSlotUnification(unificationGroup.DefiningMethod);
479+
unificationGroup.AddMethodRequiringSlotUnification(methodImpl);
480+
}
481+
unificationGroup.SetDefiningMethod(methodImpl);
482+
}
483+
}
465484
}
466485

467486
Debug.Assert(unificationGroup.IsInGroupOrIsDefiningSlot(originalDefiningMethod));

src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/CoreTestAssembly/Platform.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,17 @@ public static class RuntimeFeature
247247
public const string ByRefLikeGenerics = nameof(ByRefLikeGenerics);
248248
public const string UnmanagedSignatureCallingConvention = nameof(UnmanagedSignatureCallingConvention);
249249
public const string VirtualStaticsInInterfaces = nameof(VirtualStaticsInInterfaces);
250+
public const string CovariantReturnsOfClasses = "CovariantReturnsOfClasses";
250251
}
251252

252253
internal sealed class IntrinsicAttribute : Attribute
253254
{
254255
}
256+
257+
public sealed partial class PreserveBaseOverridesAttribute : System.Attribute
258+
{
259+
public PreserveBaseOverridesAttribute() { }
260+
}
255261
}
256262

257263
namespace System.Runtime.Intrinsics

src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/CoreTestAssembly/VirtualFunctionOverride.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,44 @@ unsafe class FunctionPointerOverloadDerived : FunctionPointerOverloadBase
6060
public override Type Method(delegate* unmanaged[Stdcall, SuppressGCTransition]<void> p) => null;
6161
public override Type Method(delegate*<void> p) => null;
6262
}
63+
64+
class BaseCovariant
65+
{
66+
public virtual BaseCovariant FromType()
67+
{
68+
return new BaseCovariant();
69+
}
70+
}
71+
72+
class ImplCovariant : BaseCovariant
73+
{
74+
public override ImplCovariant FromType()
75+
{
76+
return new ImplCovariant();
77+
}
78+
}
79+
80+
class SubImplCovariant : ImplCovariant
81+
{
82+
public override SubImplCovariant FromType()
83+
{
84+
return new SubImplCovariant();
85+
}
86+
}
87+
88+
class SubImplCovariant2 : ImplCovariant
89+
{
90+
public override ImplCovariant FromType()
91+
{
92+
return new ImplCovariant();
93+
}
94+
}
95+
96+
class SubSubImplCovariant : SubImplCovariant2
97+
{
98+
public override SubSubImplCovariant FromType()
99+
{
100+
return new SubSubImplCovariant();
101+
}
102+
}
63103
}

src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/ILTestAssembly/ILTestAssembly.ilproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<Compile Include="Signature.il" />
2020
<Compile Include="MethodImplOverride1.il" />
2121
<Compile Include="MDArrayFunctionResolution.il" />
22+
<Compile Include="PreserveBaseOverridesAttibuteTesting.il" />
2223
</ItemGroup>
2324

2425
</Project>

0 commit comments

Comments
 (0)