Bug 35401

Summary: mcs generates incorrect code for CoreCLR try-finally03.cs and try-finally-struct03.cs test cases
Product: [Mono] Compilers Reporter: Alexander Köplinger [MSFT] <alkpli>
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:
Attachments: try-finally03.cs and try-finally-struct03.cs

Description Alexander Köplinger [MSFT] 2015-10-30 11:08:59 UTC
Created attachment 13585 [details]
try-finally03.cs and try-finally-struct03.cs

Compile the attached files (taken from the open source MS CoreCLR test suite) with mcs.

If you run the assembly produced by mcs with .NET or Mono, they fail (.NET prints some output, Mono just crashes).

Compile the files with csc/roslyn, now they both work on .NET and Mono.

A quick IL diff showed that csc emits an additional nop:

IL from mcs:
>.class public auto ansi beforefieldinit RefX0
>       extends [mscorlib]System.Object
>{
>  .method public hidebysig specialname rtspecialname 
>          instance void  .ctor() cil managed
>  {
>    // Code size       7 (0x7)
>    .maxstack  8
>    IL_0000:  ldarg.0
>    IL_0001:  call       instance void [mscorlib]System.Object::.ctor()
>    IL_0006:  ret
>  } // end of method RefX0::.ctor
>
>} // end of class RefX0

IL from csc:

>.class public auto ansi beforefieldinit RefX0
>       extends [mscorlib]System.Object
>{
>  .method public hidebysig specialname rtspecialname 
>          instance void  .ctor() cil managed
>  {
>    // Code size       8 (0x8)
>    .maxstack  8
>    IL_0000:  ldarg.0
>    IL_0001:  call       instance void [mscorlib]System.Object::.ctor()
>***    IL_0006:  nop
>    IL_0007:  ret
>  } // end of method RefX0::.ctor
>
>} // end of class RefX0


Reproduces on Mono 4.0 and master.
Comment 1 Marek Safar 2015-11-02 08:45:46 UTC
Fixed in master