summaryrefslogtreecommitdiff
path: root/tests/src/JIT/Regression/JitBlue/DevDiv_794631/DevDiv_794631.cs
blob: 3f699966351dd531c9c10781ddc901ed6ac0b624 (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
// 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;

class Repro
{
    static int Main()
    {
        //This testcase ensures that we correctly generate one ReadUInt16() call
        //instead of two due to a bug in fgmorph which transformed a call result 
        //as an index of an array incorrectly resulting in an unexpected index

        U1[] u1 = new U1[1];
        U2[] u2 = new U2[2];
        u2[1] = new U2();
        U1 obj = u1[ReadUInt16()];

        if (obj == null)
        {
            Console.WriteLine("PASS!");
            return 100;
        }
        else
        {
            Console.WriteLine("FAIL!");
            Console.WriteLine("obj is not null.");
            return 101;
        }
    }

    static byte[] buf = new byte[] { 0, 0, 0, 6 };
    static int pos;

    static ushort ReadUInt16()
    {
        ushort s = (ushort)((buf[pos] << 8) + buf[pos + 1]);
        pos += 2;
        return s;
    }

    class U1 { }
    class U2 { }
}