Browse Source

Fix incorrect type for numeric.compound.assign when the pointer type is incompatible with the store type.

Closes #1511, #1530, #1533.
pull/1596/head
Daniel Grunwald 7 years ago
parent
commit
a6def4cdf5
  1. 1
      ICSharpCode.Decompiler/IL/Instructions/CompoundAssignmentInstruction.cs
  2. 12
      ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs

1
ICSharpCode.Decompiler/IL/Instructions/CompoundAssignmentInstruction.cs

@ -97,6 +97,7 @@ namespace ICSharpCode.Decompiler.IL @@ -97,6 +97,7 @@ namespace ICSharpCode.Decompiler.IL
this.AddILRange(binary);
Debug.Assert(compoundAssignmentType == CompoundAssignmentType.EvaluatesToNewValue || (Operator == BinaryNumericOperator.Add || Operator == BinaryNumericOperator.Sub));
Debug.Assert(IsValidCompoundAssignmentTarget(Target));
Debug.Assert(this.ResultType == (IsLifted ? StackType.O : UnderlyingResultType));
}
/// <summary>

12
ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs

@ -478,9 +478,17 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -478,9 +478,17 @@ namespace ICSharpCode.Decompiler.IL.Transforms
// Try to determine the real type of the object we're modifying:
storeType = stobj.Target.InferType(compilation);
if (storeType is ByReferenceType refType) {
storeType = refType.ElementType;
if (TypeUtils.IsCompatibleTypeForMemoryAccess(refType.ElementType, stobj.Type)) {
storeType = refType.ElementType;
} else {
storeType = stobj.Type;
}
} else if (storeType is PointerType pointerType) {
storeType = pointerType.ElementType;
if (TypeUtils.IsCompatibleTypeForMemoryAccess(pointerType.ElementType, stobj.Type)) {
storeType = pointerType.ElementType;
} else {
storeType = stobj.Type;
}
} else {
storeType = stobj.Type;
}

Loading…
Cancel
Save