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

JIT: invalid flags handling by fgMorphStoreDynBlock #79750

Closed
jakobbotsch opened this issue Dec 16, 2022 · 1 comment · Fixed by #79751
Closed

JIT: invalid flags handling by fgMorphStoreDynBlock #79750

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

Comments

@jakobbotsch
Copy link
Member

jakobbotsch commented Dec 16, 2022

fgMorphStoreDynBlock calls SetIndirExceptionFlags, but that function should not be used for stores.

using System.Runtime.CompilerServices;

class Runtime_12345
{
    static unsafe int Main(string[] args)
    {
        byte dest = 0;
        byte source = 100;
        uint size = GetSize();
        Unsafe.CopyBlock(ref dest, ref GetAddr(ref source), size);

        return dest;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static ref byte GetAddr(ref byte a) => ref a;

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static uint GetSize() => 1;
}
Assert failure(PID 24244 [0x00005eb4], Thread: 18180 [0x4704]): Assertion failed '!"Missing flags on tree"' in 'Runtime_12345:Main(System.String[])' during 'Morph - Global' (IL size 26; hash 0x264ab10b; FullOpts)

    File: C:\dev\dotnet\runtime4\src\coreclr\jit\fgdiagnostic.cpp Line: 3195
    Image: C:\dev\dotnet\runtime4\artifacts\bin\coreclr\windows.x64.Checked\CoreRun.exe

Will extract my fix from #79346 and add the test case.

@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 Dec 16, 2022
@jakobbotsch jakobbotsch self-assigned this Dec 16, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Dec 16, 2022
@ghost
Copy link

ghost commented Dec 16, 2022

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

Issue Details

fgMorphStoreDynBlock calls SetIndirExceptionFlags, but that function should not be used for stores.

using System.Runtime.CompilerServices;

class Runtime_12345
{
    static unsafe int Main(string[] args)
    {
        byte dest = 0;
        byte source = 100;
        uint size = GetSize();
        Unsafe.CopyBlock(ref dest, ref GetAddr(ref source), size);

        return dest;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static ref byte GetAddr(ref byte a) => ref a;

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static uint GetSize() => 1;
}
Assert failure(PID 24244 [0x00005eb4], Thread: 18180 [0x4704]): Assertion failed '!"Missing flags on tree"' in 'superfluous_mov.Program:Main(System.String[])' during 'Morph - Global' (IL size 26; hash 0x264ab10b; FullOpts)

    File: C:\dev\dotnet\runtime4\src\coreclr\jit\fgdiagnostic.cpp Line: 3195
    Image: C:\dev\dotnet\runtime4\artifacts\bin\coreclr\windows.x64.Checked\CoreRun.exe

Will extract my fix from #79346 and add the test case.

Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@jakobbotsch jakobbotsch removed the untriaged New issue has not been triaged by the area owner label Dec 16, 2022
@jakobbotsch jakobbotsch added this to the 8.0.0 milestone Dec 16, 2022
jakobbotsch added a commit to jakobbotsch/runtime that referenced this issue Dec 16, 2022
SetIndirExceptionFlags expects only unary indirs (reads) and does not
handle other cases correctly. Add an assert for it and fix the users.

Only fgMorphStoreDynBlock had the bug since gtUpdateNodeOperSideEffects
assumes the caller will propagate effect flags from operands afterwards.

Extracted from early liveness PR.

Fix dotnet#79750
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Dec 16, 2022
jakobbotsch added a commit that referenced this issue Dec 17, 2022
SetIndirExceptionFlags expects only unary indirs (reads) and does not
handle other cases correctly. Add an assert for it and fix the users.

Only fgMorphStoreDynBlock had the bug since gtUpdateNodeOperSideEffects
assumes the caller will propagate effect flags from operands afterwards.

Extracted from early liveness PR.

Fix #79750
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Dec 17, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jan 16, 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.

1 participant