Bug 56081 - Returning a valuetype from an async method with an awaited parameter yields a Mono.CSharp.InternalErrorException: Await yields with non-empty stack
Summary: Returning a valuetype from an async method with an awaited parameter yields a...
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 4.8.0 (C9)
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2017-05-07 09:30 UTC by tyler
Modified: 2017-05-26 16:31 UTC (History)
1 user (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Sample solution attached detailing the compiler crash (3.35 KB, application/gzip)
2017-05-07 09:30 UTC, tyler
Details

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 4.8.0.495/e4a3cf3 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

Note You need to log in before you can comment on or make changes to this bug.