Bug 28774

Summary: mcs crashes with stack overflow when compiling class with Lazy<T> and stackalloc byte[]
Product: [Mono] Compilers Reporter: Alexander Köplinger <alex.koeplinger>
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+mono
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Tags: Is this bug a regression?: ---
Last known good build:

Description Alexander Köplinger 2015-04-04 15:29:55 UTC
The following code makes mcs crash during compilation with a stack overflow:

> using System;
> using System.Runtime.InteropServices;
> 
> class Test
> {
>     Lazy<string> x = new Lazy<string>(() =>
>     {
>         unsafe
>         {
>             byte* buffer = stackalloc byte[8192];
>         }
>         return "";
>     });
> }

Error:

> $ mcs /t:library /unsafe test.cs
> Stack overflow: IP: 0x61ca8c, fault addr: (nil)
> Stacktrace:
>   at <unknown> <0xffffffff>
>   at Mono.CSharp.Expression.Clone (Mono.CSharp.CloneContext) <0x00016>
>   <...>
>   at Mono.CSharp.StackAlloc.CloneTo (Mono.CSharp.CloneContext,Mono.CSharp.Expression) <0x00083>
>   at Mono.CSharp.Expression.Clone (Mono.CSharp.CloneContext) <0x0005a>
>   at Mono.CSharp.StackAlloc.CloneTo (Mono.CSharp.CloneContext,Mono.CSharp.Expression) <0x00083>
>   at Mono.CSharp.Expression.Clone (Mono.CSharp.CloneContext) <0x0005a>
>   at Mono.CSharp.StackAlloc.CloneTo (Mono.CSharp.CloneContext,Mono.CSharp.Expression) <0x00083>
>   at Mono.CSharp.Expression.Clone (Mono.CSharp.CloneContext) <0x0005a>
>   at Mono.CSharp.StackAlloc.CloneTo (Mono.CSharp.CloneContext,Mono.CSharp.Expression) <0x00083>
>   at Mono.CSharp.Expression.Clone (Mono.CSharp.CloneContext) <0x0005a>
>   at Mono.CSharp.StackAlloc.CloneTo (Mono.CSharp.CloneContext,Mono.CSharp.Expression) <0x00083>
>   at Mono.CSharp.Expression.Clone (Mono.CSharp.CloneContext) <0x0005a>
>   at Mono.CSharp.StackAlloc.CloneTo (Mono.CSharp.CloneContext,Mono.CSharp.Expression) <0x00083>
>   at Mono.CSharp.Expression.Clone (Mono.CSharp.CloneContext) <0x0005a>
>   at Mono.CSharp.StackAlloc.CloneTo (Mono.CSharp.CloneContext,Mono.CSharp.Expression) <0x00083>
>   ... and so on ...

Tried on both 3.12 and master.
Comment 1 Marek Safar 2015-04-07 10:35:32 UTC
Fixed in master