Skip to content

Commit b18ed89

Browse files
committed
#2050: Add assertion to check that no transform uses StObj.TargetSlot incorrectly.
1 parent ef3a967 commit b18ed89

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

ICSharpCode.Decompiler/IL/Instructions.cs

+1
Original file line numberDiff line numberDiff line change
@@ -4117,6 +4117,7 @@ internal override void CheckInvariant(ILPhase phase)
41174117
base.CheckInvariant(phase);
41184118
Debug.Assert(target.ResultType == StackType.Ref || target.ResultType == StackType.I);
41194119
Debug.Assert(value.ResultType == type.GetStackType());
4120+
CheckTargetSlot();
41204121
}
41214122
}
41224123
}

ICSharpCode.Decompiler/IL/Instructions.tt

+2-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@
253253
new OpCode("stobj", "Indirect store (store to ref/pointer)." + Environment.NewLine
254254
+ "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())",
255255
CustomClassName("StObj"), CustomArguments(("target", new[] { "Ref", "I" }), ("value", new[] { "type.GetStackType()" })), HasTypeOperand, MemoryAccess, CustomWriteToButKeepOriginal,
256-
SupportsVolatilePrefix, SupportsUnalignedPrefix, MayThrow, ResultType("type.GetStackType()")),
256+
SupportsVolatilePrefix, SupportsUnalignedPrefix, MayThrow, ResultType("type.GetStackType()"),
257+
CustomInvariant("CheckTargetSlot();")),
257258

258259
new OpCode("box", "Boxes a value.",
259260
Unary, HasTypeOperand, MemoryAccess, MayThrow, ResultType("O")),

ICSharpCode.Decompiler/IL/Instructions/LdFlda.cs

+15
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,20 @@ public bool CanInlineIntoTargetSlot(ILInstruction inst)
6868
return true;
6969
}
7070
}
71+
72+
/// <summary>
73+
/// called as part of CheckInvariant()
74+
/// </summary>
75+
void CheckTargetSlot()
76+
{
77+
switch (this.Target.OpCode) {
78+
case OpCode.LdElema:
79+
case OpCode.LdFlda:
80+
if (this.Target.HasDirectFlag(InstructionFlags.MayThrow)) {
81+
Debug.Assert(SemanticHelper.IsPure(this.Value.Flags));
82+
}
83+
break;
84+
}
85+
}
7186
}
7287
}

0 commit comments

Comments
 (0)