Browse Source

Merge pull request #3893 from sailro/fix-3892-unsafe-object-creation

Fix #3892: preserve unsafe for pointer constructors
pull/3901/head
Siegfried Pammer 2 months ago committed by GitHub
parent
commit
9ff3ac9633
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 13
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs
  2. 8
      ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUnsafeModifier.cs

13
ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs

@ -24,6 +24,14 @@ using System.Runtime.InteropServices; @@ -24,6 +24,14 @@ using System.Runtime.InteropServices;
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 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -683,4 +691,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
}
}
internal static class UnsafeObjectCreation
{
private unsafe static readonly PointerConstructor pointerConstructor = new PointerConstructor(null);
}
}

8
ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUnsafeModifier.cs

@ -192,6 +192,14 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -192,6 +192,14 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
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);

Loading…
Cancel
Save