You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mono's Vector128 support incorrectly handles Abs for signed integer MinValue #95592
This test passes on coreclr. On mono it fails with:
System.Runtime.Intrinsics.Tests.Vectors.Vector128Tests.Vector128SByteAbs_MinValue [FAIL]
System.OverflowException : Negating the minimum value of a twos complement number is invalid.
Stack Trace:
/_/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector128Tests.cs(163,0): at System.Runtime.Intrinsics.Tests.Vectors.Vector128Tests.Vector128SByteAbs_MinValue()
/_/src/mono/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.Mono.cs(22,0): at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
/_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs(57,0): at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
$ dotnet runUnhandled Exception:System.OverflowException: Negating the minimum value of a twos complement number is invalid. at Program.<Main>$(String[] args) in /tmp/abcd/Program.cs:line 5[ERROR] FATAL UNHANDLED EXCEPTION: System.OverflowException: Negating the minimum value of a twos complement number is invalid. at Program.<Main>$(String[] args) in /tmp/abcd/Program.cs:line 5
$ MONO_ENV_OPTIONS=--interp dotnet runUnhandled Exception:System.OverflowException: Negating the minimum value of a twos complement number is invalid. at Program.<Main>$(String[] args) in /tmp/abcd/Program.cs:line 5[ERROR] FATAL UNHANDLED EXCEPTION: System.OverflowException: Negating the minimum value of a twos complement number is invalid. at Program.<Main>$(String[] args) in /tmp/abcd/Program.cs:line 5
This might be a bug in Scalar<T>.Abs which is used for the software fallback. Looks like its just deferring to Math.Abs which would throw for MinValue rather than returning MinValue
Activity
lambdageek commentedon Dec 4, 2023
Self contained repro with net8.0:
This throws with both JIT and interp:
MichalPetryka commentedon Dec 4, 2023
runtime/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Scalar.cs
Line 165 in 4ceefab
The issue is here, the Mono JIT doesn't expand Abs for integers and uses the managed fallback which is broken so this isn't Mono specific.
tannergooding commentedon Dec 4, 2023
This might be a bug in
Scalar<T>.Abswhich is used for the software fallback. Looks like its just deferring toMath.Abswhich would throw forMinValuerather than returningMinValueFix Scalar.Abs for TInteger.MinValue
Fix Scalar.Abs for TInteger.MinValue (#95597)
akoeplinger commentedon Dec 6, 2023
@lambdageek I saw you added this to 8.0.x milestone, do we want to backport the fix or is 9.0 ok?
lambdageek commentedon Dec 6, 2023
Probably net9.0 is ok unless we hear from a customer