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
|
using System;
using System.Diagnostics.Tracing;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.TestFramework {
/// <summary>
/// This test is here to give some coverage to the attribute to ensure it doesn't break. We need to leverage the ETW feature since it is the only
/// one that modifies bodies currently
/// </summary>
#if NETCOREAPP
[IgnoreTestCase ("--exclude-feature is not supported on .NET Core")]
#endif
[SetupLinkerArgument ("--exclude-feature", "etw")]
// Keep framework code that calls EventSource methods like OnEventCommand
[SetupLinkerCoreAction ("skip")]
// Used to avoid different compilers generating different IL which can mess up the instruction asserts
[SetupCompileArgument ("/optimize+")]
public class VerifyExpectModifiedAttributesWork {
public static void Main ()
{
var b = VerifyExpectModifiedAttributesWork_RemovedEventSource.Log.IsEnabled ();
if (b)
VerifyExpectModifiedAttributesWork_RemovedEventSource.Log.SomeMethod ();
}
public class ClassForLocal {
}
public static void CallsToForceALocal (int arg1, int arg2, int arg3)
{
}
}
[Kept]
[KeptBaseType (typeof (EventSource))]
[KeptMember (".ctor()")]
[KeptMember (".cctor()")]
[EventSource (Name = "MyCompany")]
class VerifyExpectModifiedAttributesWork_RemovedEventSource : EventSource {
public class Keywords {
public const EventKeywords Page = (EventKeywords)1;
public int Unused;
}
[Kept]
public static VerifyExpectModifiedAttributesWork_RemovedEventSource Log = new VerifyExpectModifiedAttributesWork_RemovedEventSource ();
[Kept]
[ExpectBodyModified]
[ExpectExceptionHandlersModified]
[ExpectLocalsModified]
protected override void OnEventCommand (EventCommandEventArgs command)
{
try {
// Do some extra stuff to be extra certain the compiler introduced a local instead of using `dup`
var tmp = new VerifyExpectModifiedAttributesWork.ClassForLocal ();
VerifyExpectModifiedAttributesWork.CallsToForceALocal (1, 3, 4);
VerifyExpectModifiedAttributesWork.CallsToForceALocal (1, 4, 4);
var hashcode = tmp.GetHashCode ();
VerifyExpectModifiedAttributesWork.CallsToForceALocal(1, hashcode, 3);
} catch {
try {
Removed ();
} catch {
var tmp = new VerifyExpectModifiedAttributesWork.ClassForLocal ();
VerifyExpectModifiedAttributesWork.CallsToForceALocal (1, 3, 4);
VerifyExpectModifiedAttributesWork.CallsToForceALocal (1, 4, 4);
var hashcode = tmp.GetHashCode ();
VerifyExpectModifiedAttributesWork.CallsToForceALocal(1, hashcode, 3);
throw;
}
throw;
}
}
[Kept]
[Event (8)]
[ExpectBodyModified]
public void SomeMethod ()
{
Removed ();
}
public void Removed ()
{
}
}
}
|