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

[Fuzzlyn] Jump into the middle of handler region #81675

Closed
tannergooding opened this issue Feb 6, 2023 · 3 comments · Fixed by #82329
Closed

[Fuzzlyn] Jump into the middle of handler region #81675

tannergooding opened this issue Feb 6, 2023 · 3 comments · Fixed by #82329
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@tannergooding
Copy link
Member

Error

The error reproduces on both regular x86 and in AltJit clrjit_win_x86_x64.dll

Jump into the middle of handler region: BB10 branches to BB11

Assert failure(PID 855144 [0x000d0c68], Thread: 812212 [0xc64b4]): Assertion failed '!"Jump into the middle of handler region"' in 'Program:Main()' during 'Unroll loops' (IL size 111; hash 0xcb019401; FullOpts)

    File: D:\Users\tagoo\source\repos\runtime_base\src\coreclr\jit\fgdiagnostic.cpp Line: 2609
    Image: D:\Users\tagoo\source\repos\runtime_base\artifacts\bin\coreclr\windows.x64.Checked\CoreRun.exe
ERROR:
Assert failure(PID 855144 [0x000d0c68], Thread: 812212 [0xc64b4]): Assertion failed '!"Jump into the middle of handler region"' in 'Program:Main()' during 'Unroll loops' (IL size 111; hash 0xcb019401; FullOpts)

    File: D:\Users\tagoo\source\repos\runtime_base\src\coreclr\jit\fgdiagnostic.cpp Line: 2609
    Image: D:\Users\tagoo\source\repos\runtime_base\artifacts\bin\coreclr\windows.x64.Checked\CoreRun.exe

Repro

// Generated by Fuzzlyn v1.5 on 2023-02-06 00:41:34
// Run on X86 Windows
// Seed: 12611629827253727687
// Reduced from 444.9 KiB to 1.1 KiB in 00:13:23
// Hits JIT assert in Release:
// Assertion failed '!"Jump into the middle of handler region"' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Unroll loops' (IL size 131; hash 0xade6b36b; FullOpts)
// 
//     File: D:\a\_work\1\s\src\coreclr\jit\fgdiagnostic.cpp Line: 2609
// 
public interface I0
{
}

public class C0 : I0
{
    public sbyte F3;
}

public class Program
{
    public static ushort s_11;
    public static bool[][] s_18;
    public static C0 s_26;
    public static short[] s_42;
    public static void Main()
    {
        short vr7 = default(short);
        for (int vr8 = 0; vr8 < 0; vr8++)
        {
            try
            {
                System.Console.WriteLine(32767);
            }
            finally
            {
                I0 vr9 = new C0();
            }
        }

        for (int vr10 = 0; vr10 < 0; vr10++)
        {
            if (s_18[0][0])
            {
                var vr11 = s_26.F3;
            }
            else
            {
                System.Console.WriteLine(0);
            }

            if (!((ushort)(-s_11++) >= 0))
            {
                vr7 = vr7;
                try
                {
                    vr7 = 0;
                }
                finally
                {
                    vr7 = s_42[0];
                }
            }
        }
    }
}
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 6, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Feb 6, 2023
@ghost
Copy link

ghost commented Feb 6, 2023

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

Issue Details

Error

The error reproduces on both regular x86 and in AltJit clrjit_win_x86_x64.dll

Jump into the middle of handler region: BB10 branches to BB11

Assert failure(PID 855144 [0x000d0c68], Thread: 812212 [0xc64b4]): Assertion failed '!"Jump into the middle of handler region"' in 'Program:Main()' during 'Unroll loops' (IL size 111; hash 0xcb019401; FullOpts)

    File: D:\Users\tagoo\source\repos\runtime_base\src\coreclr\jit\fgdiagnostic.cpp Line: 2609
    Image: D:\Users\tagoo\source\repos\runtime_base\artifacts\bin\coreclr\windows.x64.Checked\CoreRun.exe
ERROR:
Assert failure(PID 855144 [0x000d0c68], Thread: 812212 [0xc64b4]): Assertion failed '!"Jump into the middle of handler region"' in 'Program:Main()' during 'Unroll loops' (IL size 111; hash 0xcb019401; FullOpts)

    File: D:\Users\tagoo\source\repos\runtime_base\src\coreclr\jit\fgdiagnostic.cpp Line: 2609
    Image: D:\Users\tagoo\source\repos\runtime_base\artifacts\bin\coreclr\windows.x64.Checked\CoreRun.exe

Repro

// Generated by Fuzzlyn v1.5 on 2023-02-06 00:41:34
// Run on X86 Windows
// Seed: 12611629827253727687
// Reduced from 444.9 KiB to 1.1 KiB in 00:13:23
// Hits JIT assert in Release:
// Assertion failed '!"Jump into the middle of handler region"' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Unroll loops' (IL size 131; hash 0xade6b36b; FullOpts)
// 
//     File: D:\a\_work\1\s\src\coreclr\jit\fgdiagnostic.cpp Line: 2609
// 
public interface I0
{
}

public class C0 : I0
{
    public sbyte F3;
}

public class Program
{
    public static ushort s_11;
    public static bool[][] s_18;
    public static C0 s_26;
    public static short[] s_42;
    public static void Main()
    {
        short vr7 = default(short);
        for (int vr8 = 0; vr8 < 0; vr8++)
        {
            try
            {
                System.Console.WriteLine(32767);
            }
            finally
            {
                I0 vr9 = new C0();
            }
        }

        for (int vr10 = 0; vr10 < 0; vr10++)
        {
            if (s_18[0][0])
            {
                var vr11 = s_26.F3;
            }
            else
            {
                System.Console.WriteLine(0);
            }

            if (!((ushort)(-s_11++) >= 0))
            {
                vr7 = vr7;
                try
                {
                    vr7 = 0;
                }
                finally
                {
                    vr7 = s_42[0];
                }
            }
        }
    }
}
Author: tannergooding
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@jakobbotsch
Copy link
Member

Fallout from #80353?

@tannergooding
Copy link
Member Author

@jakobbotsch, it's certainly possible but given the checks are vr8 < 0 and vr10 < 0 it wouldn't be my first guess.

#80353 simply updated the current limit from 1 (which should cover those checks) to 4.

@JulieLeeMSFT JulieLeeMSFT removed the untriaged New issue has not been triaged by the area owner label Feb 13, 2023
@JulieLeeMSFT JulieLeeMSFT added this to the 8.0.0 milestone Feb 13, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Feb 18, 2023
BruceForstall added a commit to BruceForstall/runtime that referenced this issue Feb 18, 2023
Fix two problems with code in loops that are determined to not execute
that have exception handling clauses:
1. Be more specific in loop unrolling to avoid unrolling even zero-count
loops (which causes the loop to be removed) if there is a block in the
loop with a different handler region than the handler region of the "top"
block. This should only kick in for x86, where handlers are not extracted
as funclets.
2. In Value Numbering, before actually value numbering nodes,
`optComputeLoopSideEffectsOfBlock()` walks all the blocks of all top-level
loops collecting data. Unfortunately, it sets the Value Number of certain
nodes as a way to pass information "up the tree" during processing. Presumably
these "fake" value numbers actually get replaced during actual value numbering
for the tree. However, when we go to actually value number the IR, we only
walk reachable blocks. Thus, in some cases, we would end up with a top-level
"fake" value number on an unreachable statement root, thus leading
`fgDebugCheckExceptionSets()` to check the tree and assert. To fix this,
at the end of the `optComputeLoopSideEffectsOfBlock()`, clear the VN in case
it was previously set.

Fixes dotnet#81675
BruceForstall added a commit that referenced this issue Feb 22, 2023
Fix two problems with code in loops that are determined to not execute
that have exception handling clauses:
1. Be more specific in loop unrolling to avoid unrolling even zero-count
loops (which causes the loop to be removed) if there is a block in the
loop with a different handler region than the handler region of the "top"
block. This should only kick in for x86, where handlers are not extracted
as funclets.
2. In Value Numbering, before actually value numbering nodes,
`optComputeLoopSideEffectsOfBlock()` walks all the blocks of all top-level
loops collecting data. Unfortunately, it sets the Value Number of certain
nodes as a way to pass information "up the tree" during processing. Presumably
these "fake" value numbers actually get replaced during actual value numbering
for the tree. However, when we go to actually value number the IR, we only
walk reachable blocks. Thus, in some cases, we would end up with a top-level
"fake" value number on an unreachable statement root, thus leading
`fgDebugCheckExceptionSets()` to check the tree and assert. To fix this,
at the end of the `optComputeLoopSideEffectsOfBlock()`, clear the VN in case
it was previously set.

Fixes #81675
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Feb 22, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Mar 24, 2023
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants