From e99296b0e3668237dd673007ffc179cb5bbb40c4 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Wed, 14 Feb 2024 13:35:18 +0100 Subject: [PATCH] Throw correct overflow exception in IDiv helper --- .../Internal/Runtime/CompilerHelpers/MathHelpers.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/MathHelpers.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/MathHelpers.cs index a471c3410abfc2..d7195891320f00 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/MathHelpers.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/MathHelpers.cs @@ -295,7 +295,7 @@ public static int IDiv(int i, int j) if (j == 0) return ThrowIntDivByZero(); else if (j == -1 && i == int.MinValue) - return ThrowIntArithExc(); + return ThrowIntOvf(); else return RhpIDiv(i, j); } @@ -320,6 +320,8 @@ public static int IMod(int i, int j) { if (j == 0) return ThrowIntDivByZero(); + else if (j == -1 && i == int.MinValue) + return ThrowIntOvf(); else return RhpIMod(i, j); } @@ -378,12 +380,6 @@ private static uint ThrowUIntDivByZero() { throw new DivideByZeroException(); } - - [MethodImpl(MethodImplOptions.NoInlining)] - private static int ThrowIntArithExc() - { - throw new ArithmeticException(); - } #endif // TARGET_ARM } }