diff --git a/docs/design/specs/Ecma-335-Augments.md b/docs/design/specs/Ecma-335-Augments.md index 546a6dbc375552..6a21e31237e941 100644 --- a/docs/design/specs/Ecma-335-Augments.md +++ b/docs/design/specs/Ecma-335-Augments.md @@ -11,6 +11,7 @@ This is a list of additions and edits to be made in ECMA-335 specifications. It - [Default Interface Methods](#default-interface-methods) - [Static Interface Methods](#static-interface-methods) - [Covariant Return Types](#covariant-return-types) +- [Unsigned data conversion with overflow detection](#unsigned-data-conversion-with-overflow-detection) ## Signatures @@ -907,4 +908,34 @@ For this example, the behavior of calls on objects of various types is presented | D | B::VirtualFunction() | ERROR | A program containing type D is not valid, as B::VirtualFunction would be implemented by D::VirtualFunction which is not *covariant-return-compatible-with* (§I.8.7.1) B::VirtualFunction | " ### II.22.27 -Edit rule 12 to specify that "The method signature defined by *MethodBody* shall match those defined by *MethodDeclaration* exactly if *MethodDeclaration* defines a method on an interface or be *covariant-return-compatible-with* (§I.8.7.1) if *MethodDeclaration* represents a method on a class." \ No newline at end of file +Edit rule 12 to specify that "The method signature defined by *MethodBody* shall match those defined by *MethodDeclaration* exactly if *MethodDeclaration* defines a method on an interface or be *covariant-return-compatible-with* (§I.8.7.1) if *MethodDeclaration* represents a method on a class." + +## Unsigned data conversion with overflow detection + +`conv.ovf..un` opcode is purposed for converting a value on the stack to an integral value while treating the stack source as unsigned. Ecma does not distinguish signed and unsigned values on the stack so such opcode is needed as a complement for `conv.ovf.`. +So if the value on the stack is 4-byte size integral created by `Ldc_I4 0xFFFFFFFF` the results of different conversion opcodes will be: + +* conv.ovf.i4 -> -1 (0xFFFFFFFF) +* conv.ovf.u4 -> overflow +* conv.ovf.i4.un -> overflow +* conv.ovf.u4.un -> uint.MaxValue (0xFFFFFFFF) + +However, the source of these opcodes can be a float value and it was not clear how in such case .un should be treated. The ECMA was saying: "The item on the top of the stack is treated as an unsigned value before the conversion." but there was no definition of "treated" so the result of: + +``` +ldc.r4 -1 +conv.ovf.i4.un +``` +was ambiguous, it could treat -1 as 0xFFFFFFFF and return 0xFFFFFFFF or it could throw an overflow exception. + +### III.3.19, conv.ovf.to type.un (page 354) +(Edit 1st Description paragraph:) +Convert the value on top of the stack to the type specified in the opcode, and leave that converted +value on the top of the stack. If the value cannot be represented, an exception is thrown. + +(Edit 2nd Description paragraph:) + +Conversions from floating-point numbers to integral values truncate the number toward zero and used as-is ignoring .un suffix. The integral item +on the top of the stack is reinterpreted as an unsigned value before the conversion. +Note that integer values of less than 4 bytes are extended to int32 (not native int) on the +evaluation stack. \ No newline at end of file diff --git a/src/tests/JIT/IL_Conformance/Convert/TestConvertFromIntegral.cs b/src/tests/JIT/IL_Conformance/Convert/TestConvertFromIntegral.cs new file mode 100644 index 00000000000000..8ab686a3fb654b --- /dev/null +++ b/src/tests/JIT/IL_Conformance/Convert/TestConvertFromIntegral.cs @@ -0,0 +1,1187 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// This is conformance test for conv described in ECMA-335 Table III.8: Conversion Operations. +// It tests int32/int64/float/double as the source and sbyte/byte/short/ushort/int/uint/long/ulong +// as the dst. + +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; +using System.Runtime.Intrinsics; +using System.Reflection; +using System.Reflection.Emit; + +namespace TestCasts +{ + class Program + { + static int failedCount = 0; + + static readonly bool ExpectException = true; + static readonly bool DontExpectException = false; + + static readonly bool UnspecifiedBehaviour = true; + + static void GenerateTest(F from, OpCode fromOpcode, OpCode convOpcode, bool exceptionExpected, T expectedTo, bool undefined = false) where F : struct where T : struct, IEquatable + { + bool checkResult = !exceptionExpected && !undefined; + Debug.Assert(!exceptionExpected || !checkResult); + Debug.Assert(checkResult || expectedTo.Equals(default(T))); + + Type[] args = new Type[] { }; // No args. + Type returnType = typeof(T); + string name = "DynamicConvertFrom" + typeof(F).FullName + "To" + typeof(T).FullName + from.ToString() + "Op" + convOpcode.Name; + DynamicMethod dm = new DynamicMethod(name, returnType, args); + + ILGenerator generator = dm.GetILGenerator(); + + if (typeof(F) == typeof(int)) generator.Emit(fromOpcode, (int)(object)from); + else if (typeof(F) == typeof(long)) generator.Emit(fromOpcode, (long)(object)from); + else if (typeof(F) == typeof(nint)) generator.Emit(fromOpcode, (nint)(object)from); + else if (typeof(F) == typeof(float)) generator.Emit(fromOpcode, (float)(object)from); + else if (typeof(F) == typeof(double)) generator.Emit(fromOpcode, (double)(object)from); + else + { + throw new NotSupportedException(); + } + + generator.Emit(convOpcode); + generator.Emit(OpCodes.Ret); + + try + { + T res = (T)dm.Invoke(null, BindingFlags.Default, null, new object[] { }, null); + if (exceptionExpected) + { + failedCount++; + Console.WriteLine("No exception in " + name); + } + if (checkResult && !expectedTo.Equals(res)) + { + failedCount++; + Console.WriteLine("Wrong result in " + name); + } + } + catch + { + if (!exceptionExpected) + { + failedCount++; + Console.WriteLine("Not expected exception in " + name); + } + } + } + + static void TestConvertFromInt4() + { + TestConvertFromInt4ToI1(); + TestConvertFromInt4ToU1(); + TestConvertFromInt4ToI2(); + TestConvertFromInt4ToU2(); + TestConvertFromInt4ToI4(); + TestConvertFromInt4ToU4(); + TestConvertFromInt4ToI8(); + TestConvertFromInt4ToU8(); + } + + static void TestConvertFromInt4ToI1() + { + OpCode sourceOp = OpCodes.Ldc_I4; + + OpCode convNoOvf = OpCodes.Conv_I1; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(sbyte.MaxValue, sourceOp, convNoOvf, DontExpectException, sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convNoOvf, DontExpectException, sbyte.MinValue); + GenerateTest(byte.MaxValue, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(byte.MinValue, sourceOp, convNoOvf, DontExpectException, (sbyte)byte.MinValue); + GenerateTest(int.MaxValue, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, 0); + + OpCode convOvf = OpCodes.Conv_Ovf_I1; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(sbyte.MaxValue, sourceOp, convOvf, DontExpectException, sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convOvf, DontExpectException, sbyte.MinValue); + GenerateTest(byte.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(byte.MinValue, sourceOp, convOvf, DontExpectException, 0); + GenerateTest(int.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(int.MinValue, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_I1_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(sbyte.MaxValue, sourceOp, convOvfUn, DontExpectException, sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(byte.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(byte.MinValue, sourceOp, convOvfUn, DontExpectException, 0); + GenerateTest(int.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(int.MinValue, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromInt4ToU1() + { + OpCode sourceOp = OpCodes.Ldc_I4; + + OpCode convNoOvf = OpCodes.Conv_U1; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, byte.MaxValue); + GenerateTest(sbyte.MaxValue, sourceOp, convNoOvf, DontExpectException, (byte)sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convNoOvf, DontExpectException, (byte)sbyte.MaxValue + 1); + GenerateTest(byte.MaxValue, sourceOp, convNoOvf, DontExpectException, byte.MaxValue); + GenerateTest(byte.MinValue, sourceOp, convNoOvf, DontExpectException, byte.MinValue); + GenerateTest(int.MaxValue, sourceOp, convNoOvf, DontExpectException, byte.MaxValue); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, 0); + + OpCode convOvf = OpCodes.Conv_Ovf_U1; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, ExpectException, 0); + GenerateTest(sbyte.MaxValue, sourceOp, convOvf, DontExpectException, (byte)sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(byte.MaxValue, sourceOp, convOvf, DontExpectException, byte.MaxValue); + GenerateTest(byte.MinValue, sourceOp, convOvf, DontExpectException, byte.MinValue); + GenerateTest(int.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(int.MinValue, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_U1_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(sbyte.MaxValue, sourceOp, convOvfUn, DontExpectException, (byte)sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(byte.MaxValue, sourceOp, convOvfUn, DontExpectException, byte.MaxValue); + GenerateTest(byte.MinValue, sourceOp, convOvfUn, DontExpectException, byte.MinValue); + GenerateTest(int.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(int.MinValue, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromInt4ToI2() + { + OpCode sourceOp = OpCodes.Ldc_I4; + + OpCode convNoOvf = OpCodes.Conv_I2; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(short.MaxValue, sourceOp, convNoOvf, DontExpectException, short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convNoOvf, DontExpectException, short.MinValue); + GenerateTest(ushort.MaxValue, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(ushort.MinValue, sourceOp, convNoOvf, DontExpectException, 0); + GenerateTest(int.MaxValue, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, 0); + + OpCode convOvf = OpCodes.Conv_Ovf_I2; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(short.MaxValue, sourceOp, convOvf, DontExpectException, short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convOvf, DontExpectException, short.MinValue); + GenerateTest(ushort.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(ushort.MinValue, sourceOp, convOvf, DontExpectException, 0); + GenerateTest(int.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(int.MinValue, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_I2_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(short.MaxValue, sourceOp, convOvfUn, DontExpectException, short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(ushort.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(ushort.MinValue, sourceOp, convOvfUn, DontExpectException, 0); + GenerateTest(int.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(int.MinValue, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromInt4ToU2() + { + OpCode sourceOp = OpCodes.Ldc_I4; + + OpCode convNoOvf = OpCodes.Conv_U2; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, ushort.MaxValue); + GenerateTest(short.MaxValue, sourceOp, convNoOvf, DontExpectException, (ushort)short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convNoOvf, DontExpectException, (short)short.MaxValue + 1); + GenerateTest(ushort.MaxValue, sourceOp, convNoOvf, DontExpectException, ushort.MaxValue); + GenerateTest(ushort.MinValue, sourceOp, convNoOvf, DontExpectException, ushort.MinValue); + GenerateTest(int.MaxValue, sourceOp, convNoOvf, DontExpectException, ushort.MaxValue); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, 0); + + OpCode convOvf = OpCodes.Conv_Ovf_U2; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, ExpectException, 0); + GenerateTest(short.MaxValue, sourceOp, convOvf, DontExpectException, (ushort)short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(ushort.MaxValue, sourceOp, convOvf, DontExpectException, ushort.MaxValue); + GenerateTest(ushort.MinValue, sourceOp, convOvf, DontExpectException, ushort.MinValue); + GenerateTest(int.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(int.MinValue, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_U2_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(short.MaxValue, sourceOp, convOvfUn, DontExpectException, (ushort)short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(ushort.MaxValue, sourceOp, convOvfUn, DontExpectException, ushort.MaxValue); + GenerateTest(ushort.MinValue, sourceOp, convOvfUn, DontExpectException, ushort.MinValue); + GenerateTest(int.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(int.MinValue, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromInt4ToI4() + { + OpCode sourceOp = OpCodes.Ldc_I4; + + OpCode convNoOvf = OpCodes.Conv_I4; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(int.MaxValue, sourceOp, convNoOvf, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, int.MinValue); + + OpCode convOvf = OpCodes.Conv_Ovf_I4; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(int.MaxValue, sourceOp, convOvf, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convOvf, DontExpectException, int.MinValue); + + OpCode convOvfUn = OpCodes.Conv_Ovf_I4_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(int.MaxValue, sourceOp, convOvfUn, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromInt4ToU4() + { + OpCode sourceOp = OpCodes.Ldc_I4; + + OpCode convNoOvf = OpCodes.Conv_U4; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, uint.MaxValue); + GenerateTest(int.MaxValue, sourceOp, convNoOvf, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, (uint)int.MaxValue + 1); + + OpCode convOvf = OpCodes.Conv_Ovf_U4; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, ExpectException, 0); + GenerateTest(int.MaxValue, sourceOp, convOvf, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_U4_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, DontExpectException, uint.MaxValue); + GenerateTest(int.MaxValue, sourceOp, convOvfUn, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convOvfUn, DontExpectException, (uint)int.MaxValue + 1); + } + + static void TestConvertFromInt4ToI8() + { + OpCode sourceOp = OpCodes.Ldc_I4; + + OpCode convNoOvf = OpCodes.Conv_I8; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(int.MaxValue, sourceOp, convNoOvf, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, int.MinValue); + + OpCode convOvf = OpCodes.Conv_Ovf_I8; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(int.MaxValue, sourceOp, convOvf, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convOvf, DontExpectException, int.MinValue); + + OpCode convOvfUn = OpCodes.Conv_Ovf_I8_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, DontExpectException, uint.MaxValue); + GenerateTest(int.MaxValue, sourceOp, convOvfUn, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convOvfUn, DontExpectException, (long)int.MaxValue + 1); + } + + static void TestConvertFromInt4ToU8() + { + OpCode sourceOp = OpCodes.Ldc_I4; + + OpCode convNoOvf = OpCodes.Conv_U8; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, uint.MaxValue); + GenerateTest(int.MaxValue, sourceOp, convNoOvf, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, (ulong)int.MaxValue + 1); + + OpCode convOvf = OpCodes.Conv_Ovf_U8; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, ExpectException, 0); + GenerateTest(int.MaxValue, sourceOp, convOvf, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_U8_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, DontExpectException, uint.MaxValue); + GenerateTest(int.MaxValue, sourceOp, convOvfUn, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convOvfUn, DontExpectException, (ulong)int.MaxValue + 1); + } + + static void TestConvertFromInt8() + { + TestConvertFromInt8ToI1(); + TestConvertFromInt8ToU1(); + TestConvertFromInt8ToI2(); + TestConvertFromInt8ToU2(); + TestConvertFromInt8ToI4(); + TestConvertFromInt8ToU4(); + TestConvertFromInt8ToI8(); + TestConvertFromInt8ToU8(); + } + + static void TestConvertFromInt8ToI1() + { + OpCode sourceOp = OpCodes.Ldc_I8; + + OpCode convNoOvf = OpCodes.Conv_I1; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(sbyte.MaxValue, sourceOp, convNoOvf, DontExpectException, sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convNoOvf, DontExpectException, sbyte.MinValue); + GenerateTest(byte.MaxValue, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(byte.MinValue, sourceOp, convNoOvf, DontExpectException, (sbyte)byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0); + + OpCode convOvf = OpCodes.Conv_Ovf_I1; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(sbyte.MaxValue, sourceOp, convOvf, DontExpectException, sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convOvf, DontExpectException, sbyte.MinValue); + GenerateTest(byte.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(byte.MinValue, sourceOp, convOvf, DontExpectException, (sbyte)byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_I1_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(sbyte.MaxValue, sourceOp, convOvfUn, DontExpectException, sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(byte.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(byte.MinValue, sourceOp, convOvfUn, DontExpectException, (sbyte)byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromInt8ToU1() + { + OpCode sourceOp = OpCodes.Ldc_I8; + + OpCode convNoOvf = OpCodes.Conv_U1; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, byte.MaxValue); + GenerateTest(sbyte.MaxValue, sourceOp, convNoOvf, DontExpectException, (byte)sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convNoOvf, DontExpectException, (byte)sbyte.MaxValue + 1); + GenerateTest(byte.MaxValue, sourceOp, convNoOvf, DontExpectException, byte.MaxValue); + GenerateTest(byte.MinValue, sourceOp, convNoOvf, DontExpectException, byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, byte.MaxValue); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0); + + OpCode convOvf = OpCodes.Conv_Ovf_U1; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, ExpectException, 0); + GenerateTest(sbyte.MaxValue, sourceOp, convOvf, DontExpectException, (byte)sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(byte.MaxValue, sourceOp, convOvf, DontExpectException, byte.MaxValue); + GenerateTest(byte.MinValue, sourceOp, convOvf, DontExpectException, byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_U1_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(sbyte.MaxValue, sourceOp, convOvfUn, DontExpectException, (byte)sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(byte.MaxValue, sourceOp, convOvfUn, DontExpectException, byte.MaxValue); + GenerateTest(byte.MinValue, sourceOp, convOvfUn, DontExpectException, byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromInt8ToI2() + { + OpCode sourceOp = OpCodes.Ldc_I8; + + OpCode convNoOvf = OpCodes.Conv_I2; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(short.MaxValue, sourceOp, convNoOvf, DontExpectException, short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convNoOvf, DontExpectException, short.MinValue); + GenerateTest(ushort.MaxValue, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(ushort.MinValue, sourceOp, convNoOvf, DontExpectException, byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0); + + OpCode convOvf = OpCodes.Conv_Ovf_I2; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(short.MaxValue, sourceOp, convOvf, DontExpectException, short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convOvf, DontExpectException, short.MinValue); + GenerateTest(ushort.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(ushort.MinValue, sourceOp, convOvf, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_I2_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(short.MaxValue, sourceOp, convOvfUn, DontExpectException, short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(ushort.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(ushort.MinValue, sourceOp, convOvfUn, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromInt8ToU2() + { + OpCode sourceOp = OpCodes.Ldc_I8; + + OpCode convNoOvf = OpCodes.Conv_U2; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, ushort.MaxValue); + GenerateTest(short.MaxValue, sourceOp, convNoOvf, DontExpectException, (ushort)short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convNoOvf, DontExpectException, (ushort)short.MaxValue + 1); + GenerateTest(ushort.MaxValue, sourceOp, convNoOvf, DontExpectException, ushort.MaxValue); + GenerateTest(ushort.MinValue, sourceOp, convNoOvf, DontExpectException, ushort.MinValue); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, ushort.MaxValue); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0); + + OpCode convOvf = OpCodes.Conv_Ovf_U2; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, ExpectException, 0); + GenerateTest(short.MaxValue, sourceOp, convOvf, DontExpectException, (ushort)short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(ushort.MaxValue, sourceOp, convOvf, DontExpectException, ushort.MaxValue); + GenerateTest(ushort.MinValue, sourceOp, convOvf, DontExpectException, ushort.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_U2_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(short.MaxValue, sourceOp, convOvfUn, DontExpectException, (ushort)short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(ushort.MaxValue, sourceOp, convOvfUn, DontExpectException, ushort.MaxValue); + GenerateTest(ushort.MinValue, sourceOp, convOvfUn, DontExpectException, ushort.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromInt8ToI4() + { + OpCode sourceOp = OpCodes.Ldc_I8; + + OpCode convNoOvf = OpCodes.Conv_I4; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(int.MaxValue, sourceOp, convNoOvf, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, int.MinValue); + GenerateTest(uint.MaxValue, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(uint.MinValue, sourceOp, convNoOvf, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0); + + OpCode convOvf = OpCodes.Conv_Ovf_I4; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(int.MaxValue, sourceOp, convOvf, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convOvf, DontExpectException, int.MinValue); + GenerateTest(uint.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(uint.MinValue, sourceOp, convOvf, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_I4_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(int.MaxValue, sourceOp, convOvfUn, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(uint.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(uint.MinValue, sourceOp, convOvfUn, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromInt8ToU4() + { + OpCode sourceOp = OpCodes.Ldc_I8; + + OpCode convNoOvf = OpCodes.Conv_U4; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, uint.MaxValue); + GenerateTest(int.MaxValue, sourceOp, convNoOvf, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, (uint)int.MaxValue + 1); + GenerateTest(uint.MaxValue, sourceOp, convNoOvf, DontExpectException, uint.MaxValue); + GenerateTest(uint.MinValue, sourceOp, convNoOvf, DontExpectException, uint.MinValue); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, uint.MaxValue); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0); + + OpCode convOvf = OpCodes.Conv_Ovf_U4; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, ExpectException, 0); + GenerateTest(int.MaxValue, sourceOp, convOvf, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(uint.MaxValue, sourceOp, convOvf, DontExpectException, uint.MaxValue); + GenerateTest(uint.MinValue, sourceOp, convOvf, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_U4_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(int.MaxValue, sourceOp, convOvfUn, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(uint.MaxValue, sourceOp, convOvfUn, DontExpectException, uint.MaxValue); + GenerateTest(uint.MinValue, sourceOp, convOvfUn, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromInt8ToI8() + { + OpCode sourceOp = OpCodes.Ldc_I8; + + OpCode convNoOvf = OpCodes.Conv_I8; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(int.MaxValue, sourceOp, convNoOvf, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, int.MinValue); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, long.MaxValue); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, long.MinValue); + + OpCode convOvf = OpCodes.Conv_Ovf_I8; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(int.MaxValue, sourceOp, convOvf, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convOvf, DontExpectException, int.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvf, DontExpectException, long.MaxValue); + GenerateTest(long.MinValue, sourceOp, convOvf, DontExpectException, long.MinValue); + + OpCode convOvfUn = OpCodes.Conv_Ovf_I8_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(int.MaxValue, sourceOp, convOvfUn, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, DontExpectException, long.MaxValue); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromInt8ToU8() + { + OpCode sourceOp = OpCodes.Ldc_I8; + + OpCode convNoOvf = OpCodes.Conv_U8; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, ulong.MaxValue); + GenerateTest(int.MaxValue, sourceOp, convNoOvf, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, 0xffffffff80000000UL); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, long.MaxValue); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, (ulong)long.MaxValue + 1); + + OpCode convOvf = OpCodes.Conv_Ovf_U8; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, ExpectException, 0); + GenerateTest(int.MaxValue, sourceOp, convOvf, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvf, DontExpectException, long.MaxValue); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_U8_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, DontExpectException, ulong.MaxValue); + GenerateTest(int.MaxValue, sourceOp, convOvfUn, DontExpectException, int.MaxValue); + GenerateTest(int.MinValue, sourceOp, convOvfUn, DontExpectException, ulong.MaxValue - int.MaxValue); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, DontExpectException, long.MaxValue); + GenerateTest(long.MinValue, sourceOp, convOvfUn, DontExpectException, (ulong)long.MaxValue + 1); + } + + + static void TestConvertFromFloat() + { + TestConvertFromFloatToI1(); + TestConvertFromFloatToU1(); + TestConvertFromFloatToI2(); + TestConvertFromFloatToU2(); + TestConvertFromFloatToI4(); + TestConvertFromFloatToU4(); + TestConvertFromFloatToI8(); + TestConvertFromFloatToU8(); + } + + static void TestConvertFromFloatToI1() + { + OpCode sourceOp = OpCodes.Ldc_R4; + + OpCode convNoOvf = OpCodes.Conv_I1; + GenerateTest(1F, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1F, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(1.1F, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1.1F, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(sbyte.MaxValue, sourceOp, convNoOvf, DontExpectException, sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convNoOvf, DontExpectException, sbyte.MinValue); + GenerateTest(byte.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(byte.MinValue, sourceOp, convNoOvf, DontExpectException, (sbyte)byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + + OpCode convOvf = OpCodes.Conv_Ovf_I1; + GenerateTest(1F, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1F, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(1.1F, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1.1F, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(sbyte.MaxValue, sourceOp, convOvf, DontExpectException, sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convOvf, DontExpectException, sbyte.MinValue); + GenerateTest(byte.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(byte.MinValue, sourceOp, convOvf, DontExpectException, (sbyte)byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_I1_Un; + GenerateTest(1F, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1F, sourceOp, convOvfUn, DontExpectException, -1); + GenerateTest(1.1F, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1.1F, sourceOp, convOvfUn, DontExpectException, -1); + GenerateTest(sbyte.MaxValue, sourceOp, convOvfUn, DontExpectException, sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convOvfUn, DontExpectException, sbyte.MinValue); + GenerateTest(byte.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(byte.MinValue, sourceOp, convOvfUn, DontExpectException, (sbyte)byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromFloatToU1() + { + OpCode sourceOp = OpCodes.Ldc_R4; + + OpCode convNoOvf = OpCodes.Conv_U1; + GenerateTest(1F, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1F, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(sbyte.MaxValue, sourceOp, convNoOvf, DontExpectException, (byte)sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(byte.MaxValue, sourceOp, convNoOvf, DontExpectException, byte.MaxValue); + GenerateTest(byte.MinValue, sourceOp, convNoOvf, DontExpectException, byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + + OpCode convOvf = OpCodes.Conv_Ovf_U1; + GenerateTest(1F, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(1.9F, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1F, sourceOp, convOvf, ExpectException, 0); + GenerateTest(sbyte.MaxValue, sourceOp, convOvf, DontExpectException, (byte)sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(byte.MaxValue, sourceOp, convOvf, DontExpectException, byte.MaxValue); + GenerateTest(byte.MinValue, sourceOp, convOvf, DontExpectException, byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvf, ExpectException, 0); + + + OpCode convOvfUn = OpCodes.Conv_Ovf_U1_Un; + GenerateTest(1F, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(2.2F, sourceOp, convOvfUn, DontExpectException, 2); + GenerateTest(-1F, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(sbyte.MaxValue, sourceOp, convOvfUn, DontExpectException, (byte)sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(byte.MaxValue, sourceOp, convOvfUn, DontExpectException, byte.MaxValue); + GenerateTest(byte.MinValue, sourceOp, convOvfUn, DontExpectException, byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromFloatToI2() + { + OpCode sourceOp = OpCodes.Ldc_R4; + + OpCode convNoOvf = OpCodes.Conv_I2; + GenerateTest(1F, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1F, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(short.MaxValue, sourceOp, convNoOvf, DontExpectException, short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convNoOvf, DontExpectException, short.MinValue); + GenerateTest(ushort.MaxValue, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(ushort.MinValue, sourceOp, convNoOvf, DontExpectException, byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + + OpCode convOvf = OpCodes.Conv_Ovf_I2; + GenerateTest(1F, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(1.2F, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1F, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(-1.8F, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(short.MaxValue, sourceOp, convOvf, DontExpectException, short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convOvf, DontExpectException, short.MinValue); + GenerateTest(ushort.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(ushort.MinValue, sourceOp, convOvf, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_I2_Un; + GenerateTest(1F, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(1.5F, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1.5F, sourceOp, convOvfUn, DontExpectException, -1); + GenerateTest(short.MaxValue, sourceOp, convOvfUn, DontExpectException, short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convOvfUn, DontExpectException, short.MinValue); + GenerateTest(ushort.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(ushort.MinValue, sourceOp, convOvfUn, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromFloatToU2() + { + OpCode sourceOp = OpCodes.Ldc_R4; + + OpCode convNoOvf = OpCodes.Conv_U2; + GenerateTest(1F, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(3.9F, sourceOp, convNoOvf, DontExpectException, 3); + GenerateTest(-1F, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + + GenerateTest(short.MaxValue, sourceOp, convNoOvf, DontExpectException, (ushort)short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(ushort.MaxValue, sourceOp, convNoOvf, DontExpectException, ushort.MaxValue); + GenerateTest(ushort.MinValue, sourceOp, convNoOvf, DontExpectException, ushort.MinValue); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + + OpCode convOvf = OpCodes.Conv_Ovf_U2; + GenerateTest(1F, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(1.3F, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1F, sourceOp, convOvf, ExpectException, 0); + GenerateTest(short.MaxValue, sourceOp, convOvf, DontExpectException, (ushort)short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(ushort.MaxValue, sourceOp, convOvf, DontExpectException, ushort.MaxValue); + GenerateTest(ushort.MinValue, sourceOp, convOvf, DontExpectException, ushort.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_U2_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(short.MaxValue, sourceOp, convOvfUn, DontExpectException, (ushort)short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(ushort.MaxValue, sourceOp, convOvfUn, DontExpectException, ushort.MaxValue); + GenerateTest(ushort.MinValue, sourceOp, convOvfUn, DontExpectException, ushort.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromFloatToI4() + { + OpCode sourceOp = OpCodes.Ldc_R4; + + OpCode convNoOvf = OpCodes.Conv_I4; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, int.MinValue); + GenerateTest(uint.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(uint.MinValue, sourceOp, convNoOvf, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + + OpCode convOvfUn = OpCodes.Conv_Ovf_I4_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, DontExpectException, -1); + GenerateTest(int.MinValue, sourceOp, convOvfUn, DontExpectException, int.MinValue); + GenerateTest(uint.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(uint.MinValue, sourceOp, convOvfUn, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromFloatToU4() + { + OpCode sourceOp = OpCodes.Ldc_R4; + + OpCode convNoOvf = OpCodes.Conv_U4; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(uint.MinValue, sourceOp, convNoOvf, DontExpectException, uint.MinValue); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + + OpCode convOvf = OpCodes.Conv_Ovf_U4; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, ExpectException, 0); + GenerateTest(int.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(uint.MinValue, sourceOp, convOvf, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_U4_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(int.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(uint.MinValue, sourceOp, convOvfUn, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromFloatToI8() + { + OpCode sourceOp = OpCodes.Ldc_R4; + + OpCode convNoOvf = OpCodes.Conv_I8; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, int.MinValue); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, long.MinValue); + + OpCode convOvf = OpCodes.Conv_Ovf_I8; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(int.MinValue, sourceOp, convOvf, DontExpectException, int.MinValue); + GenerateTest(long.MinValue, sourceOp, convOvf, DontExpectException, long.MinValue); + GenerateTest(Single.NaN, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_I8_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, DontExpectException, -1); + GenerateTest(int.MinValue, sourceOp, convOvfUn, DontExpectException, int.MinValue); + GenerateTest(long.MinValue, sourceOp, convOvfUn, DontExpectException, long.MinValue); + GenerateTest(Single.NaN, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromFloatToU8() + { + OpCode sourceOp = OpCodes.Ldc_R4; + + OpCode convNoOvf = OpCodes.Conv_U8; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + + OpCode convOvf = OpCodes.Conv_Ovf_U8; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, ExpectException, 0); + GenerateTest(int.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_U8_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(int.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromDouble() + { + TestConvertFromDoubleToI1(); + TestConvertFromDoubleToU1(); + TestConvertFromDoubleToI2(); + TestConvertFromDoubleToU2(); + TestConvertFromDoubleToI4(); + TestConvertFromDoubleToU4(); + TestConvertFromDoubleToI8(); + TestConvertFromDoubleToU8(); + } + + static void TestConvertFromDoubleToI1() + { + OpCode sourceOp = OpCodes.Ldc_R8; + + OpCode convNoOvf = OpCodes.Conv_I1; + GenerateTest(1F, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1F, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(1.1F, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1.1F, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(sbyte.MaxValue, sourceOp, convNoOvf, DontExpectException, sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convNoOvf, DontExpectException, sbyte.MinValue); + GenerateTest(byte.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(byte.MinValue, sourceOp, convNoOvf, DontExpectException, (sbyte)byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + + OpCode convOvf = OpCodes.Conv_Ovf_I1; + GenerateTest(1F, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1F, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(1.1F, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1.1F, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(sbyte.MaxValue, sourceOp, convOvf, DontExpectException, sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convOvf, DontExpectException, sbyte.MinValue); + GenerateTest(byte.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(byte.MinValue, sourceOp, convOvf, DontExpectException, (sbyte)byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_I1_Un; + GenerateTest(1F, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1F, sourceOp, convOvfUn, DontExpectException, -1); + GenerateTest(1.1F, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1.1F, sourceOp, convOvfUn, DontExpectException, -1); + GenerateTest(sbyte.MaxValue, sourceOp, convOvfUn, DontExpectException, sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convOvfUn, DontExpectException, sbyte.MinValue); + GenerateTest(byte.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(byte.MinValue, sourceOp, convOvfUn, DontExpectException, (sbyte)byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromDoubleToU1() + { + OpCode sourceOp = OpCodes.Ldc_R8; + + OpCode convNoOvf = OpCodes.Conv_U1; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(sbyte.MaxValue, sourceOp, convNoOvf, DontExpectException, (byte)sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(byte.MaxValue, sourceOp, convNoOvf, DontExpectException, byte.MaxValue); + GenerateTest(byte.MinValue, sourceOp, convNoOvf, DontExpectException, byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + + OpCode convOvf = OpCodes.Conv_Ovf_U1; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, ExpectException, 0); + GenerateTest(sbyte.MaxValue, sourceOp, convOvf, DontExpectException, (byte)sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(byte.MaxValue, sourceOp, convOvf, DontExpectException, byte.MaxValue); + GenerateTest(byte.MinValue, sourceOp, convOvf, DontExpectException, byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_U1_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(sbyte.MaxValue, sourceOp, convOvfUn, DontExpectException, (byte)sbyte.MaxValue); + GenerateTest(sbyte.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(byte.MaxValue, sourceOp, convOvfUn, DontExpectException, byte.MaxValue); + GenerateTest(byte.MinValue, sourceOp, convOvfUn, DontExpectException, byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromDoubleToI2() + { + OpCode sourceOp = OpCodes.Ldc_R8; + + OpCode convNoOvf = OpCodes.Conv_I2; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(short.MaxValue, sourceOp, convNoOvf, DontExpectException, short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convNoOvf, DontExpectException, short.MinValue); + GenerateTest(ushort.MaxValue, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(ushort.MinValue, sourceOp, convNoOvf, DontExpectException, byte.MinValue); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + + OpCode convOvf = OpCodes.Conv_Ovf_I2; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(short.MaxValue, sourceOp, convOvf, DontExpectException, short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convOvf, DontExpectException, short.MinValue); + GenerateTest(ushort.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(ushort.MinValue, sourceOp, convOvf, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_I2_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, DontExpectException, -1); + GenerateTest(short.MaxValue, sourceOp, convOvfUn, DontExpectException, short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convOvfUn, DontExpectException, short.MinValue); + GenerateTest(ushort.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(ushort.MinValue, sourceOp, convOvfUn, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromDoubleToU2() + { + OpCode sourceOp = OpCodes.Ldc_R8; + + OpCode convNoOvf = OpCodes.Conv_U2; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(short.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(short.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(ushort.MaxValue, sourceOp, convNoOvf, DontExpectException, ushort.MaxValue); + GenerateTest(ushort.MinValue, sourceOp, convNoOvf, DontExpectException, ushort.MinValue); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + + OpCode convOvf = OpCodes.Conv_Ovf_U2; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, ExpectException, 0); + GenerateTest(short.MaxValue, sourceOp, convOvf, DontExpectException, (ushort)short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(ushort.MaxValue, sourceOp, convOvf, DontExpectException, ushort.MaxValue); + GenerateTest(ushort.MinValue, sourceOp, convOvf, DontExpectException, ushort.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_U2_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(short.MaxValue, sourceOp, convOvfUn, DontExpectException, (ushort)short.MaxValue); + GenerateTest(short.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(ushort.MaxValue, sourceOp, convOvfUn, DontExpectException, ushort.MaxValue); + GenerateTest(ushort.MinValue, sourceOp, convOvfUn, DontExpectException, ushort.MinValue); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromDoubleToI4() + { + OpCode sourceOp = OpCodes.Ldc_R8; + + OpCode convNoOvf = OpCodes.Conv_I4; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, int.MinValue); + GenerateTest(uint.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(uint.MinValue, sourceOp, convNoOvf, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + + OpCode convOvf = OpCodes.Conv_Ovf_I4; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(int.MinValue, sourceOp, convOvf, DontExpectException, int.MinValue); + GenerateTest(uint.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(uint.MinValue, sourceOp, convOvf, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_I4_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, DontExpectException, -1); + GenerateTest(int.MinValue, sourceOp, convOvfUn, DontExpectException, int.MinValue); + GenerateTest(uint.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(uint.MinValue, sourceOp, convOvfUn, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromDoubleToU4() + { + OpCode sourceOp = OpCodes.Ldc_R8; + + OpCode convNoOvf = OpCodes.Conv_U4; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(uint.MinValue, sourceOp, convNoOvf, DontExpectException, uint.MinValue); + GenerateTest(long.MaxValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + + OpCode convOvf = OpCodes.Conv_Ovf_U4; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, ExpectException, 0); + GenerateTest(int.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(uint.MinValue, sourceOp, convOvf, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_U4_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(int.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(uint.MinValue, sourceOp, convOvfUn, DontExpectException, 0); + GenerateTest(long.MaxValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromDoubleToI8() + { + OpCode sourceOp = OpCodes.Ldc_R8; + + OpCode convNoOvf = OpCodes.Conv_I8; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, -1); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, int.MinValue); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, long.MinValue); + + OpCode convOvf = OpCodes.Conv_Ovf_I8; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, DontExpectException, -1); + GenerateTest(int.MinValue, sourceOp, convOvf, DontExpectException, int.MinValue); + GenerateTest(long.MinValue, sourceOp, convOvf, DontExpectException, long.MinValue); + GenerateTest(Single.NaN, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_I8_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, DontExpectException, -1); + GenerateTest(int.MinValue, sourceOp, convOvfUn, DontExpectException, int.MinValue); + GenerateTest(long.MinValue, sourceOp, convOvfUn, DontExpectException, long.MinValue); + GenerateTest(-9E+18, sourceOp, convOvfUn, DontExpectException, (long)-9E+18); + GenerateTest(9E+18, sourceOp, convOvfUn, DontExpectException, (long)9E+18); + GenerateTest(18E+18, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(Single.NaN, sourceOp, convOvfUn, ExpectException, 0); + } + + static void TestConvertFromDoubleToU8() + { + OpCode sourceOp = OpCodes.Ldc_R8; + + OpCode convNoOvf = OpCodes.Conv_U8; + GenerateTest(1, sourceOp, convNoOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(int.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + GenerateTest(long.MinValue, sourceOp, convNoOvf, DontExpectException, 0, UnspecifiedBehaviour); + + OpCode convOvf = OpCodes.Conv_Ovf_U8; + GenerateTest(1, sourceOp, convOvf, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvf, ExpectException, 0); + GenerateTest(int.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvf, ExpectException, 0); + GenerateTest(-9E+18, sourceOp, convOvf, ExpectException, 0); + GenerateTest(9E+18, sourceOp, convOvf, DontExpectException, (ulong)9E+18); + GenerateTest(18E+18, sourceOp, convOvf, DontExpectException, (ulong)18E+18); + GenerateTest(Single.NaN, sourceOp, convOvf, ExpectException, 0); + + OpCode convOvfUn = OpCodes.Conv_Ovf_U8_Un; + GenerateTest(1, sourceOp, convOvfUn, DontExpectException, 1); + GenerateTest(-1, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(int.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(long.MinValue, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(-9E+18, sourceOp, convOvfUn, ExpectException, 0); + GenerateTest(9E+18, sourceOp, convOvfUn, DontExpectException, (ulong)9E+18); + GenerateTest(18E+18, sourceOp, convOvfUn, DontExpectException, (ulong)18E+18); + GenerateTest(Single.NaN, sourceOp, convOvfUn, ExpectException, 0); + } + + static int Main(string[] args) + { + TestConvertFromInt4(); + TestConvertFromInt8(); + TestConvertFromFloat(); + TestConvertFromDouble(); + if (failedCount > 0) + { + Console.WriteLine("The number of failed tests: " + failedCount); + return 101; + } + else + { + Console.WriteLine("All tests passed"); + return 100; + } + + } + } +} diff --git a/src/tests/JIT/IL_Conformance/Convert/TestConvertFromIntegral.csproj b/src/tests/JIT/IL_Conformance/Convert/TestConvertFromIntegral.csproj new file mode 100644 index 00000000000000..0d098d9ebdad52 --- /dev/null +++ b/src/tests/JIT/IL_Conformance/Convert/TestConvertFromIntegral.csproj @@ -0,0 +1,24 @@ + + + Exe + 1 + + + None + True + + + + + + + + + + diff --git a/src/tests/issues.targets b/src/tests/issues.targets index bb72c2b2bc0786..b99a5ef7f21ed0 100644 --- a/src/tests/issues.targets +++ b/src/tests/issues.targets @@ -1659,6 +1659,9 @@ Tests coreclr JIT's debug poisoning of address taken variables + + https://github.com/dotnet/runtime/issues/56784 +