Browse Source

Fix missing conversion on ref-reassignment.

pull/2113/head
Daniel Grunwald 5 years ago
parent
commit
3e6e628483
  1. 10
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Unsafe.cs
  2. 26
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Unsafe.il
  3. 1
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

10
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Unsafe.cs

@ -26,6 +26,16 @@ internal sealed class ExtraUnsafeTests @@ -26,6 +26,16 @@ internal sealed class ExtraUnsafeTests
return (uint*)Unsafe.AsPointer(ref managedPtr);
}
public static ref ulong RefAssignTypeMismatch(ref uint a, ref uint b)
{
ref ushort reference = ref Unsafe.As<uint, ushort>(ref a);
if (a != 0) {
reference = ref Unsafe.As<uint, ushort>(ref b);
}
Console.WriteLine(reference);
return ref Unsafe.As<ushort, ulong>(ref reference);
}
public unsafe static byte[] Issue1292(int val, byte[] arr)
{
//The blocks IL_0019 are reachable both inside and outside the pinned region starting at IL_0013. ILSpy has duplicated these blocks in order to place them both within and outside the `fixed` statement.

26
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Unsafe.il

@ -475,6 +475,32 @@ @@ -475,6 +475,32 @@
ret
}
.method public hidebysig static uint64& RefAssignTypeMismatch(uint32& a, uint32& b)
{
.maxstack 8
.locals (
[0] uint16&
)
ldarg.0
stloc.0
ldarg.0
ldind.i4
brfalse lbl
ldarg.1
stloc.0
lbl:
ldloc.0
ldind.i2
call void [mscorlib]System.Console::WriteLine(uint16)
ldloc.0
ret
}
.method public hidebysig static
uint8[] Issue1292 (
int32 val,

1
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -640,6 +640,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -640,6 +640,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (lhs.Expression is DirectionExpression dirExpr && lhs.ResolveResult is ByReferenceResolveResult lhsRefRR) {
// ref (re-)assignment, emit "ref (a = ref b)".
lhs = lhs.UnwrapChild(dirExpr.Expression);
translatedValue = translatedValue.ConvertTo(lhsRefRR.Type, this, allowImplicitConversion: true);
var assign = new AssignmentExpression(lhs.Expression, translatedValue.Expression)
.WithRR(new OperatorResolveResult(lhs.Type, ExpressionType.Assign, lhsRefRR, translatedValue.ResolveResult));
return new DirectionExpression(FieldDirection.Ref, assign)

Loading…
Cancel
Save