[interp] Throw overflow exception when converting NaN (mono/mono#18384)
authorVlad Brezae <brezaevlad@gmail.com>
Thu, 9 Jan 2020 10:08:15 +0000 (12:08 +0200)
committerGitHub <noreply@github.com>
Thu, 9 Jan 2020 10:08:15 +0000 (12:08 +0200)
Fixes https://github.com/mono/mono/issues/18061

Commit migrated from https://github.com/mono/mono/commit/345550fb99a12f66054b7c1f545b4d117368c47f

src/mono/mono/mini/interp/interp.c
src/mono/netcore/CoreFX.issues_interpreter.rsp

index e7257ac..49594a9 100644 (file)
@@ -5752,13 +5752,13 @@ main_loop:
                        ++ip;
                        MINT_IN_BREAK;
                MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8)
-                       if (sp [-1].data.f < 0 || sp [-1].data.f > G_MAXINT64)
+                       if (sp [-1].data.f < 0 || sp [-1].data.f > G_MAXINT64 || isnan (sp [-1].data.f))
                                goto overflow_label;
                        sp [-1].data.l = (gint64)sp [-1].data.f;
                        ++ip;
                        MINT_IN_BREAK;
                MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R4)
-                       if (sp [-1].data.f_r4 < 0 || sp [-1].data.f_r4 > G_MAXINT64)
+                       if (sp [-1].data.f_r4 < 0 || sp [-1].data.f_r4 > G_MAXINT64 || isnan (sp [-1].data.f_r4))
                                goto overflow_label;
                        sp [-1].data.l = (gint64)sp [-1].data.f_r4;
                        ++ip;
@@ -6052,13 +6052,13 @@ main_loop:
                        ++ip;
                        MINT_IN_BREAK;
                MINT_IN_CASE(MINT_CONV_OVF_I4_R4)
-                       if (sp [-1].data.f_r4 < G_MININT32 || sp [-1].data.f_r4 > G_MAXINT32)
+                       if (sp [-1].data.f_r4 < G_MININT32 || sp [-1].data.f_r4 > G_MAXINT32 || isnan (sp [-1].data.f_r4))
                                goto overflow_label;
                        sp [-1].data.i = (gint32) sp [-1].data.f_r4;
                        ++ip;
                        MINT_IN_BREAK;
                MINT_IN_CASE(MINT_CONV_OVF_I4_R8)
-                       if (sp [-1].data.f < G_MININT32 || sp [-1].data.f > G_MAXINT32)
+                       if (sp [-1].data.f < G_MININT32 || sp [-1].data.f > G_MAXINT32 || isnan (sp [-1].data.f))
                                goto overflow_label;
                        sp [-1].data.i = (gint32) sp [-1].data.f;
                        ++ip;
@@ -6075,13 +6075,13 @@ main_loop:
                        ++ip;
                        MINT_IN_BREAK;
                MINT_IN_CASE(MINT_CONV_OVF_U4_R4)
-                       if (sp [-1].data.f_r4 < 0 || sp [-1].data.f_r4 > G_MAXUINT32)
+                       if (sp [-1].data.f_r4 < 0 || sp [-1].data.f_r4 > G_MAXUINT32 || isnan (sp [-1].data.f_r4))
                                goto overflow_label;
                        sp [-1].data.i = (guint32) sp [-1].data.f_r4;
                        ++ip;
                        MINT_IN_BREAK;
                MINT_IN_CASE(MINT_CONV_OVF_U4_R8)
-                       if (sp [-1].data.f < 0 || sp [-1].data.f > G_MAXUINT32)
+                       if (sp [-1].data.f < 0 || sp [-1].data.f > G_MAXUINT32 || isnan (sp [-1].data.f))
                                goto overflow_label;
                        sp [-1].data.i = (guint32) sp [-1].data.f;
                        ++ip;
@@ -6109,13 +6109,13 @@ main_loop:
                        ++ip;
                        MINT_IN_BREAK;
                MINT_IN_CASE(MINT_CONV_OVF_I2_R8)
-                       if (sp [-1].data.f < G_MININT16 || sp [-1].data.f > G_MAXINT16)
+                       if (sp [-1].data.f < G_MININT16 || sp [-1].data.f > G_MAXINT16 || isnan (sp [-1].data.f))
                                goto overflow_label;
                        sp [-1].data.i = (gint16) sp [-1].data.f;
                        ++ip;
                        MINT_IN_BREAK;
                MINT_IN_CASE(MINT_CONV_OVF_I2_UN_R8)
-                       if (sp [-1].data.f < 0 || sp [-1].data.f > G_MAXINT16)
+                       if (sp [-1].data.f < 0 || sp [-1].data.f > G_MAXINT16 || isnan (sp [-1].data.f))
                                goto overflow_label;
                        sp [-1].data.i = (gint16) sp [-1].data.f;
                        ++ip;
@@ -6132,7 +6132,7 @@ main_loop:
                        ++ip;
                        MINT_IN_BREAK;
                MINT_IN_CASE(MINT_CONV_OVF_U2_R8)
-                       if (sp [-1].data.f < 0 || sp [-1].data.f > G_MAXUINT16)
+                       if (sp [-1].data.f < 0 || sp [-1].data.f > G_MAXUINT16 || isnan (sp [-1].data.f))
                                goto overflow_label;
                        sp [-1].data.i = (guint16) sp [-1].data.f;
                        ++ip;
@@ -6160,13 +6160,13 @@ main_loop:
                        ++ip;
                        MINT_IN_BREAK;
                MINT_IN_CASE(MINT_CONV_OVF_I1_R8)
-                       if (sp [-1].data.f < G_MININT8 || sp [-1].data.f > G_MAXINT8)
+                       if (sp [-1].data.f < G_MININT8 || sp [-1].data.f > G_MAXINT8 || isnan (sp [-1].data.f))
                                goto overflow_label;
                        sp [-1].data.i = (gint8) sp [-1].data.f;
                        ++ip;
                        MINT_IN_BREAK;
                MINT_IN_CASE(MINT_CONV_OVF_I1_UN_R8)
-                       if (sp [-1].data.f < 0 || sp [-1].data.f > G_MAXINT8)
+                       if (sp [-1].data.f < 0 || sp [-1].data.f > G_MAXINT8 || isnan (sp [-1].data.f))
                                goto overflow_label;
                        sp [-1].data.i = (gint8) sp [-1].data.f;
                        ++ip;
@@ -6183,7 +6183,7 @@ main_loop:
                        ++ip;
                        MINT_IN_BREAK;
                MINT_IN_CASE(MINT_CONV_OVF_U1_R8)
-                       if (sp [-1].data.f < 0 || sp [-1].data.f > G_MAXUINT8)
+                       if (sp [-1].data.f < 0 || sp [-1].data.f > G_MAXUINT8 || isnan (sp [-1].data.f))
                                goto overflow_label;
                        sp [-1].data.i = (guint8) sp [-1].data.f;
                        ++ip;
index fff998f..84c2af8 100644 (file)
@@ -45,9 +45,5 @@
 -nomethod System.Runtime.Serialization.Formatters.Tests.BinaryFormatterTests.*
 -nomethod System.Net.Sockets.Tests.SendReceiveSyncForceNonBlocking.TcpReceiveSendGetsCanceledByDispose
 
-# https://github.com/mono/mono/issues/18061 [interpreter] Conversions.ToX(NaN) are expected to throw OverflowException
--nomethod Microsoft.VisualBasic.Tests.ConversionsTests.*
--nomethod Microsoft.VisualBasic.CompilerServices.Tests.IntegerTypeTests.FromString_ThrowsOverflowException
-
 # https://github.com/mono/mono/issues/18063 [interpreter] EqualityComparer<TEnum?>.Default.Equals doesn't work correctly
 -nomethod System.Collections.Generic.Tests.EqualityComparerTests.NullableEquals*