--- /dev/null
+// Compiler options: -unsafe
+
+using System;
+
+class PointerArithmeticTest
+{
+ unsafe static int Main()
+ {
+ try {
+ return CheckAdd((byte*)(-1), -1);
+ } catch (System.OverflowException) {}
+
+ try {
+ return CheckSub((short*)(-1), int.MaxValue);
+ } catch (System.OverflowException) {}
+
+ CheckSub2((short*)(-1), int.MaxValue);
+
+ if ((long)Conversions (long.MaxValue) != uint.MaxValue)
+ return 5;
+
+ Console.WriteLine ("OK");
+ return 0;
+ }
+
+ unsafe static int* Conversions (long b)
+ {
+ return (int*)b;
+ }
+
+ unsafe static int CheckAdd(byte* ptr, int offset)
+ {
+ if (checked(ptr + offset < ptr))
+ return 1;
+
+ return 101;
+ }
+
+ unsafe static int CheckSub(short* ptr, int offset)
+ {
+ if (checked(ptr - offset < ptr))
+ return 2;
+
+ return 102;
+ }
+
+ unsafe static int CheckSub2(short* ptr, int offset)
+ {
+ short* b = ptr + offset;
+ if (checked(ptr - b < 0))
+ return 3;
+
+ return 0;
+ }
+}
<test name="gtest-226.cs">
<type name="A">
<method name="Void .ctor()">
- <size>27</size>
+ <size>24</size>
</method>
</type>
<type name="M">
<size>7</size>
</method>
<method name="Int32 Main()">
- <size>90</size>
+ <size>84</size>
</method>
</type>
</test>
</method>
</type>
</test>
+ <test name="test-642.cs">
+ <type name="C">
+ <method name="Void .ctor()">
+ <size>7</size>
+ </method>
+ <method name="Int32 Main()">
+ <size>40</size>
+ </method>
+ </type>
+ </test>
+ <test name="test-643.cs">
+ <type name="PointerArithmeticTest">
+ <method name="Void .ctor()">
+ <size>7</size>
+ </method>
+ <method name="Int32 Main()">
+ <size>105</size>
+ </method>
+ <method name="System.Int32* Conversions(Int64)">
+ <size>3</size>
+ </method>
+ <method name="Int32 CheckAdd(System.Byte*, Int32)">
+ <size>15</size>
+ </method>
+ <method name="Int32 CheckSub(System.Int16*, Int32)">
+ <size>17</size>
+ </method>
+ <method name="Int32 CheckSub2(System.Int16*, Int32)">
+ <size>24</size>
+ </method>
+ </type>
+ </test>
<test name="test-65.cs">
<type name="X">
<method name="Void .ctor()">