Skip to content

[CIL, Bug] jmp error when jump to Func2<!!T,!!T>, T = ValueTuple3<int32[],int32,int32> #11802

Closed

Description

@RevensofT

Hi,
I got unusual error I can't point a finger what's wrong with it, maybe a bug so I report it here.

Op jmp error on jump to generic delegate of value tuple of generic array,

.method public static !!T recursive<T>(
		!!T Data,
		class [mscorlib]System.Func`2<!!T,!!T> Recursive_method,
		class [mscorlib]System.Func`2<!!T,bool> Stop_condition) 
		cil managed aggressiveinlining
{   .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) 
		.maxstack 3 
		ldarg.2		ldarg.0
		callvirt	instance !1 class [mscorlib]System.Func`2<!!T,bool>::Invoke(!0)
		brfalse.s	lb_recursive
		ldarg.0	ret

		lb_recursive:
		ldarg.1		ldarg.0
		callvirt	instance !1 class [mscorlib]System.Func`2<!!T,!!T>::Invoke(!0)

		// It's work fine with tail. call.		
		/* 
		ldarg.1		ldarg.2
		tail. call	!!0 Your_namespace.Your_static_class::recursive<!!0>(
					!!0,
					class [mscorlib]System.Func`2<!!0,!!0>,
					class [mscorlib]System.Func`2<!!0,bool>)
		*/
		
		// But error when T is value tuple of generic array type.
		starg.s 0
		jmp			!!0 Your_namespace.Your_static_class::recursive<!!0>(	
						!!0,
						class [mscorlib]System.Func`2<!!0,!!0>,
						class [mscorlib]System.Func`2<!!0,bool>)
		ret
}

I test on some sample and found it only error when tuple with array type.

    Public Function Test_recursion(Of T)(Input As T, Work As Func(Of T, T), Stop_c As Func(Of T, Boolean)) As T
        If Stop_c(Input) Then Return Input
        Input = Work(Input)
        Return Test_recursion(Input, Work, Stop_c)
    End Function

    Public Sub main()

        '// Work fine without any error
        Console.WriteLine(
            Your_namespace.recursive((Input:=5, sum:=1),
                Function(Data) (Data.input - 1, Data.sum * Data.input),
                Function(Data) Data.input < 2
            ).sum
        )

        Dim Input_data = (Input:={1, 2, 3, 4}, Index:=0, sum:=0)

        Console.WriteLine(Test_recursion(Input_data,
                Function(Data) (Data.Input, Data.Index + 1, Data.sum + Data.Input(Data.Index)),
                Function(Data) Data.Index >= Data.Input.Length).sum)

        '// Crash when run into this line, not a hint what's cause this error.
        Console.WriteLine(Your_namespace.recursive(Input_data,
                Function(Data) (Data.Input, Data.Index + 1, Data.sum + Data.Input(Data.Index)),
                Function(Data) Data.Index >= Data.Input.Length).sum)

        Console.ReadKey()
    End Sub

Activity

  1. RussKeldorph commented on Jan 16, 2019

    @RussKeldorph
    Contributor

    @AndyAyersMS @briansull @dotnet/jit-contrib Does this look familiar?

  2. AndyAyersMS commented on Jan 16, 2019

    @AndyAyersMS
    Member

    Doesn't look familiar.

  3. RussKeldorph commented on Jan 16, 2019

    @RussKeldorph
    Contributor

    Ok, assuming CodeGen until proven otherwise.

  4. briansull commented on Jan 18, 2019

    @briansull
    Contributor

    Can you provide a complete repro case for this issue?

    And what is the exact "error" that occurs?
    Sounds like an A/V is the error.

  5. briansull commented on Jan 18, 2019

    @briansull
    Contributor

    I also don't think that using a 'jmp; opcode is supported for generic methods and such methods have "hidden" parameters that need to be setup, such as the generic context.

  6. RevensofT commented on Jan 19, 2019

    @RevensofT
    Author

    @briansull
    I'm sorry, I might be post on wrong place, an error emerge at .Net framework CLR; I'm not sure coreclr work in the same way but the code I post is all I wrote and got this error, an error feedback just a generic error like I write some line wrong in CIL; I just create a console project to test "recursive"(I directly write in in .il) to help me do a tail recursion in VB.net.

    In my opinion, jmp isn't much use on any case in .net so I assume it might be an unnotice bug occur on type checking because it's only error when a nest type is array.

  7. briansull commented on Jan 22, 2019

    @briansull
    Contributor

    @RevensofT
    The jmp opcode does not support the full set of possible call targets.
    Instead it is recommended that you use the tail prefix opcode instead of using the jmp opcode.

  8. transferred this issue fromdotnet/coreclron Jan 31, 2020
  9. added this to the 3.0 milestone on Jan 31, 2020
  10. ghost locked as resolved and limited conversation to collaborators on Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions