Bug 20603

Summary: Unreachable local variable declaration causing MCS to crash
Product: [Mono] Compilers Reporter: neil.sculthorpe
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+mono
Priority: ---    
Version: 3.2.x   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Minimal bug file causing MCS to crash

Description neil.sculthorpe 2014-06-15 13:56:32 UTC
Created attachment 7078 [details]
Minimal bug file causing MCS to crash

Compiling the following problem,

class Program {
  public static void Main() {
         goto L1;
         int z;
     L1: z = 3;
  }
}

causes the MCS compiler (v3.2.8.0, on Ubuntu 14.04) to crash with the following error:

Unhandled Exception:
Mono.CSharp.InternalErrorException: Labels.cs(3,22): Program.Main() ---> Mono.CSharp.InternalErrorException: Labels.cs(3,29): ---> System.NullReferenceException: Object reference not set to an instance of an object

However, a similar program compiles and runs successfully:

class Program {
  public static void Main() {
         int x = 7;
         if (x > 0) {goto L1;}
         int z;
     L1: z = 3;
         System.Console.WriteLine(z);
  }
}

I speculate that in the former program, an optimisation is deleting "int z" as unreachable-code.  In the latter program, making "x" a "const" variable also triggers the error.
Comment 1 Marek Safar 2014-06-16 05:58:29 UTC
Fixed in master