Bug 33573 - Function call in fixed get called 3 times.
Summary: Function call in fixed get called 3 times.
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 4.0.0
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2015-09-02 13:46 UTC by Florian Kummer
Modified: 2015-09-03 07:07 UTC (History)
2 users (show)

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


Attachments

Description Florian Kummer 2015-09-02 13:46:30 UTC
I use the following code:

==========================================
using System;

namespace Error {
  class MainClass {
    public static double[] GetTempBuffer() {
      Console.WriteLine("GetTempBuffer ... ");
      return new double[4];
    }

    public static void Main(string[] args) {
      unsafe {
        //double[] _dummy = GetTempBuffer(); // works
        //fixed(double* dummy = _dummy) {    // works
        fixed(double* dummy = GetTempBuffer()) {    // fails: ges called 3 times !!!!
        }
      }
    }
  }
}
=============================================

When i compile with mcs and execute I get the following output:
GetTempBuffer ... 
GetTempBuffer ... 
GetTempBuffer ... 

Compiling with csc under Windows gives the correct result for both, .NET and mono execution.
The problem seems to happen during compilation; the disassemble of the mcs looks as:

================================ 

.method public hidebysig static void  Main(string[] args) cil managed
{
  .entrypoint
  // Code size       45 (0x2d)
  .maxstack  2
  .locals init (float64* pinned V_0)
  IL_0000:  call       float64[] Error.MainClass::GetTempBuffer()
  IL_0005:  brfalse    IL_0016
  IL_000a:  call       float64[] Error.MainClass::GetTempBuffer()
  IL_000f:  ldlen
  IL_0010:  conv.i4
  IL_0011:  brtrue     IL_001d
  IL_0016:  ldc.i4.0
  IL_0017:  conv.u
  IL_0018:  br         IL_0028
  IL_001d:  call       float64[] Error.MainClass::GetTempBuffer()
  IL_0022:  ldc.i4.0
  IL_0023:  ldelema    [mscorlib]System.Double
  IL_0028:  stloc.0
  IL_0029:  ldc.i4.0
  IL_002a:  conv.u
  IL_002b:  stloc.0
  IL_002c:  ret
} // end of method MainClass::Main
=======================================================================
Comment 1 Florian Kummer 2015-09-03 05:48:07 UTC
*********$ mcs --version
Mono C# compiler version 4.0.3.0
Comment 2 Marek Safar 2015-09-03 07:07:02 UTC
Fixed in master and Mono 4.2

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