[Mono-list] Coding advice before I raise a bug

David Burnett vargol at ntlworld.com
Thu Jun 12 18:45:28 UTC 2014


On 12/06/2014 16:12, Edward Ned Harvey (mono) wrote:
>> From: mono-list-bounces at lists.ximian.com [mailto:mono-list-
>> bounces at lists.ximian.com] On Behalf Of David Burnett
>>
>> I may have found a compiler bug, but as I'm fairly new to c# I thought I'd
>
> First things first, how can we recreate the bug?  I tried some rudimentary testing based on the code you posted, and I failed to get the described result.  In all the cases I tried, I got x += x behaving as you would expect it to behave.  The same as x *= 2 (for ints between 1 and 2047).
>
> What version of mono are you using?
>


Macintosh:Release vargol$ mono --version
Mono JIT compiler version 3.2.7 ((no/40f92d5 Thu Feb  6 18:29:16 EST 2014)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           normal
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  x86
	Disabled:      none
	Misc:          softdebug
	LLVM:          yes(3.4svn-mono-(no/e656cac)
	GC:            sgen


running on OSX 10.6.8, 32 bit edition.

On advice of Eric Zeitler at gmail.com I've run monodis on the fixed and 'broken'
versions of the Assembly and the il created looks valid the diff is below.
I'm by no means an expert I'm assuming ldloc.0 twice followed by add
is loading median into two registers and adding.


*** 33324,33331 ****
   	IL_0022:  bgt IL_0036
   
   	IL_0027:  ldloc.0
! 	IL_0028:  ldc.i4.2
! 	IL_0029:  mul
   	IL_002a:  stloc.0
   	IL_002b:  ldloc.0
   	IL_002c:  ldarg.3
--- 33324,33331 ----
   	IL_0022:  bgt IL_0036
   
   	IL_0027:  ldloc.0
! 	IL_0028:  ldloc.0
! 	IL_0029:  add
   	IL_002a:  stloc.0
   	IL_002b:  ldloc.0
   	IL_002c:  ldarg.3


So its not a compiler bug, but maybe run time or JIT compiler bug.

I've tried running the bad version using --llvm and it seems to work correctly.
A fresh compile against .net also works correctly.

I've created a branch on my github repository holding the broken code and an example file.

The repository is

https://github.com/Vargol/PhotonPump.git

The branch is mono_bug

to run the example

cd to the PhotonPump/SunflowSharp.Test/bin/Release directory and run
mono SunflowSharp.Test.exe ../../../examples/particle_chau.sc

It should eventually fail

...
LIGHT  info: Balancing caustics photon map ...
index 1, start 1, end 3
4 median 1
3 median 1
index 3, start 2, end 3
4 median 1
System.IndexOutOfRangeException: Array index is out of range.
...
followed by a stack crawl


A successful run looks like

...
LIGHT  info: Balancing caustics photon map ...
index 1, start 1, end 3
4 median 1
3 median 2
LIGHT  info: Caustic photon map:
...
followed by much more


I guess however that this is off to mono-devel-list and a proper bug report.
and I've got a better test case to build.

Dave












More information about the Mono-list mailing list