Bug 56081

Summary: Returning a valuetype from an async method with an awaited parameter yields a Mono.CSharp.InternalErrorException: Await yields with non-empty stack
Product: [Mono] Compilers Reporter: tyler
Component: C#Assignee: Marek Safar <masafa>
Severity: normal CC: mono-bugs+mono
Priority: ---    
Version: 4.8.0 (C9)   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Sample solution attached detailing the compiler crash

Description tyler 2017-05-07 09:30:24 UTC
Created attachment 21992 [details]
Sample solution attached detailing the compiler crash

Using Mono JIT compiler version 4.8.0 (Stable Mon Feb 27 08:30:18 UTC 2017)

Sample project attached with a very isolated reproducible example.  Either build the solution using xbuild or use the provided commandline to compile it:

> mcs /noconfig /debug:full /debug+ /optimize- /out:obj/Debug/CrashTest.dll A.cs B.cs Properties/AssemblyInfo.cs ValueType.cs obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs /target:library /define:"DEBUG;TRACE" /nostdlib /platform:AnyCPU /reference:/usr/lib/mono/4.5-api/System.dll /reference:/usr/lib/mono/4.5-api/System.Data.dll /reference:/usr/lib/mono/4.5-api/System.Xml.dll /reference:/usr/lib/mono/4.5-api/System.Core.dll /reference:/usr/lib/mono/4.5-api//mscorlib.dll /warn:4

The stacktrace is long and is ommitted in this report for brevity.  A full copy of the stderr of the compiler is contained in crash.log in the project tarball. Compiling an async method which returns a Task<struct> crashes the mono compiler when the results of an await is used as a parameter to the constructor of another value type inline without the use of a temporary local for storage.

The offending line is here in A.cs:18:

> return new ValueType(local1, await b.ProduceStructure(input1, input2));

b.ProduceStructure produces a Task<long>.  If I set the result of the awaited b.ProduceStructure is set to a local the compiler will emit successfully, so this is able to be fairly easily worked around, alas not a huge priority.

I feel that this is loosely related to #42224 - but was marked resolved in 4.6/stable and it is reproducible for me.

Thanks for your time in looking at this!
Comment 1 Marek Safar 2017-05-26 16:31:09 UTC
Fixed in master and 2017-04 branch