summaryrefslogtreecommitdiff
path: root/tests/src/JIT/Regression/CLR-x86-JIT/v2.1/b106272/b106272.cs
blob: 84b602e3c429983369e7d2b3adc017aaee1a5b3f (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
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using System;

namespace TernaryOperatorOptimization
{
    class Program
    {
        private static bool caughtException = false;

        static int Main(string[] args)
        {
            Console.WriteLine("Regression testcase for devdiv 106272 - Invalid JIT optimization");
            Console.WriteLine("with ternary/conditional operator (?:) in release builds");
            Console.WriteLine("This testcase needs to be build as retail version, /o+");

            try
            {
                TestIt();
            }
            catch (InvalidCastException)
            {
                caughtException = true;
            }

            Console.WriteLine();

            if (caughtException)
            {
                Console.WriteLine("!!!!!   TEST PASSED  !!!!!");
                return 100;
            }
            else
            {
                Console.WriteLine("!!!!!   TEST FAILED  !!!!!");
                return 101;
            }
        }

        private static void TestIt()
        {
            string o = SideEffectMethod() ? (string)null : (string)null;
            Console.WriteLine("o: " + o);

            string o2 = ((int)(object)"this should always throw!") == 5 ? (string)null : (string)null;
            Console.WriteLine("o2: Previous source line should have thrown an InvalidCastException!!!" + o2);
        }

        private static bool SideEffectMethod()
        {
            Console.WriteLine("This should be called!");
            return false;
        }
    }
}