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
6 changes: 1 addition & 5 deletions src/coreclr/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,10 +1104,6 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call,

targetMethodHnd = ldftnToken->m_token.hMethod;
}
else
{
assert(targetMethodHnd == nullptr);
}

#ifdef FEATURE_READYTORUN
if (IsAot())
Expand Down Expand Up @@ -1161,7 +1157,7 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call,
#ifndef TARGET_WASM // TODO-WASM: Wasm doesn't use the dynamically composed helpers yet. When we do, we probably will
// need to use a different set of arguments to construct the right helper call to avoid dynamically
// composing a helper
else if (oper == GT_FTN_ADDR)
else if ((oper == GT_FTN_ADDR) && (ldftnToken != nullptr))
{
JITDUMP("optimized\n");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,32 @@ public static void Verify_CallCtorWithEmptyNotNullName()
extern static UserDataClass CallPrivateConstructorWithEmptyName();
}

interface IDelegateTarget
{
static virtual object GetValue() => "DelegateTargetValue";
}

class DelegateTargetImpl : IDelegateTarget { }

delegate object DelegateFromUnsafeAccessor();

[UnsafeAccessor(UnsafeAccessorKind.Constructor)]
extern static DelegateFromUnsafeAccessor ConstructDelegate(object o, IntPtr p);

static class DelegateTargetResolver<T> where T : IDelegateTarget
{
public static unsafe delegate*<object> Resolve() => &T.GetValue;
}

[Fact]
public static unsafe void Verify_ConstructDelegateFromFunctionPointer()
{
Console.WriteLine($"Running {nameof(Verify_ConstructDelegateFromFunctionPointer)}");

var del = ConstructDelegate(null, (nint)DelegateTargetResolver<DelegateTargetImpl>.Resolve());
Assert.Equal("DelegateTargetValue", del());
}

[Fact]
public static void Verify_CallCtorAsMethod()
{
Expand Down
Loading