summaryrefslogtreecommitdiff
path: root/tests/src/JIT/jit64/regress/ddb/87766/ddb87766.cs
blob: 057dfc20b324f1d9dbb0127c5aa7e554beee6836 (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
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.


using System;

public class VInline
{
    private int _fi1;
    private int _fi2;
    public VInline(int ival)
    {
        _fi1 = ival;
        _fi2 = 0;
    }
    [System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
    private void GetI1(ref int i)
    {
        i = _fi1;
    }
    public int Accumulate(int a)
    {
        int i = 0;
        GetI1(ref i); //here's the ldloca, passing the address of i as the arg
        i = i / _fi2;    //fi2 == 0 so this should always cause an exception
        return i;
    }
}
public class VIMain
{
    public static int Main()
    {
        int ret = 100;
        VInline vi = new VInline(1);
        int ival = 2;
        try
        {
            ival = vi.Accumulate(ival);  //this call should throw a divide by zero exception
        }
        catch (DivideByZeroException e)
        {
            Console.WriteLine("exeption stack trace: " + e.StackTrace.ToString());  //display the stack trace
            if (e.StackTrace.ToString().Contains("Accumulate"))
            {
                Console.WriteLine("Fail, method Accumulate NOT inlined.");
                ret = 666;
            }
            else
            {
                Console.WriteLine("Pass, method Accumulate inlined.");
            }
        }

        return ret;
    }
}