Skip to content

Commit

Permalink
Fixed (Value)Task<T>-returning Setup/Cleanup methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
timcassell committed Mar 12, 2022
1 parent e004ec6 commit f52e351
Showing 1 changed file with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -959,25 +959,27 @@ private void EmitAwaitableSetupTeardown(
if (targetMethod == null)
throw new ArgumentNullException(nameof(targetMethod));

if (returnTypeInfo.WorkloadMethodReturnType == typeof(void))
{
ilBuilder.Emit(OpCodes.Ldarg_0);
}
/*
// call for instance void
// GlobalSetup();
IL_0000: ldarg.0
IL_0001: call instance void [BenchmarkDotNet]BenchmarkDotNet.Samples.SampleBenchmark::GlobalSetup()
IL_0001: ldfld class BenchmarkDotNet.Helpers.AwaitHelper BenchmarkDotNet.Helpers.Runnable_0::awaitHelper
*/
ilBuilder.Emit(OpCodes.Ldarg_0);
ilBuilder.Emit(OpCodes.Ldfld, awaitHelperField);
/*
// call for static with return value
// call for instance
// GlobalSetup();
IL_0000: call string [BenchmarkDotNet]BenchmarkDotNet.Samples.SampleBenchmark::GlobalCleanup()
IL_0005: pop
IL_0006: ldarg.0
IL_0007: call instance void [BenchmarkDotNet]BenchmarkDotNet.Samples.SampleBenchmark::GlobalSetup()
*/
ilBuilder.Emit(OpCodes.Ldarg_0);
/*
IL_0026: ldarg.0
IL_0027: ldfld class BenchmarkDotNet.Helpers.AwaitHelper BenchmarkDotNet.Helpers.Runnable_0::awaitHelper
// call for static
// GlobalSetup();
IL_0006: call string [BenchmarkDotNet]BenchmarkDotNet.Samples.SampleBenchmark::GlobalCleanup()
*/
ilBuilder.Emit(OpCodes.Ldarg_0);
ilBuilder.Emit(OpCodes.Ldfld, awaitHelperField);
if (targetMethod.IsStatic)
{
ilBuilder.Emit(OpCodes.Call, targetMethod);
Expand All @@ -999,9 +1001,7 @@ private void EmitAwaitableSetupTeardown(
IL_000e: callvirt instance void BenchmarkDotNet.Helpers.AwaitHelper::GetResult(class [System.Private.CoreLib]System.Threading.Tasks.Task)
*/
ilBuilder.Emit(OpCodes.Callvirt, returnTypeInfo.GetResultMethod);

if (targetMethod.ReturnType != typeof(void))
ilBuilder.Emit(OpCodes.Pop);
ilBuilder.Emit(OpCodes.Pop);
}

private void EmitCtorBody()
Expand Down

0 comments on commit f52e351

Please sign in to comment.