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

FltToInt: OverflowException in Debug and no exception in Release #58832

Closed
EgorBo opened this issue Sep 8, 2021 · 2 comments · Fixed by #58868
Closed

FltToInt: OverflowException in Debug and no exception in Release #58832

EgorBo opened this issue Sep 8, 2021 · 2 comments · Fixed by #58868
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@EgorBo
Copy link
Member

EgorBo commented Sep 8, 2021

I noticed that we assign the same VN for "checked" and "unchecked" conversions from double to integer here, so I came up with the following repro that throws OverflowException in Debug (as expected) and prints "done" in Release:

using System;

public class Program
{
    static double fld = double.MaxValue;

    static void Main()
    {
        double x = fld;
        try { Console.WriteLine(checked((ulong)x)); } catch { }

        if ((ulong)x == checked((ulong)x)) // should throw here
            Console.WriteLine("done"); // not expected to be invoked
    }
}
@dotnet-issue-labeler dotnet-issue-labeler bot added area-ExceptionHandling-coreclr untriaged New issue has not been triaged by the area owner labels Sep 8, 2021
@EgorBo EgorBo added this to the 6.0.0 milestone Sep 8, 2021
@EgorBo EgorBo self-assigned this Sep 8, 2021
@EgorBo EgorBo added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI and removed area-ExceptionHandling-coreclr labels Sep 8, 2021
@ghost
Copy link

ghost commented Sep 8, 2021

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

Issue Details

I noticed that we assign the same VN for "checked" and "unchecked" conversions from double to integer here, so I came up with the following repro that throws OverflowException in Debug (as expected) and prints "done" in Release:

using System;

public class Program
{
    static double fld = double.MaxValue;

    static void Main()
    {
        double x = fld;
        try { Console.WriteLine(checked((ulong)x)); } catch { }

        if ((ulong)x == checked((ulong)x)) // should throw here
            Console.WriteLine("done"); // not expected to be invoked
    }
}
Author: EgorBo
Assignees: EgorBo
Labels:

area-CodeGen-coreclr, untriaged

Milestone: 6.0.0

@JulieLeeMSFT JulieLeeMSFT removed the untriaged New issue has not been triaged by the area owner label Sep 8, 2021
@SingleAccretion
Copy link
Contributor

Quite surprising this wasn't caught while I was adding VN tests for all these casts.

.NET 6 fix would be to add the overflow exception somewhere here.

.NET 7 fix is to delete all the VNFuncs for helpers (they're not needed anymore) and route all the codepaths through VNForCast, which should also add the exception set.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Sep 9, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Sep 10, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Oct 10, 2021
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.

3 participants