Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@ internal DiagnosticMethodInfo GetDiagnosticMethodInfo()
}
else
{
functionPointer = ldftnResult;
nint unboxedPointer = RuntimeAugments.GetCodeTarget(ldftnResult);
if (unboxedPointer == ldftnResult)
unboxedPointer = RuntimeAugments.GetTargetOfUnboxingAndInstantiatingStub(ldftnResult);

functionPointer = unboxedPointer != 0 ? unboxedPointer : ldftnResult;
}
return RuntimeAugments.StackTraceCallbacksIfAvailable?.TryGetDiagnosticMethodInfoFromStartAddress(functionPointer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;

class Program
Expand All @@ -11,6 +13,7 @@ static int Main()
{
BodyFoldingTest.Run();
DiagnosticMethodInfoTests.Run();
Test108688Regression.Run();

string stackTrace = Environment.StackTrace;

Expand Down Expand Up @@ -83,4 +86,171 @@ public class Nested
}
}
}

class Test108688Regression
{
public static void Run()
{
{
DelStruct s;
Action del = s.InstanceMethod;
var dmi = DiagnosticMethodInfo.Create(del);
#if STRIPPED
if (dmi != null)
throw new Exception();
#else
if (dmi.Name != nameof(DelStruct.InstanceMethod))
throw new Exception();
// Need to make sure it was stack trace metadata and not reflection metadata that provided this
if (GetMethodSecretly(del.Target.GetType(), dmi.Name) != null)
throw new Exception();
#endif
}

{
DelStruct s;
Action del = s.InstanceGenericMethod<int>;
var dmi = DiagnosticMethodInfo.Create(del);
#if STRIPPED
if (dmi != null)
throw new Exception();
#else
if (dmi.Name != nameof(DelStruct.InstanceGenericMethod))
throw new Exception();
// Need to make sure it was stack trace metadata and not reflection metadata that provided this
if (GetMethodSecretly(del.Target.GetType(), dmi.Name) != null)
throw new Exception();
#endif
}

{
DelStruct s;
Action del = s.InstanceGenericMethod<object>;
var dmi = DiagnosticMethodInfo.Create(del);
#if STRIPPED
if (dmi != null)
throw new Exception();
#else
if (dmi.Name != nameof(DelStruct.InstanceGenericMethod))
throw new Exception();
// Need to make sure it was stack trace metadata and not reflection metadata that provided this
if (GetMethodSecretly(del.Target.GetType(), dmi.Name) != null)
throw new Exception();
#endif
}

{
DelStruct<int> s;
Action del = s.InstanceMethod;
var dmi = DiagnosticMethodInfo.Create(del);
#if STRIPPED
if (dmi != null)
throw new Exception();
#else
if (dmi.Name != nameof(DelStruct.InstanceMethod))
throw new Exception();
// Need to make sure it was stack trace metadata and not reflection metadata that provided this
if (GetMethodSecretly(del.Target.GetType(), dmi.Name) != null)
throw new Exception();
#endif
}

{
DelStruct<int> s;
Action del = s.InstanceGenericMethod<int>;
var dmi = DiagnosticMethodInfo.Create(del);
#if STRIPPED
if (dmi != null)
throw new Exception();
#else
if (dmi.Name != nameof(DelStruct.InstanceGenericMethod))
throw new Exception();
// Need to make sure it was stack trace metadata and not reflection metadata that provided this
if (GetMethodSecretly(del.Target.GetType(), dmi.Name) != null)
throw new Exception();
#endif
}

{
DelStruct<int> s;
Action del = s.InstanceGenericMethod<object>;
var dmi = DiagnosticMethodInfo.Create(del);
#if STRIPPED
if (dmi != null)
throw new Exception();
#else
if (dmi.Name != nameof(DelStruct.InstanceGenericMethod))
throw new Exception();
// Need to make sure it was stack trace metadata and not reflection metadata that provided this
if (GetMethodSecretly(del.Target.GetType(), dmi.Name) != null)
throw new Exception();
#endif
}

{
DelStruct<object> s;
Action del = s.InstanceMethod;
var dmi = DiagnosticMethodInfo.Create(del);
#if STRIPPED
if (dmi != null)
throw new Exception();
#else
if (dmi.Name != nameof(DelStruct.InstanceMethod))
throw new Exception();
// Need to make sure it was stack trace metadata and not reflection metadata that provided this
if (GetMethodSecretly(del.Target.GetType(), dmi.Name) != null)
throw new Exception();
#endif
}

{
DelStruct<object> s;
Action del = s.InstanceGenericMethod<int>;
var dmi = DiagnosticMethodInfo.Create(del);
#if STRIPPED
if (dmi != null)
throw new Exception();
#else
if (dmi.Name != nameof(DelStruct.InstanceGenericMethod))
throw new Exception();
// Need to make sure it was stack trace metadata and not reflection metadata that provided this
if (GetMethodSecretly(del.Target.GetType(), dmi.Name) != null)
throw new Exception();
#endif
}

{
DelStruct<object> s;
Action del = s.InstanceGenericMethod<object>;
var dmi = DiagnosticMethodInfo.Create(del);
#if STRIPPED
if (dmi != null)
throw new Exception();
#else
if (dmi.Name != nameof(DelStruct.InstanceGenericMethod))
throw new Exception();
// Need to make sure it was stack trace metadata and not reflection metadata that provided this
if (GetMethodSecretly(del.Target.GetType(), dmi.Name) != null)
throw new Exception();
#endif
}
}

[UnconditionalSuppressMessage("", "IL2070")]
private static MethodInfo GetMethodSecretly(Type t, string name)
=> t.GetMethod(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);

struct DelStruct
{
public void InstanceMethod() { }
public void InstanceGenericMethod<T>() { }
}

struct DelStruct<T>
{
public void InstanceMethod() { }
public void InstanceGenericMethod<U>() { }
}
}

}