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

Invalid IL produced for an unused struct load from a ref local #60905

Closed
SingleAccretion opened this issue Apr 22, 2022 · 0 comments · Fixed by #60910
Closed

Invalid IL produced for an unused struct load from a ref local #60905

SingleAccretion opened this issue Apr 22, 2022 · 0 comments · Fixed by #60910
Assignees
Milestone

Comments

@SingleAccretion
Copy link

Version Used: the P5 preview SDK, csc.dll had a product version of 4.2.0-4.22212.4+f2d278f9a5131b7944d6ac5fecf2ce5b0a98195f.

Steps to Reproduce:

Compile and run:

using System.Runtime.CompilerServices;

Problem(new Struct[1]);

[MethodImpl(MethodImplOptions.NoInlining)]
static void Problem(Struct[] a)
{
    ref var b = ref a[0];
    _ = b;
}

struct Struct { }

Expected Behavior: program exits successfully.

Actual Behavior: InvalidProgramException is thrown because the IL produced for Problem is not valid:

IL to import:
IL_0000  02                ldarg.0
IL_0001  16                ldc.i4.0
IL_0002  8f 24 00 00 02    ldelema      0x2000024
IL_0007  26                pop
IL_0008  25                dup          // The stack is empty at this point, there is nothing to "dup"
IL_0009  71 24 00 00 02    ldobj        0x2000024
IL_000e  26                pop
IL_000f  2a                ret
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 22, 2022
@cston cston self-assigned this Apr 22, 2022
@jcouv jcouv added this to the Compiler.Next milestone Apr 22, 2022
@jcouv jcouv added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 22, 2022
@cston cston modified the milestones: Compiler.Next, 17.3 May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants