diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs index 0c7ccc67a8..e1f19ac1fb 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs @@ -24,6 +24,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { + [StructLayout(LayoutKind.Sequential, Size = 1)] + internal struct PointerConstructor + { + public unsafe PointerConstructor(void* pointer) + { + } + } + internal class SizeofTest { private struct StructWithStaticField @@ -683,4 +691,9 @@ public unsafe static void FixedPointerToPointer(int*[] arr) } } } + + internal static class UnsafeObjectCreation + { + private unsafe static readonly PointerConstructor pointerConstructor = new PointerConstructor(null); + } } diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUnsafeModifier.cs b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUnsafeModifier.cs index 7ce802b597..846c70c839 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUnsafeModifier.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUnsafeModifier.cs @@ -192,6 +192,14 @@ public override bool VisitInvocationExpression(InvocationExpression invocationEx return result; } + public override bool VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression) + { + bool result = base.VisitObjectCreateExpression(objectCreateExpression); + if (HasUnsafeResolveResult(objectCreateExpression)) + return true; + return result; + } + public override bool VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer) { base.VisitFixedVariableInitializer(fixedVariableInitializer);