blob: 77fa7ba32960ad1832530d2f7f91e0edc2eb9f31 (
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
|
// 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.
// test that .cctor of NotInlined and Inlined (class/struct) is called when Foo.Meth_In and Foo_Meth_NotIn
// is invoked.
using System;
using System.IO;
using System.Runtime.CompilerServices;
public class Foo
{
public static void Meth_In()
{
// NotInlined.NotInlinedMeth is not inlined
NotInlined.NotInlinedMeth<int>();
}
public static void Meth_NotIn()
{
// Inlined.InlinedMeth is inlined
Inlined.InlinedMeth<Foo>();
}
public static void ValMeth_In()
{
// NotInlinedVal.NotInlinedValMeth is not inlined
NotInlinedVal.NotInlinedValMeth<char>();
}
public static void ValMeth_NotIn()
{
// InlinedVal.InlinedValMeth is inlined
InlinedVal.InlinedValMeth<NotInlined>();
}
}
public class NotInlined
{
static NotInlined()
{
Console.WriteLine("Inside NotInlined::.cctor");
File.WriteAllText("notinlined.txt", "inside .cctor");
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static void NotInlinedMeth<T>()
{
}
}
public class Inlined
{
static Inlined()
{
Console.WriteLine("Inside Inlined::.cctor");
File.WriteAllText("inlined.txt", "inside .cctor");
}
public static void InlinedMeth<T>()
{
}
}
public struct NotInlinedVal
{
static NotInlinedVal()
{
Console.WriteLine("Inside NotInlinedVal::.cctor");
File.WriteAllText("notinlinedval.txt", "inside .cctor");
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static void NotInlinedValMeth<T>()
{
}
}
public struct InlinedVal
{
static InlinedVal()
{
Console.WriteLine("Inside InlinedVal::.cctor");
File.WriteAllText("inlinedval.txt", "inside .cctor");
}
public static void InlinedValMeth<T>()
{
}
}
public class Test
{
public static int Main()
{
Foo.Meth_In();
Foo.Meth_NotIn();
Foo.ValMeth_In();
Foo.ValMeth_NotIn();
if (!File.Exists("inlined.txt") || !File.Exists("notinlined.txt") || !File.Exists("inlinedval.txt") || !File.Exists("notinlinedval.txt") )
{
Console.WriteLine("FAIL: Cctor wasn't called");
return 101;
}
else
{
Console.WriteLine("PASS: Cctor was called");
File.Delete("inlined.txt");
File.Delete("notinlined.txt");
File.Delete("inlinedval.txt");
File.Delete("notinlinedval.txt");
return 100;
}
}
}
|