Skip to content

Bug: overflow check is optimized out #130431

Closed

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

Activity

  1. self-assigned this
    on Jul 9, 2026
  2. added this to the 11.0.0 milestone on Jul 9, 2026
  3. added
    area-CodeGen-coreclr
    on Jul 9, 2026
  4. dotnet-policy-service commented on Jul 9, 2026

    @dotnet-policy-service
    Contributor

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

  5. locked and limited conversation to collaborators on Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions