Skip to content

[release/9.0-staging] Do not substitute return values of constrained calls #113462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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 @@ -748,12 +748,12 @@ private bool TryGetConstantArgument(MethodIL methodIL, byte[] body, OpcodeFlags[
{
BodySubstitution substitution = _substitutionProvider.GetSubstitution(method);
if (substitution != null && substitution.Value is int
&& (opcode != ILOpcode.callvirt || !method.IsVirtual))
&& ((opcode != ILOpcode.callvirt && !method.Signature.IsStatic) || !method.IsVirtual))
{
constant = (int)substitution.Value;
return true;
}
if ((opcode != ILOpcode.callvirt || !method.IsVirtual)
if (((opcode != ILOpcode.callvirt && !method.Signature.IsStatic) || !method.IsVirtual)
&& TryGetMethodConstantValue(method, out constant))
{
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class DeadCodeElimination
public static int Run()
{
SanityTest.Run();
Test110932Regression.Run();
TestInstanceMethodOptimization.Run();
TestReflectionInvokeSignatures.Run();
TestAbstractTypeNeverDerivedVirtualsOptimization.Run();
Expand Down Expand Up @@ -52,6 +53,34 @@ public static void Run()
}
}

class Test110932Regression
{
static bool s_trueConst = true;
static bool s_falseConst = false;

interface I
{
static virtual bool GetValue() => false;
}

class C : I
{
static bool I.GetValue() => true;
}

public static void Run()
{
if (!Call<C>())
throw new Exception();
}
static bool Call<T>() where T : I
{
if (T.GetValue())
return s_trueConst;
return s_falseConst;
}
}

class TestInstanceMethodOptimization
{
class UnreferencedType { }
Expand Down
Loading