Bug 29506

Summary: invalid IL generated for async method
Product: [Mono] Compilers Reporter: Zoltan Varga <vargaz>
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: bugzilla.xamarin, jesse.attas, mono-bugs+mono
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Bug Depends on:    
Bug Blocks: 29281    

Description Zoltan Varga 2015-04-28 19:12:35 UTC
In the testcase below, mcs generates invalid il for the '<OnDoWorkAsync>c__AnonStorey7'::'<>m__0' method:

        .locals init (valuetype ATask/'<OnDoWorkAsync>c__async4'/'<OnDoWorkAsync>c__AnonStorey7'/'<OnDoWorkAsync>c__async6' V_0)
        IL_0000:  ldloca.s   V_0
        IL_0002:  ldloc.0
        IL_0003:  stfld      valuetype ATask/'<OnDoWorkAsync>c__async0' ATask/'<OnDoWorkAsync>c__async4'/'<OnDoWorkAsync>c__AnonStorey7'/'<OnDoWorkAsync>c__async6'::'<>f__ref$0'

I tries to store local 0 into a field of itself, which has a different type.

Testcase:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

public static class ExceptionHelper
{
	public static async Task ConditionalCatchExceptThreadAbortAsync(Func<Task> funcTask, Action<Exception> conditionalCatchAction, Action finallyAction) {
		return;
	}
}

class ATask
{
	private readonly object _asyncTaskCancellationSource;

	private readonly object aname;

	protected async Task<bool> OnDoWorkAsync()
	{
		await ExceptionHelper.ConditionalCatchExceptThreadAbortAsync(
                    async () =>
                    {
                        if (_asyncTaskCancellationSource != null)
                        {
                            Tuple<object, object, object, Action> item = null;

                            await ExceptionHelper.ConditionalCatchExceptThreadAbortAsync(
                                async () =>
                                {
                                    try
                                    {
                                        Console.WriteLine(aname);
                                    }
                                    catch (OperationCanceledException)
                                    {
                                    }
                                },
                                (e) =>
                                {
                                    if (item.Item1 != null)
                                    {
                                    }
                                },
                                () =>
                                {
                                });
                        }
                    },
                (e) =>
                {
                },
                () =>
                {
                });

                return true;
            }
}

public class Tests
{
	public static void Main (String[] args) {
	}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Comment 1 Zoltan Varga 2015-04-28 19:12:56 UTC
This happens with 4.0/master.
Comment 2 Marek Safar 2015-05-05 09:02:32 UTC
Fixed in master