diff options
author | Brian Sullivan <briansul@microsoft.com> | 2019-06-20 18:43:32 -0700 |
---|---|---|
committer | Brian Sullivan <briansul@microsoft.com> | 2019-06-20 18:43:32 -0700 |
commit | 56ea111329f8dd834795676178957d63d84ba167 (patch) | |
tree | bf672e3a510f2eb853f1cd910b84a28b8cd3d170 /tests/src/JIT/Regression/JitBlue | |
parent | d4fd282d4b3d2190f0350a2f1f92c188f0073017 (diff) | |
download | coreclr-56ea111329f8dd834795676178957d63d84ba167.tar.gz coreclr-56ea111329f8dd834795676178957d63d84ba167.tar.bz2 coreclr-56ea111329f8dd834795676178957d63d84ba167.zip |
Added the complementary test cases of going from a negative int to an unsigned.
Diffstat (limited to 'tests/src/JIT/Regression/JitBlue')
-rw-r--r-- | tests/src/JIT/Regression/JitBlue/GitHub_25134/GitHub_25134.cs | 85 |
1 files changed, 77 insertions, 8 deletions
diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_25134/GitHub_25134.cs b/tests/src/JIT/Regression/JitBlue/GitHub_25134/GitHub_25134.cs index e68e2b82e8..05b21d7a5b 100644 --- a/tests/src/JIT/Regression/JitBlue/GitHub_25134/GitHub_25134.cs +++ b/tests/src/JIT/Regression/JitBlue/GitHub_25134/GitHub_25134.cs @@ -8,26 +8,31 @@ using System.Runtime.CompilerServices; class Program { static bool s_caughtException; - static uint s_value = int.MaxValue + 1U; - static int s_result = 0; + + static uint s_uint_value = int.MaxValue + 1U; + static int s_int_result = 0; + + static int s_int_value = -1; + static uint s_uint_result = 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] static int CastToIntChecked(uint value) { + // checked cast of uint to int return checked((int)value); } - // Testing a checked cast to Uint -- the inlining case + // Testing a checked cast of uint to int -- the inlining case // [MethodImpl(MethodImplOptions.NoInlining)] static void Test1() { - int result = CastToIntChecked(s_value); - s_result = result; + int result = CastToIntChecked(s_uint_value); + s_int_result = result; Console.WriteLine("Result is " + result); } - // Testing a checked cast to Uint -- the non-inlining case + // Testing a checked cast of uint to int -- the non-inlining case // [MethodImpl(MethodImplOptions.NoInlining)] static void Test2() @@ -37,10 +42,51 @@ class Program { s_caughtException = false; - copy = s_value; + copy = s_uint_value; int result = checked((int)copy); - s_result = result; + s_int_result = result; + Console.WriteLine("Result is " + result); + } + catch (System.OverflowException ex) + { + s_caughtException = true; + Console.WriteLine("CORRECT: " + ex); + copy = 0; + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static uint CastToUIntChecked(int value) + { + // checked cast of int to uint + return checked((uint)value); + } + + // Testing a checked cast of int to uint -- the inlining case + // + [MethodImpl(MethodImplOptions.NoInlining)] + static void Test3() + { + uint result = CastToUIntChecked(s_int_value); + s_uint_result = result; + Console.WriteLine("Result is " + result); + } + + // Testing a checked cast of int to uint -- the non-inlining case + // + [MethodImpl(MethodImplOptions.NoInlining)] + static void Test4() + { + uint copy = 0; + try + { + s_caughtException = false; + + copy = s_uint_value; + + int result = checked((int)copy); + s_int_result = result; Console.WriteLine("Result is " + result); } catch (System.OverflowException ex) @@ -78,6 +124,29 @@ class Program failed = true; } + try + { + Test3(); + } + catch (System.OverflowException ex) + { + s_caughtException = true; + Console.WriteLine("CORRECT: " + ex); + } + + if (s_caughtException == false) + { + Console.WriteLine("FAILED - Test3"); + failed = true; + } + + Test4(); + if (s_caughtException == false) + { + Console.WriteLine("FAILED - Test4"); + failed = true; + } + if (failed) { return 101; |