summaryrefslogtreecommitdiff
path: root/tests/src/JIT/jit64/regress/vsw/373472/test.cs
blob: 47d9b53882575b731e5e39c410001a9d2d4e1df0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

// This test is used to try out very large decrementing loop strides.  The strides cannot be negated if the integer
// is too large.  For example, a stride of 0xA0000000 cannot be turned into a signed number.  For the most
// part, other things prevent us from getting to OSR with a condition like this but it's good to have
// coverage for large strides.

public class StrideTest
{
    public static int Main()
    {
        bool pass = true;
        pass &= Test1();
        pass &= Test2();
        pass &= Test3();

        return (pass ? 100 : 1);
    }

    public static bool Test1()
    {
        try
        {
            uint[] array = new uint[0x8ffffff];
            for (uint i = 0x8fffffe; true; i -= 0xa0000001)
            {
                array[i] = 40;
            }
        }
        catch (IndexOutOfRangeException)
        {
            return true;
        }
        catch (Exception e)
        {
            Console.WriteLine("test1 exception: {0}", e.ToString());
        }

        Console.WriteLine("Test1 failed");
        return false;
    }

    public static bool Test2()
    {
        try
        {
            uint[] array = new uint[0x8ffffff];
            for (uint i = 0; true; i -= 0xa0a0a0a0)
            {
                array[i] = i;
            }
        }
        catch (IndexOutOfRangeException)
        {
            return true;
        }
        catch (Exception e)
        {
            Console.WriteLine("test2 exception: {0}", e.ToString());
        }

        Console.WriteLine("Test2 failed");
        return false;
    }

    public static bool Test3()
    {
        try
        {
            int[] array = new int[0x8ffffff];
            for (long i = 0x8ffffffL - 1; i > 0x8ffffffL - 0xa0a0a0a0L - 1000; i -= 0xa0a0a0a0L)
            {
                array[i] = (int)i;
            }
        }
        catch (IndexOutOfRangeException)
        {
            return true;
        }
        catch (OverflowException)
        {
            // This could potentially produce an overflow exception on x86 when calculating
            // address offset.
            return true;
        }
        catch (Exception e)
        {
            Console.WriteLine("test3 exception: {0}", e.ToString());
        }

        Console.WriteLine("Test3 failed");
        return false;
    }

    public static bool Test4()
    {
        try
        {
            ulong[] array = new ulong[0xfffffff];
            ulong i = 0xa000000000000002;
            while (true)
            {
                i -= 0xa000000000000001;
                array[i] = i;
            }
        }
        catch (IndexOutOfRangeException)
        {
            return true;
        }
        catch (Exception) { }

        Console.WriteLine("Test4 failed");
        return false;
    }

    public static bool Test5()
    {
        try
        {
            ulong[] array = new ulong[0xfffffff];
            ulong i = 0xa000000000000010;
            while (true)
            {
                i -= 0xa000000000000001;
                while (i >= 0)
                {
                    array[i] = i;
                    i -= 1;
                }

                array[i] = i;
            }
        }
        catch (IndexOutOfRangeException)
        {
            return true;
        }
        catch (Exception) { }

        Console.WriteLine("Test5 failed");
        return false;
    }
}