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

Incorrect IL generated for function pointer call with in parameter #47487

Closed
dgrunwald opened this issue Sep 5, 2020 · 0 comments
Closed

Incorrect IL generated for function pointer call with in parameter #47487

dgrunwald opened this issue Sep 5, 2020 · 0 comments
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Feature - Function Pointers Adding Function Pointers Urgency-Soon
Milestone

Comments

@dgrunwald
Copy link

Version Used: Visual Studio 2019 16.8.0 Preview 2.1

Steps to Reproduce:

    unsafe class Program
    {
        static void Main(string[] args)
        {
            delegate*<in int, ref char, void> F = &Test;
            char c = 'a';
            F(int.MaxValue, ref c);
        }

        public static void Test(in int b, ref char c)
        {
            Console.WriteLine($"b = {b}, c = {c}");
        }
    }

Expected Behavior:
b = 2147483647, c = a

Actual Behavior:

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at CSharpCore.Program.Test(Int32 ByRef, Char ByRef)
   at CSharpCore.Program.Main(System.String[])

The IL code passes int.MaxValue directly, when it should be passing the address of a temporary.

	IL_0000: nop
	IL_0001: ldarg.0
	IL_0002: ldfld method void *(uint8& modreq([System.Runtime]System.Runtime.InteropServices.InAttribute), char&) CSharpCore.FunctionPointersWithRefParams::F1 /* 04000003 */
	IL_0007: stloc.0
	IL_0008: ldc.i4.1
	IL_0009: ldarga.s c
	IL_000b: ldloc.0
	IL_000c: calli void(uint8& modreq([System.Runtime]System.Runtime.InteropServices.InAttribute), char&) /* 11000004 */
	IL_0011: nop
	IL_0012: ret

Note: removing the ref char c parameter causes the in int b parameter to be passed correctly.

@333fred 333fred self-assigned this Sep 9, 2020
@333fred 333fred added this to the 16.8 milestone Sep 9, 2020
@333fred 333fred added the 4 - In Review A fix for the issue is submitted for review. label Sep 29, 2020
@ghost ghost closed this as completed in e4b7d60 Sep 30, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Feature - Function Pointers Adding Function Pointers Urgency-Soon
Projects
None yet
Development

No branches or pull requests

3 participants