Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref local of jagged array leads to InvalidProgramException #10101

Closed
lambdageek opened this issue Aug 14, 2018 · 4 comments

Comments

@lambdageek
Copy link
Member

@lambdageek lambdageek commented Aug 14, 2018

If object f has a field a of type int[][], then ref int[] r = ref f.a[1]; leads to an InvalidProgramException

Steps to Reproduce

  1. csc Foo.cs
  2. mono Foo.exe

Foo.cs:

using System;

public class Foo {
	public int[][] a;

	public Foo () {
		a = new int[][]{
			new int[]{1,2,3}, 
			new int[]{4,5,6},
			new int[]{7,8,9}
		};
	}

	public static void Main ()
	{
		var f = new Foo ();

		Console.WriteLine ($"{f.a[1][1]}");

		ref int[] r = ref f.a[1];

		bar (ref r);

		Console.WriteLine ($"{f.a[1][1]}");
	}

	public static void bar (ref int[] x)
	{
		x = new int[]{11,12,13};
	}
}

Current Behavior

Unhandled Exception:
System.InvalidProgramException: Invalid IL code in Foo:Main (): IL_0030: stloc.1   


[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidProgramException: Invalid IL code in Foo:Main (): IL_0030: stloc.1   

Expected Behavior

5
12

On which platforms did you notice this

[x] macOS
[ ] Linux
[ ] Windows

Version Used:

Mono JIT compiler version 5.18.0.20 (2018-08/64e9b1a9839 Mon Aug 13 14:14:00 EDT 2018)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	Interpreter:   yes
	LLVM:          yes(600)
	Suspend:       hybrid
	GC:            sgen (concurrent by default)

Also fails with mono master.
Also fails with 2018-02:

Mono JIT compiler version 5.12.0.301 (2018-02/4fe3280bba1 Fri Jul 20 08:25:42 EDT 2018)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           normal
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	Interpreter:   yes
	LLVM:          yes(3.6.0svn-mono-master/8b1520c8aae)
	GC:            sgen (concurrent by default)

Originally reported as xamarin/xamarin-android#2059

@lambdageek

This comment has been minimized.

Copy link
Member Author

@lambdageek lambdageek commented Aug 14, 2018

The relevant bit of IL is

	.locals init (
		class Foo	V_0,
		int32[]&	V_1)

	...

	IL_0025:  ldfld int32[][] Foo::a
	IL_002a:  ldc.i4.1 
	IL_002b:  ldelema int32[]
	IL_0030:  stloc.1 
	IL_0031:  ldloc.1 
	IL_0032:  call void class Foo::bar([out] int32[]&)
@kumpera kumpera self-assigned this Aug 24, 2018
@marek-safar

This comment has been minimized.

Copy link
Member

@marek-safar marek-safar commented Aug 27, 2018

Do we have any estimate on this one ?

@kumpera

This comment has been minimized.

Copy link
Member

@kumpera kumpera commented Aug 27, 2018

Probably a day of work. I have't scheduled it though.

@joncham

This comment has been minimized.

Copy link
Contributor

@joncham joncham commented Feb 21, 2019

@marek-safar marek-safar added this to the 2019-02 (6.0.xx) milestone Feb 21, 2019
vargaz added a commit to vargaz/mono that referenced this issue Feb 21, 2019
vargaz added a commit to vargaz/mono that referenced this issue Feb 27, 2019
lewurm added a commit that referenced this issue Feb 27, 2019
…class not its element class. (#13134)

Fixes #10101.
@marek-safar marek-safar removed this from the 2019-02 (6.0.xx) milestone Mar 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.