Bug 23283 - Invalid IL code in System.WindowsConsoleDriver:MoveBufferArea
Summary: Invalid IL code in System.WindowsConsoleDriver:MoveBufferArea
Status: RESOLVED NORESPONSE
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: 3.6.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-09-23 06:30 UTC by remirpan
Modified: 2017-07-12 23:01 UTC (History)
4 users (show)

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


Attachments
example (5.56 KB, application/octet-stream)
2014-09-23 06:30 UTC, remirpan
Details
mcs\class\corlib\System\Console.cs (139.55 KB, image/jpeg)
2014-09-25 06:32 UTC, remirpan
Details


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 NORESPONSE

Description remirpan 2014-09-23 06:30:49 UTC
Created attachment 8151 [details]
example

System.InvalidProgramException: Invalid IL code in System.WindowsConsoleDriver:MoveBufferArea (int,int,int,int,int,int,char,System.ConsoleColor,System.ConsoleColor): IL_00ac: stloc.s 5

// mcs\class\corlib\System\WindowsConsoleDriver.cs
public void MoveBufferArea (int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight,
			int targetLeft, int targetTop, Char sourceChar,
			ConsoleColor sourceForeColor, ConsoleColor sourceBackColor)
{
...
	CharInfo [] buffer = new CharInfo [sourceWidth * sourceHeight];
...
	// fixed (void *ptr = &buffer [0]) { <--- Invalid IL code ... stloc.s
	fixed (CharInfo *ptr = &buffer [0]) {
...
	}
...
}

// mono\mini\method-to-ir.c
int
mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_bblock, MonoBasicBlock *end_bblock, 
		   MonoInst *return_var, GList *dont_inline, MonoInst **inline_args, 
		   guint inline_offset, gboolean is_virtual_call)
{
///
/// if "(assembly->in_gac || assembly->image == mono_defaults.corlib)" then
///   dont_verify_stloc = 0
/// else
///   dont_verify_stloc = 1
///
...
	case CEE_STLOC_S:
		CHECK_OPSIZE (2);
		CHECK_STACK (1);
		--sp;
		CHECK_LOCAL (ip [1]);
///
/// if "fixed (void *ptr = &buffer[0])" then
///   (header->locals [ip [1]])->type = MONO_TYPE_I(0x18)
///   UNVERIFIED -> Invalid IL code in ... stloc.s
///
/// if "fixed (CharInfo *ptr = &buffer[0])" then
///   (header->locals [ip [1]])->type = MONO_TYPE_VALUETYPE(0x11)
///
		if (!dont_verify_stloc && target_type_is_incompatible (cfg, header->locals [ip [1]], *sp))
			UNVERIFIED;
		emit_stloc_ir (cfg, sp, header, ip [1]);
		ip += 2;
		inline_costs += 1;
		break;
...
}

//eof
Comment 1 Marek Safar 2014-09-24 07:32:33 UTC
I cannot see anything wrong with the code. Sample compiled with mcs runs on .net. I don't have working windows + mono setup to try it there as well.
Comment 2 remirpan 2014-09-25 06:30:00 UTC
new example

class Program
{
    static void Main(string[] args)
    {
        System.Console.Clear();
    }
}

add at mcs\class\corlib\System\Console.cs
	...
	unsafe public static partial class Console
	...
	static Console ()
	{
		byte[] buf = new byte[8];
		fixed (byte* ptr = &buf[0]) // <--- OK
		{
		}
		fixed (void* ptr = &buf[0]) // <--- Invalid IL code in System.Console:.cctor()
		{
		}
	...
	}

//eof
Comment 3 remirpan 2014-09-25 06:32:11 UTC
Created attachment 8183 [details]
mcs\class\corlib\System\Console.cs
Comment 4 Marek Safar 2014-09-26 03:54:41 UTC
I still cannot reproduce the issue. Trying your code with Mono 3.10 works as expected, no error.

class Program
{
    static void Main(string[] args)
    {
        Console.Clear();
    }
}

public static class Console
{
    static Console ()
    {
        byte[] buf = new byte[8];
        fixed (byte* ptr = &buf[0]) // <--- OK
        {
        }
        fixed (void* ptr = &buf[0]) // <--- Invalid IL code in
        {
        }
    }

    public static void Clear ()
    {

    }
}
Comment 5 Ludovic Henry 2017-07-12 23:01:57 UTC
Can you still reproduce with latest version of mono? If you can, please reopen and provide a repro case. Thank you