Skip to content

Bug: overflow check is optimized out #130431

Description

@EgorBo
using System.Runtime.CompilerServices;
using System.Linq.Expressions;

internal static class Program
{
    public static int Main()
    {
        try
        {
            uint result = Test(1, uint.MaxValue);
            Console.WriteLine(result);
            return result == 0 ? 100 : 1;
        }
        catch (Exception exception)
        {
            Console.WriteLine(exception);
            return 2;
        }
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static uint Test(uint x, uint y)
    {
        uint result = checked(y + unchecked((byte)x));

        if (x == 0)
        {
            return result + 1;
        }

        return result;
    }
}

Tier0: System.OverflowException: Arithmetic operation resulted in an overflow.
Tier1: 0

Metadata

Metadata

Assignees

Labels

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

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions