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

fgMorphArgs reorders (non-call) exception-throwing arguments #63905

Closed
jakobbotsch opened this issue Jan 17, 2022 · 1 comment · Fixed by #70893
Closed

fgMorphArgs reorders (non-call) exception-throwing arguments #63905

jakobbotsch opened this issue Jan 17, 2022 · 1 comment · Fixed by #70893
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI bug
Milestone

Comments

@jakobbotsch
Copy link
Member

jakobbotsch commented Jan 17, 2022

Description

For each arg, fgMorphArgs looks for GTF_CALL and GTF_ASG to figure out if args before that one need to be spilled to temps in anticipation of sorting them. This should take GTF_EXCEPT into account as otherwise we can reorder late args that may throw exceptions.

Reproduction Steps

The following program throws DivisionByZeroException when it should throw NullReferenceException:

using System.Runtime.CompilerServices;

public class Program
{
    public static void Main(string[] args)
    {
        Foo();
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static void Foo()
    {
        C c = null;
        int i = 1;
        Bar(c.Field, i / 0);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static void Bar(object o, int val)
    {
    }

    private class C
    {
        public object Field;
    }
}

Expected behavior

NullReferenceException

Actual behavior

DivisionByZeroException

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

cc @dotnet/jit-contrib

@dotnet-issue-labeler dotnet-issue-labeler bot added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI untriaged New issue has not been triaged by the area owner labels Jan 17, 2022
@ghost
Copy link

ghost commented Jan 17, 2022

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

Issue Details

Description

For each arg, fgMorphArgs looks for GTF_CALL and GTF_ASG to figure out if args before that one need to be spilled to temps in anticipation of sorting them. This should take GTF_EXCEPT into account as otherwise we can reorder late args that may throw exceptions.

Reproduction Steps

The following program throws DivisionByZeroException when it should throw NullReferenceException:

using System.Runtime.CompilerServices;

public unsafe class Program
{
    public static void Main(string[] args)
    {
        Foo();
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static void Foo()
    {
        C c = null;
        int i = 1;
        Bar(c.Field, i / 0);
    }

    private static void Bar(object o, int val)
    {
    }

    private class C
    {
        public object Field;
    }
}

Expected behavior

NullReferenceException

Actual behavior

DivisionByZeroException

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

cc @dotnet/jit-contrib

Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr, untriaged

Milestone: -

@jakobbotsch jakobbotsch self-assigned this Jan 17, 2022
@jakobbotsch jakobbotsch removed the untriaged New issue has not been triaged by the area owner label Jan 17, 2022
@jakobbotsch jakobbotsch added this to the 7.0.0 milestone Jan 17, 2022
jakobbotsch added a commit to jakobbotsch/runtime that referenced this issue Jun 17, 2022
Implement a precise scan for arguments that may throw exceptions which
collects the exceptions they may throw. When we see two such interfering
sets, make sure that the first argument is evaluated to a temp so that
they do not get reordered by sort.

Fix dotnet#63905
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jun 17, 2022
jakobbotsch added a commit that referenced this issue Jun 22, 2022
Implement a precise scan for arguments that may throw exceptions which
collects the exceptions they may throw. When we see two such interfering
sets, make sure that the first argument is evaluated to a temp so that
they do not get reordered by the later sort.

Fix #63905
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jun 22, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jul 23, 2022
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 bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant