Skip to content

JIT: Late expansion of delegate calls can reorder null checks with other argument exceptions #75832

Closed

Description

@jakobbotsch

The JIT inlines delegate calls, which is done in lowering by inserting indirections to fetch the instance and target from the delegate object. However, the indirection that fetches the instance is inserted right after the existing 'this' argument node. This can reorder the null-check of the delegate object with exceptions thrown by other arguments.

For example, the following example throws NullReferenceException in release. It should throw DivisionByZeroException (as it does in debug).

public static void Main()
{
    Test(0);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Test(int i)
{
    GetAction()(100 / i);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static Action<int> GetAction() => null;

category:correctness
theme:delegates
skill-level:intermediate
cost:small
impact:small

Activity

  1. ghost added
    untriaged
    on Sep 19, 2022
  2. ghost added
    area-CodeGen-coreclr
    on Sep 19, 2022
  3. removed
    untriaged
    on Sep 19, 2022
  4. self-assigned this
    on Sep 19, 2022
  5. added this to the 8.0.0 milestone on Sep 19, 2022
  6. ghost added
    in-pr
    on Sep 19, 2022
  7. ghost removed
    in-pr
    on Oct 20, 2022
  8. added
    Priority:3
    on Jun 20, 2023
  9. added a commit that references this issue on Jul 19, 2023
    c566378
  10. ghost added
    in-pr
    on Jul 19, 2023
  11. added a commit that references this issue on Jul 20, 2023
    3db5172
  12. ghost removed
    in-pr
    on Jul 20, 2023
  13. ghost locked as resolved and limited conversation to collaborators on Aug 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Priority:3area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions