dotnet / dotnet/runtime

JIT: (bug) negating division by the signed minimum gives the wrong result

Open
#133,517 2 comments 0 reactions 1 assignee Claimed by @EgorBo View on GitHub
area-CodeGen-coreclr
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

## Repro

```csharp
using System;
using System.Runtime.CompilerServices;

class Program {
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
static int Test(int x) => -(x / int.MinValue);

static void Main() {
Console.WriteLine(Test(int.MinValue));
}
}
```

## Expected

```
-1
```

`int.MinValue / int.MinValue` is `1`, negated is `-1`.

## Actual

```
1
```

## Platform

Windows x64, .NET 11.0.0-rc.1.26425.128. Also affects `long` and `nint`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.