Bug 33138 - Stackallocing a zero-length array and assigning doesn't result in NullReferenceException
Summary: Stackallocing a zero-length array and assigning doesn't result in NullReferen...
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-08-15 19:45 UTC by Alexander Köplinger
Modified: 2016-04-19 01:17 UTC (History)
4 users (show)

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:

Description Alexander Köplinger 2015-08-15 19:45:17 UTC
I ran the JIT CodeGen bringup tests from CoreCLR and one of them failed (tests/src/JIT/CodeGenBringUpTests/Localloc.cs).

Reduced to the following code:

> using System;
> public class Program
> {
> 	public static void Main()
> 	{
> 		try {
> 			unsafe {
> 				byte* a = stackalloc byte[0];
> 				*a = 0;
> 			}
> 		}
> 		catch (Exception) {
> 			Console.WriteLine("Catched Exception");
> 		}
> 		Console.WriteLine("Hello");
> 	}
> }

Running it on MS.NET prints

> Catched Exception
> Hello

Running it on Mono prints

> Hello

Removing the try-catch results in a NullReferenceException on MS.NET and a segfault on Mono.
Comment 1 Alexander Köplinger 2015-08-17 11:47:30 UTC
I've now ran all of the CoreCLR tests and there are a bunch of other failures apart from this, so I refrained from filing tickets for now: https://github.com/mono/mono/pull/1985
Comment 2 Zoltan Varga 2015-08-17 14:11:22 UTC
Supporting this would require adding checks to localloc, slowing it down for little gain.
Comment 3 Alexander Köplinger 2015-08-17 18:14:41 UTC
I'm fine with WontFix as a resolution if you think fixing it adds too much overhead :)
Comment 4 Alexander Köplinger [MSFT] 2016-04-19 01:17:13 UTC
Disabled the test in https://github.com/mono/coreclr/commit/b05c242a59eab1c4ea2803960c8065167308546d.