Skip to content

Commit

Permalink
Fix a case in MethodImpl overriding which wasn't handled as expected …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
davidwrighton committed Sep 5, 2024
1 parent 36e6b42 commit 4a17f04
Show file tree
Hide file tree
Showing 19 changed files with 3,923 additions and 649 deletions.
2 changes: 2 additions & 0 deletions docs/workflow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ Now you know about configurations and how we use them, so now you will want to r

* [Building CoreCLR runtime](/docs/workflow/building/coreclr/README.md)
* [Building Mono runtime](/docs/workflow/building/mono/README.md)
* [Building NativeAOT runtime](/docs/workflow/building/coreclr/nativeaot.md)
* [Building Libraries](/docs/workflow/building/libraries/README.md)

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

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

And how to measure performance:
Expand Down
2 changes: 2 additions & 0 deletions docs/workflow/building/coreclr/nativeaot.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ If you haven't built the tests yet, run `src\tests\build.cmd nativeaot [Debug|Re

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.

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.

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:

* CORE_ROOT=$repo_root\artifacts\tests\coreclr\[windows|linux|osx].x64.[Debug|Release]\Tests\Core_Root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,26 @@ private static void FindBaseUnificationGroup(MetadataType currentType, Unificati
// Unless the current type has a name/sig match for the group, look to the base type to define the unification group further
if ((nameSigMatchMethod == null) && (baseType != null))
{
// TODO! Consider if we should do this check even if the virtual name/sig match finds something.
// We may want to build up a unification group for the base just to check the further MethodImpl case here.
FindBaseUnificationGroup(baseType, unificationGroup);

// We should check to see if a the DefiningMethod on the base unification group is overriden via MethodImpl
// TODO! check to see if we need to check for MethodImpls affecting other members of the unification group
// other than the defining method
if (unificationGroup.DefiningMethod != null)
{
methodImpl = FindImplFromDeclFromMethodImpls(currentType, unificationGroup.DefiningMethod);
if (methodImpl != null)
{
if (methodImpl.RequiresSlotUnification())
{
unificationGroup.AddMethodRequiringSlotUnification(unificationGroup.DefiningMethod);
unificationGroup.AddMethodRequiringSlotUnification(methodImpl);
}
unificationGroup.SetDefiningMethod(methodImpl);
}
}
}

Debug.Assert(unificationGroup.IsInGroupOrIsDefiningSlot(originalDefiningMethod));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,17 @@ public static class RuntimeFeature
public const string ByRefLikeGenerics = nameof(ByRefLikeGenerics);
public const string UnmanagedSignatureCallingConvention = nameof(UnmanagedSignatureCallingConvention);
public const string VirtualStaticsInInterfaces = nameof(VirtualStaticsInInterfaces);
public const string CovariantReturnsOfClasses = "CovariantReturnsOfClasses";
}

internal sealed class IntrinsicAttribute : Attribute
{
}

public sealed partial class PreserveBaseOverridesAttribute : System.Attribute
{
public PreserveBaseOverridesAttribute() { }
}
}

namespace System.Runtime.Intrinsics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,44 @@ unsafe class FunctionPointerOverloadDerived : FunctionPointerOverloadBase
public override Type Method(delegate* unmanaged[Stdcall, SuppressGCTransition]<void> p) => null;
public override Type Method(delegate*<void> p) => null;
}

class BaseCovariant
{
public virtual BaseCovariant FromType()
{
return new BaseCovariant();
}
}

class ImplCovariant : BaseCovariant
{
public override ImplCovariant FromType()
{
return new ImplCovariant();
}
}

class SubImplCovariant : ImplCovariant
{
public override SubImplCovariant FromType()
{
return new SubImplCovariant();
}
}

class SubImplCovariant2 : ImplCovariant
{
public override ImplCovariant FromType()
{
return new ImplCovariant();
}
}

class SubSubImplCovariant : SubImplCovariant2
{
public override SubSubImplCovariant FromType()
{
return new SubSubImplCovariant();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<Compile Include="Signature.il" />
<Compile Include="MethodImplOverride1.il" />
<Compile Include="MDArrayFunctionResolution.il" />
<Compile Include="PreserveBaseOverridesAttibuteTesting.il" />
</ItemGroup>

</Project>
Loading

0 comments on commit 4a17f04

Please sign in to comment.