dotnet / dotnet/runtime

ILVerify does not detect disallowed boxing of byref-like types

Open
#132,954 9 comments 0 reactions 0 assignees View on GitHub
area-Tools-ILVerification untriaged
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

### Description

I'm working on adding `ref struct` support to the Boo compiler, and as expected it's producing some invalid IL until I get the details worked out. But one of the early tests is failing, throwing `System.InvalidProgramException: Common Language Runtime detected an invalid program` at runtime, while passing ILVerify with no errors.

### Reproduction Steps

[Open the attached zip file.](https://github.com/user-attachments/files/31621119/testcase.zip) It contains the testcase, and its ILDASM disassembly for convenience. The disassembly has one non-trivial method, `Main.`

This is the original code. It should do exactly what it looks like it does:
```
import System

var span = "Hello, World!".AsSpan()
for letter in span:
Console.Write(letter)
Console.WriteLine()
```

The generated assembly throws `InvalidProgramException` at runtime, but ILVerify gives it a clean bill of health, so it's not clear what I need to fix in the codegen.

### Expected behavior

ILVerify should correctly diagnose invalid assemblies.

### Actual behavior

ILVerify shows no errors.

### Regression?

_No response_

### Known Workarounds

_No response_

### Configuration

.NET 10, Windows 10, x64.

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by opening the attached testcase.zip and its ILDASM disassembly, focusing on the non-trivial Main method and the byref-like boxing sequence. Run ILVerify on the attached assembly and compare its result with the runtime InvalidProgramException. Done means ILVerify reports the disallowed boxing as an error.

Written by the indexing model from the issue text.

Assessment

Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.