ILSpy
ILSpy copied to clipboard
Support System.Runtime.CompilerServices.Unsafe intrinsics
C++/CLI code may use managed references in ways more flexible than C#. In such cases, the decompiler could use System.Runtime.CompilerServices.Unsafe method calls to represent the missing operations.
The Unsafe class itself can serve as test case.
How many of these are still unsupported (including your PR #2045)?
All the Unsafe
members in the test case that aren't decompiled into Unsafe
calls are currently emitting code that fails to compile. So this issue is still less than 50% done.
Status:
- ReadUnaligned, WriteUnaligned: implemented as of 782e4ae88c66d7dccb210cc530900f62a1c3aeae
- AsPointer: implemented:
ExpressionBuilder.VisitConv
will emit this forConversionKind.StopGCTracking
. - Read, Write, Copy, SizeOf: these are only invalid because the generated code using pointer arithmetic is not valid with unconstrained generic types. See also #2144
- Add/Subtract/ByteOffset: Managed reference overloads are implemented. Pointer overloads are invalid because the generated code using pointer arithmetic is not valid with unconstrained generic types.
-
T As<T>(object)
: This is currently decompiled into a cast. Fixing this pretty much would involve replacing the fallback case in theConvertTo
method. But I think currentlyConvertTo
is used in so many places that this would end up with unexpected side effects. - AreSame/IsAddressGreaterThan/IsAddressLessThan: TODO, these currently produce invalid syntax
- Unbox: TODO, currently emits invalid syntax
ref (T)obj
- NullRef: emits
ref *(T*)null
which is invalid when T is unconstrained generic - IsNullRef: emits
Unsafe.AsPointer(ref source) == null
which I guess is OK - SkipInit: TODO, currently ILSpy can emit code with a compiler errors due to uninitialized variable