static int test_0_byte_cast () {
int a;
long l;
+ ulong ul;
byte b = 0;
bool failed;
if (b != 0)
return -2;
+
try {
a = 256;
failed = true;
return 12;
if (b != 0)
return -12;
-
+
+ try {
+ ul = 256;
+ failed = true;
+ checked {
+ b = (byte)ul;
+ }
+ }
+ catch (OverflowException) {
+ failed = false;
+ }
+ if (failed)
+ return 13;
+ if (b != 0)
+ return -13;
+
return 0;
}
if (failed)
return 20;
if (b != 127)
- return -19;
+ return -20;
return 0;
}
static int test_0_ushort_cast () {
int a;
long l;
+ ulong ul;
ushort b;
bool failed;
if (failed)
return 12;
+ try {
+ ul = 0xfffff;
+ failed = true;
+ checked {
+ b = (ushort)ul;
+ }
+ } catch (OverflowException) {
+ failed = false;
+ }
+ if (failed)
+ return 13;
+
return 0;
}
if (failed)
return 16;
+ try {
+ l = 0x00000000ffffffff;
+ failed = true;
+ checked {
+ b = (short)l;
+ }
+ } catch (OverflowException) {
+ failed = false;
+ }
+ if (failed)
+ return 17;
+
return 0;
}
if (failed)
return 8;
+ try {
+ uint ui = System.UInt32.MaxValue;
+ failed = true;
+ checked {
+ a = (int)ui;
+ }
+ }
+ catch (OverflowException) {
+ failed = false;
+ }
+ if (failed)
+ return 9;
+
+ try {
+ ulong ul = (long)(System.Int32.MaxValue) + 1;
+ failed = true;
+ checked {
+ a = (int)ul;
+ }
+ }
+ catch (OverflowException) {
+ failed = false;
+ }
+ if (failed)
+ return 10;
+
+
{
int i;
float f = 1.1f;
if (failed)
return 8;
+ try {
+ int i = -1;
+ failed = true;
+ checked {
+ a = (uint)i;
+ }
+ }
+ catch (OverflowException) {
+ failed = false;
+ }
+ if (failed)
+ return 9;
+
{
uint i;
float f = 1.1f;
if (failed)
return 2;
-
try {
double d = System.Int64.MinValue - 1024.0;
failed = false;
ulong a;
bool failed;
+ /*
+ * These tests depend on properties of x86 fp arithmetic so they won't work
+ * on other platforms.
+ */
+
+ /*
try {
double d = System.UInt64.MaxValue - 1024.0;
failed = true;
}
if (failed)
return 2;
-
+ */
try {
double d = 0;
}
}
+ try {
+ int i = -1;
+ failed = true;
+ checked {
+ a = (ulong)i;
+ }
+ }
+ catch (OverflowException) {
+ failed = false;
+ }
+ if (failed)
+ return 5;
+
+ try {
+ int i = Int32.MinValue;
+ failed = true;
+ checked {
+ a = (ulong)i;
+ }
+ }
+ catch (OverflowException) {
+ failed = false;
+ }
+ if (failed)
+ return 6;
+
return 0;
}
if ((uint)d != 4294967295)
return 1;
+ /*
+ * These tests depend on properties of x86 fp arithmetic so they won't work
+ * on other platforms.
+ */
+ /*
d = 0xffffffffffffffff;
if ((ulong)d != 0)
if ((byte)d != 0)
return 4;
+ */
d = 0xffff;
ThrowClass.rethrow2 ();
}
catch (Exception ex) {
+ // Check that each catch clause has its own exception variable
+ // If not, the throw below will overwrite the exception used
+ // by the rethrow
+ try {
+ throw new DivideByZeroException ();
+ }
+ catch (Exception foo) {
+ }
+
throw;
}
}
}
return 1;
- }
+ }
+
+ interface IFace {}
+ class Face : IFace {}
+
+ static int test_1_array_mismatch_2 () {
+ try {
+ object [] o = new Face [1];
+ o [0] = 1;
+ return 0;
+ } catch (ArrayTypeMismatchException) {
+ return 1;
+ }
+ }
+
+ static int test_1_array_mismatch_3 () {
+ try {
+ object [] o = new IFace [1];
+ o [0] = 1;
+ return 0;
+ } catch (ArrayTypeMismatchException) {
+ return 1;
+ }
+ }
+
+ static int test_1_array_mismatch_4 () {
+ try {
+ object [][] o = new Face [5] [];
+ o [0] = new object [5];
+
+ return 0;
+ } catch (ArrayTypeMismatchException) {
+ return 1;
+ }
+ }
+
+ static int test_0_array_size () {
+ bool failed;
+
+ try {
+ failed = true;
+ int[] mem1 = new int [Int32.MaxValue];
+ }
+ catch (OutOfMemoryException e) {
+ failed = false;
+ }
+ if (failed)
+ return 1;
+
+ try {
+ failed = true;
+ int[,] mem2 = new int [Int32.MaxValue, Int32.MaxValue];
+ }
+ catch (OutOfMemoryException e) {
+ failed = false;
+ }
+ if (failed)
+ return 2;
+
+ return 0;
+ }
+
+ struct S {
+ int i, j, k, l, m, n;
+ }
+
+ static IntPtr[] addr;
+
+ static unsafe void throw_func (int i, S s) {
+ addr [i] = new IntPtr (&i);
+ throw new Exception ();
+ }
+
+ /* Test that arguments are correctly popped off the stack during unwinding */
+ static int test_0_stack_unwind () {
+ addr = new IntPtr [1000];
+ S s = new S ();
+ for (int j = 0; j < 1000; j++) {
+ try {
+ throw_func (j, s);
+ }
+ catch (Exception) {
+ }
+ }
+ return (addr [0].ToInt64 () - addr [100].ToInt64 () < 100) ? 0 : 1;
+ }
}