inversionhourglass/Rougamo

System.InvalidProgramException

inversionhourglass opened this issue · 1 comments

// it will raise a System.InvalidProgramException
await Test.TestAsync();

[Test]
public static async Task TestAsync()
{
    try
    {
        await Task.Yield();
    }
    catch (Exception ex)
    {
        throw;
    }
}

class TestAttribute : MoAttribute
{
    public override void OnEntry(MethodContext context)
    {
        Console.WriteLine("onentry");
    }
}

该问题仅在debug模式下出现,主要问题在于这段代码在debug模式下产生了一段无意义的分支判断片段,肉夹馍的IL优化逻辑对此类代码片段处理存在bug,删除了分支判断跳转目标IL

private void MoveNext()
{
	int num = <>1__state;
	try
	{
                // 无意义分支判断代码片段
		if (num != 0)
		{
		}
		try
		{
			YieldAwaitable.YieldAwaiter awaiter;
			if (num != 0)
			{
				awaiter = Task.Yield().GetAwaiter();
				if (!awaiter.IsCompleted)
				{
					num = (<>1__state = 0);
					<>u__1 = awaiter;
					<XAsync>d__1 stateMachine = this;
					<>t__builder.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine);
					return;
				}
			}
			else
			{
				awaiter = <>u__1;
				<>u__1 = default(YieldAwaitable.YieldAwaiter);
				num = (<>1__state = -1);
			}
			awaiter.GetResult();
		}
		catch (Exception ex)
		{
			<ex>5__1 = ex;
			throw;
		}
	}
	catch (Exception ex)
	{
		<>1__state = -2;
		<>t__builder.SetException(ex);
		return;
	}
	<>1__state = -2;
	<>t__builder.SetResult();
}