Bug 19083

Summary: Bug in mini_emit_memset
Product: [Mono] Runtime Reporter: Bill Seurer <seurer>
Component: JITAssignee: Bugzilla <bugzilla>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+mono, mono-bugs+runtime, seurer, vargaz
Priority: ---    
Version: 3.2.x   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Tags: Is this bug a regression?: ---
Last known good build:

Description Bill Seurer 2014-04-16 09:49:54 UTC
The "case 8": code below can never be reached because the if statement preceding the switch will not allow sizes larger than 4 to enter the switch statement.  I noticed this in the code for mono-3.2.8 but it is also in mono-2.10.8 and probably other releases.

In mono/mini/method-to-ir.c:


static void
mini_emit_memset (MonoCompile *cfg, int destreg, int offset, int size, int val, int align)
{
	int val_reg;

	g_assert (val == 0);

	if (align == 0)
		align = 4;

	if ((size <= 4) && (size <= align)) {
		switch (size) {
		case 1:
			MONO_EMIT_NEW_STORE_MEMBASE_IMM (cfg, OP_STOREI1_MEMBASE_IMM, destreg, offset, val);
			return;
		case 2:
			MONO_EMIT_NEW_STORE_MEMBASE_IMM (cfg, OP_STOREI2_MEMBASE_IMM, destreg, offset, val);
			return;
		case 4:
			MONO_EMIT_NEW_STORE_MEMBASE_IMM (cfg, OP_STOREI4_MEMBASE_IMM, destreg, offset, val);
			return;
#if SIZEOF_REGISTER == 8
		case 8:
			MONO_EMIT_NEW_STORE_MEMBASE_IMM (cfg, OP_STOREI8_MEMBASE_IMM, destreg, offset, val);
			return;
#endif
		}
	}
...etc...
Comment 1 Zoltan Varga 2014-04-17 11:50:27 UTC
Fixed in master f287d3c95b3036b4dc2f969981a27acfe7821054. Thanks.