[tuner] handle the case with multiple "preserve" attributes
[mono-project.git] / mcs / tests / test-643.cs
blobf7204392ff0f28660a209d17185bcab900ead40d
1 // Compiler options: -unsafe
3 using System;
5 class PointerArithmeticTest
7 unsafe public static int Main()
9 try {
10 return CheckAdd((byte*)(-1), -1);
11 } catch (System.OverflowException) {}
13 try {
14 return CheckSub((short*)(-1), int.MaxValue);
15 } catch (System.OverflowException) {}
17 CheckSub2((short*)(-1), int.MaxValue);
19 if ((long)Conversions (long.MaxValue) != (IntPtr.Size <= 4 ? uint.MaxValue : long.MaxValue))
20 return 5;
22 Console.WriteLine ("OK");
23 return 0;
26 unsafe static int* Conversions (long b)
28 return (int*)b;
31 unsafe static int CheckAdd(byte* ptr, int offset)
33 if (checked(ptr + offset < ptr))
34 return 1;
36 return 101;
39 unsafe static int CheckSub(short* ptr, int offset)
41 if (checked(ptr - offset < ptr))
42 return 2;
44 return 102;
47 unsafe static int CheckSub2(short* ptr, int offset)
49 short* b = ptr + offset;
50 if (checked(ptr - b < 0))
51 return 3;
53 return 0;