-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Conversation
Great tests but I'm nervous about deleting "dead" code given this is for compat (and I'm not familiar enough with VB to easily persuade myself it is dead) I'll ask @OmarTawfik to sign off on this one as a VB guy. |
@@ -887,13 +887,7 @@ Namespace Microsoft.VisualBasic.CompilerServices | |||
|
|||
Public Shared Function PlusObject(ByVal Operand As Object) As Object | |||
|
|||
If Operand Is Nothing Then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dead code, as GetTypeCode
is implemented as
Private Shared Function GetTypeCode(ByVal o As Object) As TypeCode
If o Is Nothing Then
Return TypeCode.Empty
Else
Return o.GetType.GetTypeCode
End If
End Function
and we return Boxed_ZeroInteger
in the TypeCode.Empty
case directly below this
@@ -955,13 +949,6 @@ Namespace Microsoft.VisualBasic.CompilerServices | |||
Public Shared Function NegateObject(ByVal Operand As Object) As Object | |||
|
|||
Dim tc As TypeCode = GetTypeCode(Operand) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dead code, as GetTypeCode
is implemented as
Private Shared Function GetTypeCode(ByVal o As Object) As TypeCode
If o Is Nothing Then
Return TypeCode.Empty
Else
Return o.GetType.GetTypeCode
End If
End Function
so tc == TypeCode.Empty
if Operand Is Nothing
Catch ex As OverflowException | ||
Return -CDbl(operand) | ||
End Try | ||
Return -operand |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have tests negating decimal.MinValue - this does not cause an overflow exception
yield return new object[] { decimal.MinValue, decimal.Parse("79228162514264337593543950335") };
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add tests with MaxValue as well (applicable to others)?
In reply to: 204927252 [](ancestors = 204927252)
Else | ||
Return CShort(result) | ||
End If | ||
Return left Mod right |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't overflow, and the degenerate case, if left == Int16.MinValue
and right == -1
does not overflow and returns 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
If result < Int32.MinValue OrElse result > Int32.MaxValue Then | ||
Return result | ||
If left = Integer.MinValue AndAlso right = -1 Then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't overflow, and the degenerate case, if left == Int16.MinValue and right == -1 does not overflow and returns 0
But I have special cased the degenerate case to match ModInt64
:
Private Shared Function ModInt64(ByVal left As Int64, ByVal right As Int64) As Object
If left = Int64.MinValue AndAlso right = -1 Then
Return 0L
Else
Return left Mod right
End If
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the first line in the comment applicable here? also, do we have tests for these?
In reply to: 204927534 [](ancestors = 204927534)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few questions.
Added more tests to cover your questions |
@OmarTawfik do you mind helping me get to the bottom of these test failures? It passes on my mac and on a windows VM but there seem to be test failures on CI Example
|
The
|
As you know you can run tests against NETFX locally after you build with |
Yup - thats a bug in the implementation of ConcatenateObject and this also led me to discover bugs in the handling of DBNull. After this PR is merged I'll put together more test cases for the cases of DBNull and IConvertible etc. |
|
Hmm this is weird. I can't seem to reproduce this locally on Windows or Unix. The following throws DVE in my tests, and so does Imports System
Imports Microsoft.VisualBasic.CompilerServices
Public Module Module1
Public Sub Main()
Dim left as Int16 = -1
Dim right as Int16 = 0
Dim y as Int16 = left Mod right
End Sub
End Module These test failures are only happening in Release mode. I'm baffled! |
@OmarTawfik friendly ping - do you have any ideas? |
@mikedn do you think the test failures here in release mode for Mod by 0 are related to https://github.com/dotnet/coreclr/issues/8648 |
Is there some simple repro? It's not very clear to me which test fails. As far as I can tell the failing test involves |
Okay so the failing test is only failing in Release mode which is firstly a bit strange. It is in the following code public static IEnumerable<object[]> ModObject_DivideByZeroObject_TestData()
{
yield return new object[] { (byte)20, false };
yield return new object[] { (byte)20, null };
yield return new object[] { (byte)20, byte.MinValue };
yield return new object[] { byte.MinValue, byte.MinValue };
yield return new object[] { byte.MaxValue, byte.MinValue };
yield return new object[] { byte.MaxValue, byte.MinValue };
yield return new object[] { byte.MaxValue, byte.MinValue };
yield return new object[] { byte.MinValue, byte.MinValue };
yield return new object[] { byte.MinValue, byte.MinValue };
yield return new object[] { byte.MinValue, byte.MinValue };
yield return new object[] { (sbyte)20, false };
yield return new object[] { (sbyte)20, null };
yield return new object[] { (sbyte)20, (sbyte)0 };
yield return new object[] { (sbyte)0, (sbyte)0 };
yield return new object[] { (sbyte)(-20), (sbyte)0 };
yield return new object[] { sbyte.MaxValue, (sbyte)0 };
yield return new object[] { sbyte.MinValue, (sbyte)0 };
yield return new object[] { (ushort)20, false };
yield return new object[] { (ushort)20, null };
yield return new object[] { (ushort)20, ushort.MinValue };
yield return new object[] { ushort.MinValue, ushort.MinValue };
yield return new object[] { ushort.MaxValue, ushort.MinValue };
yield return new object[] { ushort.MaxValue, ushort.MinValue };
yield return new object[] { ushort.MaxValue, ushort.MinValue };
yield return new object[] { ushort.MinValue, ushort.MinValue };
yield return new object[] { ushort.MinValue, ushort.MinValue };
yield return new object[] { ushort.MinValue, ushort.MinValue };
yield return new object[] { (short)20, false };
yield return new object[] { (short)20, null };
yield return new object[] { (short)20, (short)0 };
yield return new object[] { (short)0, (short)0 };
yield return new object[] { (short)(-20), (short)0 };
yield return new object[] { short.MaxValue, (short)0 };
yield return new object[] { short.MinValue, (short)0 };
yield return new object[] { (uint)20, false };
yield return new object[] { (uint)20, null };
yield return new object[] { (uint)20, uint.MinValue };
yield return new object[] { uint.MinValue, uint.MinValue };
yield return new object[] { uint.MaxValue, uint.MinValue };
yield return new object[] { uint.MaxValue, uint.MinValue };
yield return new object[] { uint.MaxValue, uint.MinValue };
yield return new object[] { uint.MinValue, uint.MinValue };
yield return new object[] { uint.MinValue, uint.MinValue };
yield return new object[] { uint.MinValue, uint.MinValue };
yield return new object[] { 20, false };
yield return new object[] { 20, null };
yield return new object[] { 20, 0 };
yield return new object[] { 0, 0 };
yield return new object[] { -20, 0 };
yield return new object[] { int.MaxValue, 0 };
yield return new object[] { int.MinValue, 0 };
yield return new object[] { (ulong)20, false };
yield return new object[] { (ulong)20, null };
yield return new object[] { (ulong)20, ulong.MinValue };
yield return new object[] { ulong.MinValue, ulong.MinValue };
yield return new object[] { ulong.MaxValue, ulong.MinValue };
yield return new object[] { ulong.MaxValue, ulong.MinValue };
yield return new object[] { ulong.MaxValue, ulong.MinValue };
yield return new object[] { ulong.MinValue, ulong.MinValue };
yield return new object[] { ulong.MinValue, ulong.MinValue };
yield return new object[] { ulong.MinValue, ulong.MinValue };
yield return new object[] { (long)20, false };
yield return new object[] { (long)20, null };
yield return new object[] { (long)20, (long)0 };
yield return new object[] { (long)0, (long)0 };
yield return new object[] { (long)(-20), (long)0 };
yield return new object[] { long.MaxValue, (long)0 };
yield return new object[] { long.MinValue, (long)0 };
yield return new object[] { (decimal)20, false };
yield return new object[] { (decimal)20, null };
yield return new object[] { (decimal)20, (decimal)0 };
yield return new object[] { (decimal)0, (decimal)0 };
yield return new object[] { (decimal)(-20), (decimal)0 };
yield return new object[] { decimal.MaxValue, (decimal)0 };
yield return new object[] { decimal.MinValue, (decimal)0 };
yield return new object[] { true, false };
yield return new object[] { true, null };
yield return new object[] { null, false };
yield return new object[] { null, null };
}
[Theory]
[MemberData(nameof(ModObject_DivideByZeroObject_TestData))]
public void ModObject_DivideByZeroObject_ThrowsDivideByZeroException(object left, object right)
{
Assert.Throws<DivideByZeroException>(() => Operators.ModObject(left, right));
} The error message is
|
Thanks, this is indeed very likely to be 8648. Minimal VB repro: Module Program
Sub Main()
Dim x As Object = Convert.ToSByte(42)
Dim y As Object = Nothing
Console.WriteLine(x Mod y)
End Sub
End Module This prints 42 with the released .NET Core 2.1. The relevant 488BCE mov rcx, rsi
E8F6C77C59 call System.Convert:ToSByte(ref):byte
480FBEF0 movsx rsi, al
48B94042EA6CFF7F0000 mov rcx, 0x7FFF6CEA4240
E863BD815F call CORINFO_HELP_NEWSFAST
83FE80 cmp esi, -128
0F8CBF080000 jl G_M19509_IG65
83FE7F cmp esi, 127
0F8FB6080000 jg G_M19509_IG65
8BCE mov ecx, esi
884808 mov byte ptr [rax+8], cl
E9A0080000 jmp G_M19509_IG63 There's no trace of A fix for 8648 is in progress in dotnet/coreclr#19284. Not sure what workarounds are available until that's done. You can try to block inlining of methods such as |
@dotnet-bot test this please |
@danmosemsft ready for merge? |
This reverts commit 7c745fb.
This reverts commit 7c745fb.
The Fix for VB Mod by zero has now been checked in with Full support for exception sets in value numbering. #20129 |
* Add more VB operator tests (#31320) * Add VB operator tests * Delete dead code from VB operators * Add comparison operator tests * Add more tests * Fix VB handling of DBNull.Value * Do all number parsing in the invariant culture * Workaround https://github.com/dotnet/coreclr/issues/8648 * Accomodate for -0.0 change and fix test comparisons
* Add more VB operator tests (dotnet#31320) * Add VB operator tests * Delete dead code from VB operators * Add comparison operator tests * Add more tests * Fix VB handling of DBNull.Value * Do all number parsing in the invariant culture * Workaround https://github.com/dotnet/coreclr/issues/8648 * Accomodate for -0.0 change and fix test comparisons
* Add VB operator tests * Delete dead code from VB operators * Add comparison operator tests * Add more tests * Fix VB handling of DBNull.Value * Do all number parsing in the invariant culture * Workaround https://github.com/dotnet/coreclr/issues/8648 Commit migrated from dotnet/corefx@7c745fb
…efx#32439) This reverts commit dotnet/corefx@7c745fb. Commit migrated from dotnet/corefx@5d3db03
* Add more VB operator tests (dotnet/corefx#31320) * Add VB operator tests * Delete dead code from VB operators * Add comparison operator tests * Add more tests * Fix VB handling of DBNull.Value * Do all number parsing in the invariant culture * Workaround https://github.com/dotnet/coreclr/issues/8648 * Accomodate for -0.0 change and fix test comparisons Commit migrated from dotnet/corefx@1c34aea
Contributes to https://github.com/dotnet/corefx/issues/31407