summaryrefslogtreecommitdiff
path: root/tests/src/JIT/jit64/opt/cse/pointerexpr1.cs
blob: 6e7a725aa3ec11b9b575d42b482f745bd30f81bc (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
149
150
151
152
153
154
155
// 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.
//

//((a+ *b)+ *c)

//permutations for  ((a+ *b)+ *c)
//((a+ *b)+ *c)
//( *c+(a+ *b))
//(a+ *b)
//( *b+a)
//a
// *b
//( *b+a)
//(a+ *b)
// *c
//( *c+(a+ *b))
//((a+ *b)+ *c)
namespace CseTest
{
    using System;


    public class TestClass
    {
        static int Main()
        {
            int a = returna(false);
            int c = returnc(false);
            int b = returnb(false);
            unsafe
            {
                return m_Main(&a, &b, &c);
            }
        }
        static unsafe int m_Main(int* a, int* b, int* c)
        {
            int ret = 100;
            int v;
            v = ((*a + *b) + *c);
            if (v != 102)
            {
                Console.WriteLine("test1: for (( *a+ *b)+ *c)  failed actual value {0} ", v);
                ret = ret + 1;
            }
#if LOOP
			for (int i = 0; i < 5; i++) {
				for (int j = 0; j < 6; j++) {
#endif
            v = (*c + (*a + *b));
            if (v != 102)
            {
                Console.WriteLine("test2: for ( *c+( *a+ *b))  failed actual value {0} ", v);
                ret = ret + 1;
            }

            v = (*a + *b);
            if (v != 67)
            {
                Console.WriteLine("test3: for ( *a+ *b)  failed actual value {0} ", v);
                ret = ret + 1;
            }
#if LOOP
				}
				*a = returna(false);
			}
#endif

            v = (*b + *a);
            if (v != 67)
            {
                Console.WriteLine("test4: for ( *b+ *a)  failed actual value {0} ", v);
                ret = ret + 1;
            }
            v = (*b + *a);
            if (v != 67)
            {
                Console.WriteLine("test5: for ( *b+ *a)  failed actual value {0} ", v);
                ret = ret + 1;
            }
            v = (*a + *b);
            if (v != 67)
            {
                Console.WriteLine("test6: for ( *a+ *b)  failed actual value {0} ", v);
                ret = ret + 1;
            }
            v = (*c + (*a + *b));
            if (v != 102)
            {
                Console.WriteLine("test7: for ( *c+( *a+ *b))  failed actual value {0} ", v);
                ret = ret + 1;
            }
            v = ((*a + *b) + *c);
            if (v != 102)
            {
                Console.WriteLine("test8: for (( *a+ *b)+ *c)  failed actual value {0} ", v);
                ret = ret + 1;
            }
            return ret;
        }

        private static int returnb(bool verbose)
        {
            int ans;
            try
            {
                ans = 34;
            }
            finally
            {
                if (verbose)
                {
                    Console.WriteLine("returning  *b=34");
                }
            }
            return ans;
        }

        private static int returnc(bool verbose)
        {
            int ans;
            try
            {
                ans = 35;
            }
            finally
            {
                if (verbose)
                {
                    Console.WriteLine("returning  *c=35");
                }
            }
            return ans;
        }

        private static int returna(bool verbose)
        {
            int ans;
            try
            {
                ans = 33;
            }
            finally
            {
                if (verbose)
                {
                    Console.WriteLine("returning  *a=33");
                }
            }
            return ans;
        }
    }
}