-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Classify type with empty base as non-blittable #46769
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
Merged
davidwrighton
merged 4 commits into
dotnet:master
from
am11:feature/crossgen2/R2RTests/MarshalUtils
Jan 20, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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
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
183 changes: 183 additions & 0 deletions
183
src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/CoreTestAssembly/Marshalling.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,183 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace Marshalling | ||
| { | ||
|
|
||
| #region Simple classes | ||
|
|
||
| public class SimpleEmptyClass | ||
| { | ||
| } | ||
|
|
||
| public class SimpleByteClass | ||
| { | ||
| public byte x; | ||
| } | ||
|
|
||
| public class SimpleInt16Class | ||
| { | ||
| public short x; | ||
| } | ||
|
|
||
| public class SimpleInt32Class | ||
| { | ||
| public int x; | ||
| } | ||
|
|
||
| public class SimpleInt64Class | ||
| { | ||
| public long x; | ||
| } | ||
|
|
||
| #endregion | ||
|
|
||
| #region LayoutKind.Explicit classes | ||
|
|
||
| [StructLayout(LayoutKind.Explicit)] | ||
| public class ExplicitEmptyBase | ||
| { | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Explicit)] | ||
| public class ClassWithExplicitEmptyBase : ExplicitEmptyBase | ||
| { | ||
| [FieldOffset(0)] | ||
| public int i; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Explicit, Size = 0)] | ||
| public class ExplicitEmptySizeZeroBase | ||
| { | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Explicit)] | ||
| public class ClassWithExplicitEmptySizeZeroBase : ExplicitEmptySizeZeroBase | ||
| { | ||
| [FieldOffset(0)] | ||
| public int i; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Explicit)] | ||
| public class ExplicitByteBase | ||
| { | ||
| [FieldOffset(0)] | ||
| public byte x; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Explicit)] | ||
| public class ClassWithExplicitByteBase : ExplicitByteBase | ||
| { | ||
| [FieldOffset(1)] | ||
| public int i; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Explicit)] | ||
| public class ExplicitInt16Base | ||
| { | ||
| [FieldOffset(0)] | ||
| public short x; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Explicit)] | ||
| public class ClassWithExplicitInt16Base : ExplicitInt16Base | ||
| { | ||
| [FieldOffset(1)] | ||
| public int i; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Explicit)] | ||
| public class ExplicitInt32Base | ||
| { | ||
| [FieldOffset(0)] | ||
| public int x; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Explicit)] | ||
| public class ClassWithExplicitInt32Base : ExplicitInt32Base | ||
| { | ||
| [FieldOffset(1)] | ||
| public int i; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Explicit)] | ||
| public class ExplicitInt64Base | ||
| { | ||
| [FieldOffset(0)] | ||
| public long x; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Explicit)] | ||
| public class ClassWithExplicitInt64Base : ExplicitInt64Base | ||
| { | ||
| [FieldOffset(1)] | ||
| public int i; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| public class SequentialEmptyBase | ||
| { | ||
| } | ||
|
|
||
| #endregion | ||
|
|
||
| #region LayoutKind.Sequential classes | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| public class ClassWithSequentialEmptyBase : SequentialEmptyBase | ||
| { | ||
| public int i; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| public class SequentialByteBase | ||
| { | ||
| public byte x; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| public class ClassWithSequentialByteBase : SequentialByteBase | ||
| { | ||
| public int i; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| public class SequentialInt16Base | ||
| { | ||
| public short x; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| public class ClassWithSequentialInt16Base : SequentialInt16Base | ||
| { | ||
| public int i; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| public class SequentialInt32Base | ||
| { | ||
| public int x; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| public class ClassWithSequentialInt32Base : SequentialInt32Base | ||
| { | ||
| public int i; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| public class SequentialInt64Base | ||
| { | ||
| public long x; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| public class ClassWithSequentialInt64Base : SequentialInt64Base | ||
| { | ||
| public int i; | ||
| } | ||
|
|
||
| #endregion | ||
| } |
54 changes: 54 additions & 0 deletions
54
src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/DefType.FieldLayoutTests.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,54 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Internal.TypeSystem; | ||
| using Internal.TypeSystem.Interop; | ||
|
|
||
| using Xunit; | ||
|
|
||
| namespace TypeSystemTests | ||
| { | ||
| public partial class DefTypeTests | ||
| { | ||
| private ModuleDesc _testModule; | ||
|
|
||
| public DefTypeTests() | ||
| { | ||
| var context = new TestTypeSystemContext(TargetArchitecture.X64); | ||
| var systemModule = context.CreateModuleForSimpleName("CoreTestAssembly"); | ||
| context.SetSystemModule(systemModule); | ||
|
|
||
| _testModule = systemModule; | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("SimpleByteClass")] | ||
| [InlineData("SimpleInt16Class")] | ||
| [InlineData("SimpleInt32Class")] | ||
| [InlineData("SimpleInt64Class")] | ||
| [InlineData("ExplicitByteBase")] | ||
| [InlineData("ExplicitInt16Base")] | ||
| [InlineData("ExplicitInt32Base")] | ||
| [InlineData("ExplicitInt64Base")] | ||
| [InlineData("SequentialByteBase")] | ||
| [InlineData("SequentialInt16Base")] | ||
| [InlineData("SequentialInt32Base")] | ||
| [InlineData("SequentialInt64Base")] | ||
| public void IsZeroSizedReferenceType_NonEmptyType_ReturnsFalse(string className) | ||
| { | ||
| DefType nonEmptyClass = _testModule.GetType("Marshalling", className); | ||
| Assert.False(nonEmptyClass.IsZeroSizedReferenceType); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("SimpleEmptyClass")] | ||
| [InlineData("ExplicitEmptyBase")] | ||
| [InlineData("ExplicitEmptySizeZeroBase")] | ||
| [InlineData("SequentialEmptyBase")] | ||
| public void IsZeroSizedReferenceType_EmptyType_ReturnsTrue(string className) | ||
| { | ||
| DefType emptyClass = _testModule.GetType("Marshalling", className); | ||
| Assert.True(emptyClass.IsZeroSizedReferenceType); | ||
| } | ||
| } | ||
| } |
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
83 changes: 83 additions & 0 deletions
83
src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/MarshalUtilsTests.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,83 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Internal.TypeSystem; | ||
| using Internal.TypeSystem.Interop; | ||
|
|
||
| using Xunit; | ||
|
|
||
| namespace TypeSystemTests | ||
| { | ||
| public class MarshalUtilsTests | ||
| { | ||
| private TestTypeSystemContext _context; | ||
| private ModuleDesc _testModule; | ||
|
|
||
| public MarshalUtilsTests() | ||
| { | ||
| _context = new TestTypeSystemContext(TargetArchitecture.X64); | ||
| var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly"); | ||
| _context.SetSystemModule(systemModule); | ||
|
|
||
| _testModule = systemModule; | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(WellKnownType.Void)] | ||
| [InlineData(WellKnownType.Boolean)] | ||
| [InlineData(WellKnownType.Char)] | ||
| [InlineData(WellKnownType.SByte)] | ||
| [InlineData(WellKnownType.Byte)] | ||
| [InlineData(WellKnownType.Int16)] | ||
| [InlineData(WellKnownType.UInt16)] | ||
| [InlineData(WellKnownType.Int32)] | ||
| [InlineData(WellKnownType.UInt32)] | ||
| [InlineData(WellKnownType.Int64)] | ||
| [InlineData(WellKnownType.UInt64)] | ||
| [InlineData(WellKnownType.IntPtr)] | ||
| [InlineData(WellKnownType.UIntPtr)] | ||
| [InlineData(WellKnownType.Single)] | ||
| [InlineData(WellKnownType.Double)] | ||
| [InlineData(WellKnownType.RuntimeFieldHandle)] | ||
| [InlineData(WellKnownType.RuntimeTypeHandle)] | ||
| [InlineData(WellKnownType.RuntimeMethodHandle)] | ||
| public void IsBlittableType_BilittableWellKnownTypes_ReturnsTrue(WellKnownType type) => | ||
| Assert.True(MarshalUtils.IsBlittableType(_context.GetWellKnownType(type))); | ||
|
|
||
| [Theory] | ||
| [InlineData(WellKnownType.String)] | ||
| [InlineData(WellKnownType.ValueType)] | ||
| [InlineData(WellKnownType.Enum)] | ||
| [InlineData(WellKnownType.Array)] | ||
| [InlineData(WellKnownType.MulticastDelegate)] | ||
| [InlineData(WellKnownType.Exception)] | ||
| [InlineData(WellKnownType.Object)] | ||
| public void IsBlittableType_NonBilittableWellKnownTypes_ReturnsFalse(WellKnownType type) => | ||
| Assert.False(MarshalUtils.IsBlittableType(_context.GetWellKnownType(type))); | ||
|
|
||
am11 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [Theory] | ||
| [InlineData("ClassWithExplicitByteBase")] | ||
| [InlineData("ClassWithExplicitInt16Base")] | ||
| [InlineData("ClassWithExplicitInt32Base")] | ||
| [InlineData("ClassWithExplicitInt64Base")] | ||
| [InlineData("ClassWithSequentialByteBase")] | ||
| [InlineData("ClassWithSequentialInt16Base")] | ||
| [InlineData("ClassWithSequentialInt32Base")] | ||
| [InlineData("ClassWithSequentialInt64Base")] | ||
| public void IsBlittableType_TypeWithBlittableBase_ReturnsTrue(string className) | ||
| { | ||
| TypeDesc classWithBlittableBase = _testModule.GetType("Marshalling", className); | ||
| Assert.True(MarshalUtils.IsBlittableType(classWithBlittableBase)); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("ClassWithExplicitEmptyBase")] | ||
| [InlineData("ClassWithExplicitEmptySizeZeroBase")] | ||
| [InlineData("ClassWithSequentialEmptyBase")] | ||
| public void IsBlittableType_TypeWithEmptyBase_ReturnsFalse(string className) | ||
| { | ||
| TypeDesc classWithEmptyBase = _testModule.GetType("Marshalling", className); | ||
| Assert.False(MarshalUtils.IsBlittableType(classWithEmptyBase)); | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.