forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump Explicit-layout value types with no fields to at minimum 1 byte …
…size. (dotnet#63975)
- Loading branch information
1 parent
6f8d8b2
commit 826e03e
Showing
3 changed files
with
73 additions
and
0 deletions.
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
60 changes: 60 additions & 0 deletions
60
src/tests/Loader/classloader/explicitlayout/Regressions/empty/explicitStruct_empty.cs
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,60 @@ | ||
// 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; | ||
using System.Runtime.InteropServices; | ||
using Xunit; | ||
|
||
[StructLayout(LayoutKind.Explicit)] | ||
public struct S | ||
{ | ||
} | ||
|
||
[StructLayout(LayoutKind.Explicit)] | ||
public struct S2 | ||
{ | ||
} | ||
|
||
[StructLayout(LayoutKind.Explicit)] | ||
public class C | ||
{ | ||
} | ||
|
||
[StructLayout(LayoutKind.Explicit)] | ||
public class C2 | ||
{ | ||
} | ||
|
||
public class Test_explicitStruct_empty | ||
{ | ||
// Mark as no-inlining so any test failures will show the right stack trace even after | ||
// we consolidate test assemblies. | ||
[Fact] | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
public static void EmptyExplicitStructCanBeLoadedAndCreated() | ||
{ | ||
S s = new S(); | ||
} | ||
|
||
[Fact] | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
public static void EmptyExplicitStructCanBeLoadedAndCreatedThroughReflection() | ||
{ | ||
object s = Activator.CreateInstance(Type.GetType("S2")); | ||
} | ||
|
||
[Fact] | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
public static void EmptyExplicitClassCanBeLoadedAndCreated() | ||
{ | ||
C c = new C(); | ||
} | ||
|
||
[Fact] | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
public static void EmptyExplicitClassCanBeLoadedAndCreatedThroughReflection() | ||
{ | ||
object c = Activator.CreateInstance(Type.GetType("C2")); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/tests/Loader/classloader/explicitlayout/Regressions/empty/explicitStruct_empty.csproj
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,5 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<ItemGroup> | ||
<Compile Include="explicitStruct_empty.cs" /> | ||
</ItemGroup> | ||
</Project> |