-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Description
The provided C# code throws an unexpected System.Exception inside
The issue is a JIT code generation error related to the optimization path activated by the method attributes and repeated execution. The error specifically manifests during the comparison of int? types.
The input values are consistently
Reproduction Steps
// 1. Compile the code below using .NET 10.0.0 in Release configuration.
// 2. Run the application.
using System;
using System.Runtime.CompilerServices;
class Program
{
[MethodImpl(MethodImplOptions.NoOptimization)]
static void Main()
{
var test = new Test();
while (true)
{
test.Method1(0, 0, 0, 999, 999);
}
}
}
class Test
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Method1(int a, int b, int c, int value1, int? value2)
{
Method2(1, 2, 3, value1, value2);
}
public void Method2(long a, int b, int c, int? value1, int? value2)
{
try
{
if (value1 != value2)
{
throw new Exception($"{value1} != {value2}");
}
}
catch
{
throw;
}
}
}Expected behavior
The program should run indefinitely without throwing an exception.
Actual behavior
The program throws
Regression?
net9.0 in not affected
Known Workarounds
No response
Configuration
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.100\
Target framework: net10.0
Other information
No response