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)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

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