Skip to content

Zero assignments are removed incorrectly #37666

@erozenfeld

Description

@erozenfeld

The following two tests are failing when jit is optimizing:

using System;
using System.Runtime.CompilerServices;

public struct TwoBools
{
    public bool b1;
    public bool b2;

    public TwoBools(bool b1, bool b2)
    {
        this.b1 = b1;
        this.b2 = b2;
    }
}

class Test
{
    public static int Main()
    {
        int result = 100;

        if (Test1().b2)
        {
            Console.WriteLine("Test1 failed");
            result = -1;
        }
        else
        {
            Console.WriteLine("Test1 passed");
        }

        if (Test2().b2)
        {
            Console.WriteLine("Test2 failed");
            result = -1;
        }
        else
        {
            Console.WriteLine("Test2 passed");
        }

        return result;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static TwoBools Test1()
    {
        TwoBools result = CreateTwoBools();
        result.b2 = false;
        return result;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static TwoBools Test2()
    {
        TwoBools result = default(TwoBools);
        result.b2 = true;
        result = default(TwoBools);
        return result;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static TwoBools CreateTwoBools()
    {
        TwoBools result = new TwoBools(true, true);
        return result;
    }
}

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIbug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions