Skip to content

Unused struct argument loads can be dropped by inlining #72808

Closed

Description

@SingleAccretion

Reproduction:

using System.Runtime.CompilerServices;

Problem(null);

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
static unsafe void Problem(S* pA) { Use(*pA); }

static void Use(S s) { }
struct S { }

Compile and run.

Expected result: NullReferenceException is thrown.

Actual result: program exits successfully.

Cause:

if (argNode->gtOper == GT_OBJ || argNode->gtOper == GT_MKREFANY)
{
// Don't put GT_OBJ node under a GT_COMMA.
// Codegen can't deal with it.
// Just hang the address here in case there are side-effect.
newStmt = gtNewStmt(gtUnusedValNode(argNode->AsOp()->gtOp1), callDI);
}

category:cq
theme:inlining
skill-level:intermediate
cost:small
impact:small

Activity

  1. added
    area-CodeGen-coreclr
    on Jul 25, 2022
  2. added this to the 8.0.0 milestone on Jul 25, 2022
  3. modified the milestones: 8.0.0, 9.0.0 on Jul 12, 2023
  4. JulieLeeMSFT commented on Aug 1, 2024

    @JulieLeeMSFT
    Member

    Ping @SingleAccretion if you will work on this issue in .NET 9. RC1 snap is Aug 11th and RC2 snap is Setp 13th.

  5. JulieLeeMSFT commented on Aug 1, 2024

    @JulieLeeMSFT
    Member

    This is a edge case. We don't have time to work on this in .NET 9. Pushing out to .NET 10.

  6. modified the milestones: 9.0.0, 10.0.0 on Aug 1, 2024
  7. jakobbotsch commented on Aug 5, 2025

    @jakobbotsch
    Member

    @SingleAccretion Will you work on this for .NET 10 (snaps end of next week), or should we move to .NET 11 (or future)?

  8. SingleAccretion commented on Aug 5, 2025

    @SingleAccretion
    ContributorAuthor

    or should we move to .NET 11 (or future)?

    We can move this; there is no rush.

  9. modified the milestones: 10.0.0, 11.0.0 on Aug 5, 2025
  10. added
    in-pr
    on Jul 9, 2026
  11. locked and limited conversation to collaborators on Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-CodeGen-coreclrbugin-pr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions