Skip to content

Commit 0bba685

Browse files
Failfast from async inst+unbox thunks (#121812)
and block tests on ActiveIssue. FailFast is better than memory corruptions.
1 parent 4ab6b05 commit 0bba685

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.BoxedTypes.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,16 @@ public override MethodIL EmitIL()
423423
Array.Empty<object>());
424424
}
425425

426+
// TODO: (async) https://github.com/dotnet/runtime/issues/121781
427+
if (_targetMethod.IsAsyncCall())
428+
{
429+
ILEmitter e = new ILEmitter();
430+
ILCodeStream c = e.NewCodeStream();
431+
432+
c.EmitCallThrowHelper(e, Context.GetCoreLibEntryPoint("System.Runtime"u8, "InternalCalls"u8, "RhpFallbackFailFast"u8, null));
433+
return e.Link(this);
434+
}
435+
426436
// Generate the unboxing stub. This loosely corresponds to following C#:
427437
// return BoxedValue.InstanceMethod(this.m_pEEType, [rest of parameters])
428438

@@ -520,6 +530,16 @@ public override MethodIL EmitIL()
520530
Array.Empty<object>());
521531
}
522532

533+
// TODO: (async) https://github.com/dotnet/runtime/issues/121781
534+
if (_targetMethod.IsAsyncCall())
535+
{
536+
ILEmitter e = new ILEmitter();
537+
ILCodeStream c = e.NewCodeStream();
538+
539+
c.EmitCallThrowHelper(e, Context.GetCoreLibEntryPoint("System.Runtime"u8, "InternalCalls"u8, "RhpFallbackFailFast"u8, null));
540+
return e.Link(this);
541+
}
542+
523543
// Generate the unboxing stub. This loosely corresponds to following C#:
524544
// return BoxedValue.InstanceMethod([rest of parameters])
525545

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.InterfaceThunks.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,16 @@ public override string DiagnosticName
217217

218218
public override MethodIL EmitIL()
219219
{
220+
// TODO: (async) https://github.com/dotnet/runtime/issues/121781
221+
if (_targetMethod.IsAsyncCall())
222+
{
223+
ILEmitter e = new ILEmitter();
224+
ILCodeStream c = e.NewCodeStream();
225+
226+
c.EmitCallThrowHelper(e, Context.GetCoreLibEntryPoint("System.Runtime"u8, "InternalCalls"u8, "RhpFallbackFailFast"u8, null));
227+
return e.Link(this);
228+
}
229+
220230
// Generate the instantiating stub. This loosely corresponds to following C#:
221231
// return Interface.Method(this, GetOrdinalInterface(this.m_pEEType, Index), [rest of parameters])
222232

src/tests/async/inst-unbox-thunks/inst-unbox-thunks.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,28 @@ public static void ManyArgUnbox()
115115
}
116116

117117
[Fact]
118+
[ActiveIssue("https://github.com/dotnet/runtime/issues/121781", typeof(TestLibrary.Utilities), nameof(TestLibrary.Utilities.IsNativeAot))]
118119
public static void NoArgGenericUnbox()
119120
{
120121
Assert.Equal("System.String", CallStruct1M0().Result);
121122
}
122123

123124
[Fact]
125+
[ActiveIssue("https://github.com/dotnet/runtime/issues/121781", typeof(TestLibrary.Utilities), nameof(TestLibrary.Utilities.IsNativeAot))]
124126
public static void ManyArgGenericUnbox()
125127
{
126128
Assert.Equal("System.String", CallStruct1M1().Result);
127129
}
128130

129131
[Fact]
132+
[ActiveIssue("https://github.com/dotnet/runtime/issues/121781", typeof(TestLibrary.Utilities), nameof(TestLibrary.Utilities.IsNativeAot))]
130133
public static void NoArgGenericInstantiating()
131134
{
132135
Assert.Equal("System.String", CallStruct1M0b().Result);
133136
}
134137

135138
[Fact]
139+
[ActiveIssue("https://github.com/dotnet/runtime/issues/121781", typeof(TestLibrary.Utilities), nameof(TestLibrary.Utilities.IsNativeAot))]
136140
public static void ManyArgGenericInstantiating()
137141
{
138142
Assert.Equal("System.String", CallStruct1M1b().Result);
@@ -183,4 +187,48 @@ public static void ManyArgGVM()
183187
{
184188
Assert.Equal("System.String", CallClass2M1().Result);
185189
}
190+
191+
interface I3<T>
192+
{
193+
async Task<string> M0()
194+
{
195+
await Task.Yield();
196+
return typeof(T).ToString();
197+
}
198+
199+
async Task<string> M1(object a0, object a1, object a2, object a3, object a4, object a5, object a6, object a7, object a8)
200+
{
201+
await Task.Yield();
202+
return typeof(T).ToString();
203+
}
204+
}
205+
206+
class Class3 : I3<string>;
207+
208+
static I3<string> o3;
209+
static async Task<string> CallClass3M0()
210+
{
211+
o3 = new Class3();
212+
return await o3.M0();
213+
}
214+
215+
static async Task<string> CallClass3M1()
216+
{
217+
o3 = new Class3();
218+
return await o3.M1(default, default, default, default, default, default, default, default, default);
219+
}
220+
221+
[Fact]
222+
[ActiveIssue("https://github.com/dotnet/runtime/issues/121781", typeof(TestLibrary.Utilities), nameof(TestLibrary.Utilities.IsNativeAot))]
223+
public static void NoArgDefaultMethod()
224+
{
225+
Assert.Equal("System.String", CallClass3M0().Result);
226+
}
227+
228+
[Fact]
229+
[ActiveIssue("https://github.com/dotnet/runtime/issues/121781", typeof(TestLibrary.Utilities), nameof(TestLibrary.Utilities.IsNativeAot))]
230+
public static void ManyArgDefaultMethod()
231+
{
232+
Assert.Equal("System.String", CallClass3M1().Result);
233+
}
186234
}

src/tests/async/inst-unbox-thunks/inst-unbox-thunks.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55
<ItemGroup>
66
<Compile Include="$(MSBuildProjectName).cs" />
77
</ItemGroup>
8+
<ItemGroup>
9+
<ProjectReference Include="$(TestLibraryProjectPath)" />
10+
</ItemGroup>
811
</Project>

0 commit comments

Comments
 (0)