Browse Source

#2050: Add assertion to check that no transform uses StObj.TargetSlot incorrectly.

pull/2069/head
Daniel Grunwald 6 years ago
parent
commit
b18ed89b67
  1. 1
      ICSharpCode.Decompiler/IL/Instructions.cs
  2. 3
      ICSharpCode.Decompiler/IL/Instructions.tt
  3. 15
      ICSharpCode.Decompiler/IL/Instructions/LdFlda.cs

1
ICSharpCode.Decompiler/IL/Instructions.cs

@ -4117,6 +4117,7 @@ namespace ICSharpCode.Decompiler.IL
base.CheckInvariant(phase); base.CheckInvariant(phase);
Debug.Assert(target.ResultType == StackType.Ref || target.ResultType == StackType.I); Debug.Assert(target.ResultType == StackType.Ref || target.ResultType == StackType.I);
Debug.Assert(value.ResultType == type.GetStackType()); Debug.Assert(value.ResultType == type.GetStackType());
CheckTargetSlot();
} }
} }
} }

3
ICSharpCode.Decompiler/IL/Instructions.tt

@ -253,7 +253,8 @@
new OpCode("stobj", "Indirect store (store to ref/pointer)." + Environment.NewLine new OpCode("stobj", "Indirect store (store to ref/pointer)." + Environment.NewLine
+ "Evaluates to the value that was stored (when using type byte/short: evaluates to the truncated value, sign/zero extended back to I4 based on type.GetSign())", + "Evaluates to the value that was stored (when using type byte/short: evaluates to the truncated value, sign/zero extended back to I4 based on type.GetSign())",
CustomClassName("StObj"), CustomArguments(("target", new[] { "Ref", "I" }), ("value", new[] { "type.GetStackType()" })), HasTypeOperand, MemoryAccess, CustomWriteToButKeepOriginal, CustomClassName("StObj"), CustomArguments(("target", new[] { "Ref", "I" }), ("value", new[] { "type.GetStackType()" })), HasTypeOperand, MemoryAccess, CustomWriteToButKeepOriginal,
SupportsVolatilePrefix, SupportsUnalignedPrefix, MayThrow, ResultType("type.GetStackType()")), SupportsVolatilePrefix, SupportsUnalignedPrefix, MayThrow, ResultType("type.GetStackType()"),
CustomInvariant("CheckTargetSlot();")),
new OpCode("box", "Boxes a value.", new OpCode("box", "Boxes a value.",
Unary, HasTypeOperand, MemoryAccess, MayThrow, ResultType("O")), Unary, HasTypeOperand, MemoryAccess, MayThrow, ResultType("O")),

15
ICSharpCode.Decompiler/IL/Instructions/LdFlda.cs

@ -68,5 +68,20 @@ namespace ICSharpCode.Decompiler.IL
return true; return true;
} }
} }
/// <summary>
/// called as part of CheckInvariant()
/// </summary>
void CheckTargetSlot()
{
switch (this.Target.OpCode) {
case OpCode.LdElema:
case OpCode.LdFlda:
if (this.Target.HasDirectFlag(InstructionFlags.MayThrow)) {
Debug.Assert(SemanticHelper.IsPure(this.Value.Flags));
}
break;
}
}
} }
} }

Loading…
Cancel
Save