Skip to content
Permalink
Browse files

Fix #1635: DynamicInvokeConstructorInstruction Did report the wrong S…

…tackType for value types and unknown types.
  • Loading branch information...
siegfriedpammer committed Aug 13, 2019
1 parent 85d1d21 commit 44c044aa337d89f4d4db610e7880401bfec7f678
@@ -415,6 +415,11 @@ private static bool ConstantTarget(dynamic a)
return true.Equals(a);
}

private static IntPtr NewIntPtr(dynamic a)
{
return new IntPtr(a);
}

private static dynamic GetDynamic(int i)
{
return null;
@@ -349,14 +349,17 @@ public override CSharpArgumentInfo GetArgumentInfoOfChild(int index)

partial class DynamicInvokeConstructorInstruction
{
readonly IType resultType;

public IReadOnlyList<CSharpArgumentInfo> ArgumentInfo { get; }

public DynamicInvokeConstructorInstruction(CSharpBinderFlags binderFlags, IType context, CSharpArgumentInfo[] argumentInfo, ILInstruction[] arguments)
public DynamicInvokeConstructorInstruction(CSharpBinderFlags binderFlags, IType type, IType context, CSharpArgumentInfo[] argumentInfo, ILInstruction[] arguments)
: base(OpCode.DynamicInvokeConstructorInstruction, binderFlags, context)
{
ArgumentInfo = argumentInfo;
Arguments = new InstructionCollection<ILInstruction>(this, 0);
Arguments.AddRange(arguments);
this.resultType = type;
}

public override void WriteTo(ITextOutput output, ILAstWritingOptions options)
@@ -365,11 +368,12 @@ public override void WriteTo(ITextOutput output, ILAstWritingOptions options)
output.Write(OpCode);
WriteBinderFlags(output, options);
output.Write(' ');
resultType?.WriteTo(output);
output.Write(".ctor");
WriteArgumentList(output, options, Arguments.Zip(ArgumentInfo));
}

public override StackType ResultType => StackType.O;
public override StackType ResultType => resultType?.GetStackType() ?? StackType.Unknown;

public override CSharpArgumentInfo GetArgumentInfoOfChild(int index)
{
@@ -183,12 +183,23 @@ ILInstruction MakeDynamicInstruction(CallSiteInfo callsite, CallVirt targetInvok
arguments: targetInvokeCall.Arguments.Skip(2).ToArray()
);
case BinderMethodKind.InvokeConstructor:
var arguments = targetInvokeCall.Arguments.Skip(2).ToArray();
// Extract type information from targetInvokeCall:
// Must either be an inlined type or
// a reference to a variable that is initialized with a type.
if (!TransformExpressionTrees.MatchGetTypeFromHandle(arguments[0], out var type)) {
if (!(arguments[0].MatchLdLoc(out var temp) && temp.IsSingleDefinition && temp.StoreInstructions.FirstOrDefault() is StLoc initStore))
return null;
if (!TransformExpressionTrees.MatchGetTypeFromHandle(initStore.Value, out type))
return null;
}
deadArguments.AddRange(targetInvokeCall.Arguments.Take(2));
return new DynamicInvokeConstructorInstruction(
binderFlags: callsite.Flags,
type: type ?? SpecialType.UnknownType,
context: callsite.Context,
argumentInfo: callsite.ArgumentInfos,
arguments: targetInvokeCall.Arguments.Skip(2).ToArray()
arguments: arguments
);
case BinderMethodKind.InvokeMember:
deadArguments.AddRange(targetInvokeCall.Arguments.Take(2));

0 comments on commit 44c044a

Please sign in to comment.
You can’t perform that action at this time.