Skip to content

Stack allocated boxes end up address exposed #104250

@hez2010

Description

@hez2010

Description

Repro:

using System.Globalization;
using System.Runtime.CompilerServices;

Test();

static void Test()
{
	PrintNegatedBoolean(true);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void PrintNegatedBoolean(bool b)
{
	var converted = new MyConverter().Convert(b, typeof(bool), null!, null!);
	if (converted is bool convertedBool)
	{
		Console.WriteLine(convertedBool);
	}
}

class MyConverter : IValueConverter
{
	public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
	{
		if (value is bool b && targetType == typeof(bool))
		{
			return !b;
		}

		return Throw();
	}

	private object Throw() => throw new NotSupportedException();

	public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
	{
		throw new NotImplementedException();
	}
}

public interface IValueConverter
{
	object Convert(object value, Type targetType, object parameter, CultureInfo culture);
	object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture);
}

Codegen for Test (tier 1):

G_M000_IG01:                ;; offset=0x0000
       push     rbx
       sub      rsp, 48

G_M000_IG02:                ;; offset=0x0005
       vxorps   xmm0, xmm0, xmm0
       vmovups  xmmword ptr [rsp+0x20], xmm0
       mov      rcx, 0x7FFA2F1B2D40
       mov      qword ptr [rsp+0x20], rcx
       mov      byte  ptr [rsp+0x28], 0
       lea      rbx, [rsp+0x20]
       test     rbx, rbx
       je       SHORT G_M000_IG05

G_M000_IG03:                ;; offset=0x002D
       mov      rdx, qword ptr [rbx]
       cmp      rdx, rcx
       je       SHORT G_M000_IG07
       jmp      SHORT G_M000_IG05

G_M000_IG04:                ;; offset=0x0037
       movzx    rcx, byte  ptr [rbx+0x08]
       call     [System.Console:WriteLine(ubyte)]

G_M000_IG05:                ;; offset=0x0041
       nop

G_M000_IG06:                ;; offset=0x0042
       add      rsp, 48
       pop      rbx
       ret

G_M000_IG07:                ;; offset=0x0048
       cmp      rdx, rcx
       je       SHORT G_M000_IG04

G_M000_IG08:                ;; offset=0x004D
       call     CORINFO_HELP_UNBOX_TYPETEST
       jmp      SHORT G_M000_IG04

Configuration

53a8a01

/cc: @AndyAyersMS

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMItenet-performancePerformance related issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions