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

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

Closed
RevensofT opened this issue Jan 12, 2019 · 7 comments
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@RevensofT
Copy link

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
@RussKeldorph
Copy link
Contributor

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

@AndyAyersMS
Copy link
Member

Doesn't look familiar.

@RussKeldorph
Copy link
Contributor

Ok, assuming CodeGen until proven otherwise.

@briansull
Copy link
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.

@briansull
Copy link
Contributor

briansull commented Jan 18, 2019

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.

@RevensofT
Copy link
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.

@briansull
Copy link
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.

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

No branches or pull requests

5 participants