dotnet / dotnet/runtime

JIT: (bug) a negative constant dimension passed to `Array.GetLength` asserts in the importer

Open
#133,556 1 comment 1 reaction 2 assignees 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
{
static int[,] s_md = new int[3, 4];

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
static string Test()
{
try { return s_md.GetLength(-1).ToString(); }
catch (Exception e) { return e.GetType().Name; }
}

static void Main() => Console.WriteLine(Test());
}
```

## Expected

```
IndexOutOfRangeException
```

## Actual

```
Assert failure(PID 110488 [0x0001af98], Thread: 82424 [0x141f8]): Assertion failed '(unsigned int)dimValue == dimValue' in 'Program:Test():System.String' during 'Importation' (IL size 37; hash 0xe4e107d8; FullOpts)

File: C:\prj\runtime-main3\src\coreclr\jit\importercalls.cpp:5381
```

The process aborts with exit code `0xC0000602`.

## Platform

Windows x64, local Checked build of dotnet/runtime main (ef97eb54da2). Not target-specific.
Requires a Checked/Debug JIT; a Release JIT throws `IndexOutOfRangeException` correctly.

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.