summaryrefslogtreecommitdiff
path: root/tests/src/JIT/CodeGenBringUpTests/StructInstMethod.cs
blob: 6385f37f395b08bc02c305f0a61963a8c78210f1 (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
// 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;
using System.Runtime.CompilerServices;

public struct Point
{
    public int x;
    public int y;
    public int z;

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public Point(int a, int b, int c) { x = a; y = b; z = c; }

    public int X
    {
        [MethodImplAttribute(MethodImplOptions.NoInlining)]
        get { return this.x; }

        [MethodImplAttribute(MethodImplOptions.NoInlining)]
        set { this.x = value; }
    }

    public int Y
    {
        [MethodImplAttribute(MethodImplOptions.NoInlining)]
        get { return this.y; }

        [MethodImplAttribute(MethodImplOptions.NoInlining)]
        set { this.y = value; }
    }

    public int Z
    {
        [MethodImplAttribute(MethodImplOptions.NoInlining)]
        get { return this.z; }

        [MethodImplAttribute(MethodImplOptions.NoInlining)]
        set { this.z = value; }
    }

    // Returns true if this represents 'origin' otherwise false.
    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public bool StructInstMethod() { return (x == 0 && y == 0 && z == 0); }

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public int StructInstMethod(ref Point p)
    {
        // JBToDo:The following is running into the assert put in place
        // for the case reg1 = reg2 op reg1 where op is not commutative.
        //int a = x-p.x;
        //int b = y-p.y;
        //int c = z-p.z;
        // return a+b+c;

        // Accessing field using get property
        int a = X;
        return a + p.x;
    }
}

public class BringUpTest
{
    const int Pass = 100;
    const int Fail = -1;


    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    public static int StructInstMethod(ref Point p2)
    {
        Point p1 = new Point(10, 20, 30);

        p1.StructInstMethod();

        if (p1.StructInstMethod()) return Fail;
        if (!p2.StructInstMethod()) return Fail;

        int a = p1.StructInstMethod(ref p2);
        int b = p1.X;
        if (a != b) return Fail;

        return Pass;
    }


    public static int Main()
    {
        Point p = new Point(10, 20, 30);
        if (p.StructInstMethod()) return Fail;

        if (p.StructInstMethod(ref p) != 20) return Fail;


        Point p2 = new Point(0, 0, 0);
        return StructInstMethod(ref p2);
    }
}