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

ILVerification fails unexpectedly on delegate construction #65010

Closed
jcouv opened this issue Feb 8, 2022 · 1 comment · Fixed by #65425
Closed

ILVerification fails unexpectedly on delegate construction #65010

jcouv opened this issue Feb 8, 2022 · 1 comment · Fixed by #65425
Labels
area-Tools-ILVerification Issues related to ilverify tool and IL verification in general help wanted [up-for-grabs] Good issue for external contributors untriaged New issue has not been triaged by the area owner

Comments

@jcouv
Copy link
Member

jcouv commented Feb 8, 2022

Description

Assignments of an extension method to Action trips ILVerification.

Reproduction Steps

Compile the following C# code and verify it.

The verification fails with:
Unrecognized arguments for delegate .ctor. { Offset = 21 } // that's 0x15
Unrecognized arguments for delegate .ctor. { Offset = 59 } // that's 0x3B

using System;
static class Program
{
    static void Main()
    {
        "ABC".Goo();
        Action a = "123".Goo;
        a();
        a = new Action(a);
        a();
        a = new Action("xyz".Goo);
        a();
    }
    static void Goo(this string x)
    {
        Console.WriteLine(x);
    }
}
// ILVerify:
//     Unrecognized arguments for delegate .ctor. { Offset = 21 } // that's 0x15
//     Unrecognized arguments for delegate .ctor. { Offset = 59 } // that's 0x3B
.class private auto ansi abstract sealed beforefieldinit Program
	extends [netstandard]System.Object
{
	.custom instance void [netstandard]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = (
		01 00 00 00
	)
	// Methods
	.method private hidebysig static 
		void Main () cil managed 
	{
		// Method begins at RVA 0x2050
		// Code size 70 (0x46)
		.maxstack 2
		.entrypoint
		IL_0000: ldstr "ABC"
		IL_0005: call void Program::Goo(string)
		IL_000a: ldstr "123"
		IL_000f: ldftn void Program::Goo(string)
		IL_0015: newobj instance void [netstandard]System.Action::.ctor(object, native int)
		IL_001a: dup
		IL_001b: callvirt instance void [netstandard]System.Action::Invoke()
		IL_0020: ldftn instance void [netstandard]System.Action::Invoke()
		IL_0026: newobj instance void [netstandard]System.Action::.ctor(object, native int)
		IL_002b: callvirt instance void [netstandard]System.Action::Invoke()
		IL_0030: ldstr "xyz"
		IL_0035: ldftn void Program::Goo(string)
		IL_003b: newobj instance void [netstandard]System.Action::.ctor(object, native int)
		IL_0040: callvirt instance void [netstandard]System.Action::Invoke()
		IL_0045: ret
	} // end of method Program::Main
	.method private hidebysig static 
		void Goo (
			string x
		) cil managed 
	{
		.custom instance void [netstandard]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = (
			01 00 00 00
		)
		// Method begins at RVA 0x20a2
		// Code size 7 (0x7)
		.maxstack 8
		IL_0000: ldarg.0
		IL_0001: call void [netstandard]System.Console::WriteLine(string)
		IL_0006: ret
	} // end of method Program::Goo
} // end of class Program

This was found in Roslyn, test: ExtensionMethodTests.ExtensionMethodInTheSameClass. Discussion

Expected behavior

No error (ie. same behavior as PEVerify)

Actual behavior

Unrecognized arguments for delegate .ctor. { Offset = 21 }
Unrecognized arguments for delegate .ctor. { Offset = 59 }

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@jcouv jcouv added the area-Tools-ILVerification Issues related to ilverify tool and IL verification in general label Feb 8, 2022
@ghost
Copy link

ghost commented Feb 8, 2022

Tagging subscribers to this area: @JulieLeeMSFT
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Assignments of an extension method to Action trips ILVerification.

Reproduction Steps

Compile the following C# code and verify it.

The verification fails with:
Unrecognized arguments for delegate .ctor. { Offset = 21 } // that's 0x15
Unrecognized arguments for delegate .ctor. { Offset = 59 } // that's 0x3B

using System;
static class Program
{
    static void Main()
    {
        "ABC".Goo();
        Action a = "123".Goo;
        a();
        a = new Action(a);
        a();
        a = new Action("xyz".Goo);
        a();
    }
    static void Goo(this string x)
    {
        Console.WriteLine(x);
    }
}
// ILVerify:
//     Unrecognized arguments for delegate .ctor. { Offset = 21 } // that's 0x15
//     Unrecognized arguments for delegate .ctor. { Offset = 59 } // that's 0x3B
.class private auto ansi abstract sealed beforefieldinit Program
	extends [netstandard]System.Object
{
	.custom instance void [netstandard]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = (
		01 00 00 00
	)
	// Methods
	.method private hidebysig static 
		void Main () cil managed 
	{
		// Method begins at RVA 0x2050
		// Code size 70 (0x46)
		.maxstack 2
		.entrypoint
		IL_0000: ldstr "ABC"
		IL_0005: call void Program::Goo(string)
		IL_000a: ldstr "123"
		IL_000f: ldftn void Program::Goo(string)
		IL_0015: newobj instance void [netstandard]System.Action::.ctor(object, native int)
		IL_001a: dup
		IL_001b: callvirt instance void [netstandard]System.Action::Invoke()
		IL_0020: ldftn instance void [netstandard]System.Action::Invoke()
		IL_0026: newobj instance void [netstandard]System.Action::.ctor(object, native int)
		IL_002b: callvirt instance void [netstandard]System.Action::Invoke()
		IL_0030: ldstr "xyz"
		IL_0035: ldftn void Program::Goo(string)
		IL_003b: newobj instance void [netstandard]System.Action::.ctor(object, native int)
		IL_0040: callvirt instance void [netstandard]System.Action::Invoke()
		IL_0045: ret
	} // end of method Program::Main
	.method private hidebysig static 
		void Goo (
			string x
		) cil managed 
	{
		.custom instance void [netstandard]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = (
			01 00 00 00
		)
		// Method begins at RVA 0x20a2
		// Code size 7 (0x7)
		.maxstack 8
		IL_0000: ldarg.0
		IL_0001: call void [netstandard]System.Console::WriteLine(string)
		IL_0006: ret
	} // end of method Program::Goo
} // end of class Program

This was found in Roslyn, test: ExtensionMethodTests.ExtensionMethodInTheSameClass. Discussion

Expected behavior

No error (ie. same behavior as PEVerify)

Actual behavior

Unrecognized arguments for delegate .ctor. { Offset = 21 }
Unrecognized arguments for delegate .ctor. { Offset = 59 }

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: jcouv
Assignees: -
Labels:

area-ILVerification

Milestone: -

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Feb 8, 2022
@jkotas jkotas added the help wanted [up-for-grabs] Good issue for external contributors label Feb 9, 2022
jkotas added a commit to jkotas/runtime that referenced this issue Feb 16, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Feb 16, 2022
jkotas added a commit that referenced this issue Feb 17, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Feb 17, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Mar 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Tools-ILVerification Issues related to ilverify tool and IL verification in general help wanted [up-for-grabs] Good issue for external contributors untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants