From a1adf696fb2b299cdc64eb4f073c94fd868690e7 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Wed, 17 Aug 2022 17:12:55 -0700 Subject: [PATCH 1/2] Adding support for UnscopedRef --- .../Abstractions/FieldDesc.cs | 1 + .../Abstractions/FunctionOrDelegateDesc.cs | 1 + .../Abstractions/IOutputBuilder.VisitDecl.cs | 2 +- .../CSharp/CSharpOutputBuilder.Visit.cs | 4 + .../CSharp/CSharpOutputBuilder.VisitDecl.cs | 18 +++- .../PInvokeGenerator.VisitDecl.cs | 87 +++++++++++-------- .../PInvokeGenerator.cs | 4 +- .../XML/XmlOutputBuilder.VisitDecl.cs | 2 +- 8 files changed, 77 insertions(+), 42 deletions(-) diff --git a/sources/ClangSharp.PInvokeGenerator/Abstractions/FieldDesc.cs b/sources/ClangSharp.PInvokeGenerator/Abstractions/FieldDesc.cs index ca13f2bc..040bf9bb 100644 --- a/sources/ClangSharp.PInvokeGenerator/Abstractions/FieldDesc.cs +++ b/sources/ClangSharp.PInvokeGenerator/Abstractions/FieldDesc.cs @@ -13,6 +13,7 @@ internal struct FieldDesc public string ParentName { get; set; } public int? Offset { get; set; } public bool NeedsNewKeyword { get; set; } + public bool NeedsUnscopedRef { get; set; } public bool HasBody { get; set; } public string InheritedFrom { get; set; } public CXSourceLocation? Location { get; set; } diff --git a/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs b/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs index 180691f5..cce4e862 100644 --- a/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs +++ b/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs @@ -21,6 +21,7 @@ internal struct FunctionOrDelegateDesc public CXSourceLocation? Location { get; set; } public bool HasBody { get; set; } public bool IsInherited { get; set; } + public bool NeedsUnscopedRef { get; set; } public bool IsVirtual { diff --git a/sources/ClangSharp.PInvokeGenerator/Abstractions/IOutputBuilder.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/Abstractions/IOutputBuilder.VisitDecl.cs index 31337196..2c89eb20 100644 --- a/sources/ClangSharp.PInvokeGenerator/Abstractions/IOutputBuilder.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/Abstractions/IOutputBuilder.VisitDecl.cs @@ -66,7 +66,7 @@ internal partial interface IOutputBuilder void BeginSetter(bool aggressivelyInlined); void EndSetter(); - void BeginIndexer(AccessSpecifier accessSpecifier, bool isUnsafe); + void BeginIndexer(AccessSpecifier accessSpecifier, bool isUnsafe, bool needsUnscopedRef); void WriteIndexer(string typeName); void BeginIndexerParameters(); void EndIndexerParameters(); diff --git a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs index 4ac268e2..ca03e2b1 100644 --- a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs +++ b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs @@ -18,6 +18,10 @@ public void WriteCustomAttribute(string attribute, Action callback = null) { AddUsingDirective("System.ComponentModel"); } + else if (attribute.Equals("UnscopedRef")) + { + AddUsingDirective("System.Diagnostics.CodeAnalysis"); + } else if (attribute.StartsWith("Guid(")|| attribute.Equals("Optional") || attribute.StartsWith("Optional, DefaultParameterValue(")) { AddUsingDirective("System.Runtime.InteropServices"); diff --git a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs index fbe0dd7d..6a1a48ec 100644 --- a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs @@ -311,6 +311,11 @@ public void BeginField(in FieldDesc desc) desc.WriteCustomAttrs?.Invoke(desc.CustomAttrGeneratorData); + if (desc.NeedsUnscopedRef) + { + WriteCustomAttribute("UnscopedRef"); + } + WriteIndented(GetAccessSpecifierString(desc.AccessSpecifier, isNested: true)); Write(' '); @@ -463,6 +468,11 @@ public void BeginFunctionOrDelegate(in FunctionOrDelegateDesc desc, ref bool isM desc.WriteCustomAttrs?.Invoke(desc.CustomAttrGeneratorData); + if (desc.NeedsUnscopedRef) + { + WriteCustomAttribute("UnscopedRef"); + } + if (_isInMarkerInterface) { WriteIndentation(); @@ -906,9 +916,15 @@ public void EndSetter() NeedsNewline = false; } - public void BeginIndexer(AccessSpecifier accessSpecifier, bool isUnsafe) + public void BeginIndexer(AccessSpecifier accessSpecifier, bool isUnsafe, bool needsUnscopedRef) { NeedsNewline = true; + + if (needsUnscopedRef) + { + WriteCustomAttribute("UnscopedRef"); + } + WriteIndented(GetAccessSpecifierString(accessSpecifier, isNested: true)); Write(' '); if (isUnsafe) diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index 3c41c2c2..9403f1b6 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -883,6 +883,7 @@ private void VisitIndirectFieldDecl(IndirectFieldDecl indirectFieldDecl) ParentName = GetRemappedCursorName(fieldDecl.Parent), Offset = null, NeedsNewKeyword = false, + NeedsUnscopedRef = _config.GeneratePreviewCode, Location = fieldDecl.Location, HasBody = true, WriteCustomAttrs = static context => { @@ -921,8 +922,7 @@ private void VisitIndirectFieldDecl(IndirectFieldDecl indirectFieldDecl) } } - var isSupportedFixedSizedBufferType = - isFixedSizedBuffer && IsSupportedFixedSizedBufferType(typeName); + var isSupportedFixedSizedBufferType = isFixedSizedBuffer && IsSupportedFixedSizedBufferType(typeName); if (isFixedSizedBuffer) { @@ -1004,53 +1004,63 @@ private void VisitIndirectFieldDecl(IndirectFieldDecl indirectFieldDecl) { code.WriteIndented("return "); - if (!isFixedSizedBuffer) - { - code.AddUsingDirective("System.Runtime.InteropServices"); - code.Write("ref MemoryMarshal.GetReference("); - } - - if (!isFixedSizedBuffer || isSupportedFixedSizedBufferType) - { - code.Write("MemoryMarshal.CreateSpan(ref "); - } - - if (isIndirectPointerField) - { - code.Write("this"); - } - else + if (desc.NeedsUnscopedRef && !isFixedSizedBuffer) { + code.Write("ref "); code.Write(contextName); code.Write('.'); code.Write(escapedName); } - - if (isFixedSizedBuffer) + else { - if (isSupportedFixedSizedBufferType) + if (!isFixedSizedBuffer) + { + code.AddUsingDirective("System.Runtime.InteropServices"); + code.Write("ref MemoryMarshal.GetReference("); + } + + if (!isFixedSizedBuffer || isSupportedFixedSizedBufferType) { - code.Write("[0], "); - code.Write(Math.Max((type.CanonicalType as ConstantArrayType)?.Size ?? 0, 1)); + code.Write("MemoryMarshal.CreateSpan(ref "); + } + + if (isIndirectPointerField) + { + code.Write("this"); } else { - code.Write(".AsSpan("); + code.Write(contextName); + code.Write('.'); + code.Write(escapedName); } - } - else - { - code.Write(", 1)"); - } - code.Write(')'); + if (isFixedSizedBuffer) + { + if (isSupportedFixedSizedBufferType) + { + code.Write("[0], "); + code.Write(Math.Max((type.CanonicalType as ConstantArrayType)?.Size ?? 0, 1)); + } + else + { + code.Write(".AsSpan("); + } + } + else + { + code.Write(", 1)"); + } - if (isIndirectPointerField) - { - code.Write('.'); - code.Write(contextName); - code.Write('.'); - code.Write(escapedName); + code.Write(')'); + + if (isIndirectPointerField) + { + code.Write('.'); + code.Write(contextName); + code.Write('.'); + code.Write(escapedName); + } } code.WriteSemicolon(); @@ -2829,7 +2839,7 @@ void VisitConstantOrIncompleteArrayFieldDecl(RecordDecl recordDecl, FieldDecl co if (generateCompatibleCode || isUnsafeElementType) { - _outputBuilder.BeginIndexer(AccessSpecifier.Public, generateCompatibleCode && !isUnsafeElementType); + _outputBuilder.BeginIndexer(AccessSpecifier.Public, isUnsafe: generateCompatibleCode && !isUnsafeElementType, needsUnscopedRef: false); _outputBuilder.WriteIndexer($"ref {arrayTypeName}"); _outputBuilder.BeginIndexerParameters(); var param = new ParameterDesc { @@ -2862,7 +2872,7 @@ void VisitConstantOrIncompleteArrayFieldDecl(RecordDecl recordDecl, FieldDecl co } else { - _outputBuilder.BeginIndexer(AccessSpecifier.Public, false); + _outputBuilder.BeginIndexer(AccessSpecifier.Public, isUnsafe: false, needsUnscopedRef: _config.GeneratePreviewCode); _outputBuilder.WriteIndexer($"ref {arrayTypeName}"); _outputBuilder.BeginIndexerParameters(); var param = new ParameterDesc { @@ -2904,6 +2914,7 @@ void VisitConstantOrIncompleteArrayFieldDecl(RecordDecl recordDecl, FieldDecl co ReturnType = $"Span<{arrayTypeName}>", Location = constantOrIncompleteArray.Location, HasBody = true, + NeedsUnscopedRef = _config.GeneratePreviewCode, }; var isUnsafe = false; diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs index fad875c4..28b9dbdf 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs @@ -1806,6 +1806,7 @@ private string EscapeAndStripName(string name) } internal static string EscapeCharacter(char value) => value switch { + '\0' => "\\0", '\\' => "\\\\", '\r' => "\\r", '\n' => "\\n", @@ -1814,7 +1815,8 @@ private string EscapeAndStripName(string name) _ => value.ToString(), }; - internal static string EscapeString(string value) => value.Replace("\\", "\\\\") + internal static string EscapeString(string value) => value.Replace("\0", "\\0") + .Replace("\\", "\\\\") .Replace("\r", "\\r") .Replace("\n", "\\n") .Replace("\t", "\\t") diff --git a/sources/ClangSharp.PInvokeGenerator/XML/XmlOutputBuilder.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/XML/XmlOutputBuilder.VisitDecl.cs index 3e118807..5500485f 100644 --- a/sources/ClangSharp.PInvokeGenerator/XML/XmlOutputBuilder.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/XML/XmlOutputBuilder.VisitDecl.cs @@ -389,7 +389,7 @@ public void BeginSetter(bool aggressivelyInlined) public void EndSetter() => _ = _sb.Append(""); - public void BeginIndexer(AccessSpecifier accessSpecifier, bool isUnsafe) + public void BeginIndexer(AccessSpecifier accessSpecifier, bool isUnsafe, bool needsUnscopedRef) { _ = _sb.Append(" Date: Thu, 18 Aug 2022 08:40:55 -0700 Subject: [PATCH 2/2] Updating the preview-codegen tests to account for UnscopedRef --- .../PInvokeGenerator.VisitDecl.cs | 2 +- .../FunctionDeclarationBodyImportTest.cs | 6 ++- .../StructDeclarationTest.cs | 48 ++++++++++++++----- .../CSharpPreviewUnix/UnionDeclarationTest.cs | 35 +++++++++++--- .../FunctionDeclarationBodyImportTest.cs | 6 ++- .../StructDeclarationTest.cs | 48 ++++++++++++++----- .../UnionDeclarationTest.cs | 35 +++++++++++--- .../FunctionDeclarationBodyImportTest.cs | 2 +- .../XmlPreviewUnix/StructDeclarationTest.cs | 12 ++--- .../XmlPreviewUnix/UnionDeclarationTest.cs | 10 ++-- .../FunctionDeclarationBodyImportTest.cs | 2 +- .../StructDeclarationTest.cs | 12 ++--- .../XmlPreviewWindows/UnionDeclarationTest.cs | 10 ++-- 13 files changed, 163 insertions(+), 65 deletions(-) diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index 9403f1b6..3ebb32a7 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -883,7 +883,7 @@ private void VisitIndirectFieldDecl(IndirectFieldDecl indirectFieldDecl) ParentName = GetRemappedCursorName(fieldDecl.Parent), Offset = null, NeedsNewKeyword = false, - NeedsUnscopedRef = _config.GeneratePreviewCode, + NeedsUnscopedRef = _config.GeneratePreviewCode && !fieldDecl.IsBitField, Location = fieldDecl.Location, HasBody = true, WriteCustomAttrs = static context => { diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/FunctionDeclarationBodyImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/FunctionDeclarationBodyImportTest.cs index 75522406..9ccf9034 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/FunctionDeclarationBodyImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/FunctionDeclarationBodyImportTest.cs @@ -1428,7 +1428,8 @@ void MyFunction() } "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -1439,11 +1440,12 @@ public partial struct MyUnion [NativeTypeName(""MyUnion::(anonymous struct at ClangUnsavedFile.h:3:5)"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/StructDeclarationTest.cs index 760b67f8..ccc47537 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/StructDeclarationTest.cs @@ -343,6 +343,7 @@ struct MyOtherStruct "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -363,6 +364,7 @@ public partial struct _c_e__FixedBuffer public MyStruct e1; public MyStruct e2; + [UnscopedRef] public ref MyStruct this[int index] {{ get @@ -371,6 +373,7 @@ public ref MyStruct this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} @@ -394,6 +397,7 @@ struct MyOtherStruct "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -446,6 +450,7 @@ public partial struct _c_e__FixedBuffer public MyStruct e0_0_2_3; public MyStruct e1_0_2_3; + [UnscopedRef] public ref MyStruct this[int index] {{ get @@ -454,6 +459,7 @@ public ref MyStruct this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); }} }} @@ -479,6 +485,7 @@ struct MyOtherStruct "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -499,6 +506,7 @@ public partial struct _c_e__FixedBuffer public MyStruct e1; public MyStruct e2; + [UnscopedRef] public ref MyStruct this[int index] {{ get @@ -507,6 +515,7 @@ public ref MyStruct this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} @@ -530,6 +539,7 @@ struct MyOtherStruct "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -551,6 +561,7 @@ public partial struct _c_e__FixedBuffer public MyStruct e1; public MyStruct e2; + [UnscopedRef] public ref MyStruct this[int index] {{ get @@ -559,6 +570,7 @@ public ref MyStruct this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} @@ -875,6 +887,7 @@ struct MyStruct "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -895,54 +908,61 @@ public unsafe partial struct MyStruct [NativeTypeName(""MyStruct::(anonymous struct at ClangUnsavedFile.h:{line}:{column})"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref {expectedManagedType} z {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; }} }} + [UnscopedRef] public ref _Anonymous_e__Struct._w_e__Struct w {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.w, 1)); + return ref Anonymous.w; }} }} + [UnscopedRef] public ref {expectedManagedType} value1 {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.value1, 1)); + return ref Anonymous.Anonymous1.value1; }} }} + [UnscopedRef] public ref {expectedManagedType} value {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.Anonymous.value, 1)); + return ref Anonymous.Anonymous1.Anonymous.value; }} }} + [UnscopedRef] public ref {expectedManagedType} value2 {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous2.value2, 1)); + return ref Anonymous.Anonymous2.value2; }} }} + [UnscopedRef] public ref MyUnion u {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.u, 1)); + return ref Anonymous.u; }} }} + [UnscopedRef] public Span<{expectedManagedType}> buffer1 {{ get @@ -951,6 +971,7 @@ public Span<{expectedManagedType}> buffer1 }} }} + [UnscopedRef] public Span buffer2 {{ get @@ -1012,6 +1033,7 @@ public partial struct _buffer2_e__FixedBuffer public MyUnion e2; public MyUnion e3; + [UnscopedRef] public ref MyUnion this[int index] {{ get @@ -1020,6 +1042,7 @@ public ref MyUnion this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 4); }} }} @@ -1051,7 +1074,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() }; "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; namespace ClangSharp.Test { @@ -1064,19 +1087,21 @@ public partial struct MyStruct [NativeTypeName(""MyStruct::(anonymous struct at ClangUnsavedFile.h:6:5)"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int z { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; } } + [UnscopedRef] public ref int w { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous.w, 1)); + return ref Anonymous.Anonymous.w; } } @@ -1437,7 +1462,7 @@ protected override Task RemapNestedAnonymousTestImpl() }; };"; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; namespace ClangSharp.Test { @@ -1452,11 +1477,12 @@ public partial struct MyStruct [NativeTypeName(""MyStruct::(anonymous struct at ClangUnsavedFile.h:7:5)"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref double a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/UnionDeclarationTest.cs index 5e1212d8..9e0cba89 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/UnionDeclarationTest.cs @@ -352,6 +352,7 @@ union MyOtherUnion "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -376,6 +377,7 @@ public partial struct _c_e__FixedBuffer public MyUnion e1; public MyUnion e2; + [UnscopedRef] public ref MyUnion this[int index] {{ get @@ -384,6 +386,7 @@ public ref MyUnion this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} @@ -407,6 +410,7 @@ union MyOtherUnion "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -463,6 +467,7 @@ public partial struct _c_e__FixedBuffer public MyUnion e0_0_2_3; public MyUnion e1_0_2_3; + [UnscopedRef] public ref MyUnion this[int index] {{ get @@ -471,6 +476,7 @@ public ref MyUnion this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); }} }} @@ -496,6 +502,7 @@ union MyOtherUnion "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -520,6 +527,7 @@ public partial struct _c_e__FixedBuffer public MyUnion e1; public MyUnion e2; + [UnscopedRef] public ref MyUnion this[int index] {{ get @@ -528,6 +536,7 @@ public ref MyUnion this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} @@ -551,6 +560,7 @@ union MyOtherUnion "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -576,6 +586,7 @@ public partial struct _c_e__FixedBuffer public MyUnion e1; public MyUnion e2; + [UnscopedRef] public ref MyUnion this[int index] {{ get @@ -584,6 +595,7 @@ public ref MyUnion this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} @@ -791,6 +803,7 @@ union MyUnion "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -816,22 +829,25 @@ public unsafe partial struct MyUnion [NativeTypeName(""MyUnion::(anonymous union at ClangUnsavedFile.h:{line}:{column})"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref {expectedManagedType} a {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; }} }} + [UnscopedRef] public ref MyStruct s {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.s, 1)); + return ref Anonymous.s; }} }} + [UnscopedRef] public Span<{expectedManagedType}> buffer {{ get @@ -881,7 +897,8 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() }; "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -898,19 +915,21 @@ public partial struct MyUnion [NativeTypeName(""MyUnion::(anonymous union at ClangUnsavedFile.h:6:5)"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref int z { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; } } + [UnscopedRef] public ref int w { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous.w, 1)); + return ref Anonymous.Anonymous.w; } } @@ -1267,7 +1286,8 @@ protected override Task RemapNestedAnonymousTestImpl() }; };"; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -1287,11 +1307,12 @@ public partial struct MyUnion [NativeTypeName(""MyUnion::(anonymous union at ClangUnsavedFile.h:7:5)"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref double a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/FunctionDeclarationBodyImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/FunctionDeclarationBodyImportTest.cs index aaec45b1..99ff8018 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/FunctionDeclarationBodyImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/FunctionDeclarationBodyImportTest.cs @@ -1428,7 +1428,8 @@ void MyFunction() } "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -1439,11 +1440,12 @@ public partial struct MyUnion [NativeTypeName(""MyUnion::(anonymous struct at ClangUnsavedFile.h:3:5)"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/StructDeclarationTest.cs index 40e30d88..5d7b2863 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/StructDeclarationTest.cs @@ -347,6 +347,7 @@ struct MyOtherStruct "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -367,6 +368,7 @@ public partial struct _c_e__FixedBuffer public MyStruct e1; public MyStruct e2; + [UnscopedRef] public ref MyStruct this[int index] {{ get @@ -375,6 +377,7 @@ public ref MyStruct this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} @@ -398,6 +401,7 @@ struct MyOtherStruct "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -450,6 +454,7 @@ public partial struct _c_e__FixedBuffer public MyStruct e0_0_2_3; public MyStruct e1_0_2_3; + [UnscopedRef] public ref MyStruct this[int index] {{ get @@ -458,6 +463,7 @@ public ref MyStruct this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); }} }} @@ -483,6 +489,7 @@ struct MyOtherStruct "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -503,6 +510,7 @@ public partial struct _c_e__FixedBuffer public MyStruct e1; public MyStruct e2; + [UnscopedRef] public ref MyStruct this[int index] {{ get @@ -511,6 +519,7 @@ public ref MyStruct this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} @@ -534,6 +543,7 @@ struct MyOtherStruct "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -555,6 +565,7 @@ public partial struct _c_e__FixedBuffer public MyStruct e1; public MyStruct e2; + [UnscopedRef] public ref MyStruct this[int index] {{ get @@ -563,6 +574,7 @@ public ref MyStruct this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} @@ -879,6 +891,7 @@ struct MyStruct "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -899,54 +912,61 @@ public unsafe partial struct MyStruct [NativeTypeName(""MyStruct::(anonymous struct at ClangUnsavedFile.h:{line}:{column})"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref {expectedManagedType} z {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; }} }} + [UnscopedRef] public ref _Anonymous_e__Struct._w_e__Struct w {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.w, 1)); + return ref Anonymous.w; }} }} + [UnscopedRef] public ref {expectedManagedType} value1 {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.value1, 1)); + return ref Anonymous.Anonymous1.value1; }} }} + [UnscopedRef] public ref {expectedManagedType} value {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.Anonymous.value, 1)); + return ref Anonymous.Anonymous1.Anonymous.value; }} }} + [UnscopedRef] public ref {expectedManagedType} value2 {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous2.value2, 1)); + return ref Anonymous.Anonymous2.value2; }} }} + [UnscopedRef] public ref MyUnion u {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.u, 1)); + return ref Anonymous.u; }} }} + [UnscopedRef] public Span<{expectedManagedType}> buffer1 {{ get @@ -955,6 +975,7 @@ public Span<{expectedManagedType}> buffer1 }} }} + [UnscopedRef] public Span buffer2 {{ get @@ -1016,6 +1037,7 @@ public partial struct _buffer2_e__FixedBuffer public MyUnion e2; public MyUnion e3; + [UnscopedRef] public ref MyUnion this[int index] {{ get @@ -1024,6 +1046,7 @@ public ref MyUnion this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 4); }} }} @@ -1055,7 +1078,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() }; "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; namespace ClangSharp.Test { @@ -1068,19 +1091,21 @@ public partial struct MyStruct [NativeTypeName(""MyStruct::(anonymous struct at ClangUnsavedFile.h:6:5)"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int z { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; } } + [UnscopedRef] public ref int w { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous.w, 1)); + return ref Anonymous.Anonymous.w; } } @@ -1441,7 +1466,7 @@ protected override Task RemapNestedAnonymousTestImpl() }; };"; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; namespace ClangSharp.Test { @@ -1456,11 +1481,12 @@ public partial struct MyStruct [NativeTypeName(""MyStruct::(anonymous struct at ClangUnsavedFile.h:7:5)"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref double a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/UnionDeclarationTest.cs index 265bab95..3cedbb23 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/UnionDeclarationTest.cs @@ -358,6 +358,7 @@ union MyOtherUnion "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -382,6 +383,7 @@ public partial struct _c_e__FixedBuffer public MyUnion e1; public MyUnion e2; + [UnscopedRef] public ref MyUnion this[int index] {{ get @@ -390,6 +392,7 @@ public ref MyUnion this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} @@ -413,6 +416,7 @@ union MyOtherUnion "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -469,6 +473,7 @@ public partial struct _c_e__FixedBuffer public MyUnion e0_0_2_3; public MyUnion e1_0_2_3; + [UnscopedRef] public ref MyUnion this[int index] {{ get @@ -477,6 +482,7 @@ public ref MyUnion this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); }} }} @@ -502,6 +508,7 @@ union MyOtherUnion "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -526,6 +533,7 @@ public partial struct _c_e__FixedBuffer public MyUnion e1; public MyUnion e2; + [UnscopedRef] public ref MyUnion this[int index] {{ get @@ -534,6 +542,7 @@ public ref MyUnion this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} @@ -557,6 +566,7 @@ union MyOtherUnion "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -582,6 +592,7 @@ public partial struct _c_e__FixedBuffer public MyUnion e1; public MyUnion e2; + [UnscopedRef] public ref MyUnion this[int index] {{ get @@ -590,6 +601,7 @@ public ref MyUnion this[int index] }} }} + [UnscopedRef] public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} @@ -797,6 +809,7 @@ union MyUnion "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -822,22 +835,25 @@ public unsafe partial struct MyUnion [NativeTypeName(""MyUnion::(anonymous union at ClangUnsavedFile.h:{line}:{column})"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref {expectedManagedType} a {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; }} }} + [UnscopedRef] public ref MyStruct s {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.s, 1)); + return ref Anonymous.s; }} }} + [UnscopedRef] public Span<{expectedManagedType}> buffer {{ get @@ -887,7 +903,8 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() }; "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -904,19 +921,21 @@ public partial struct MyUnion [NativeTypeName(""MyUnion::(anonymous union at ClangUnsavedFile.h:6:5)"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref int z { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; } } + [UnscopedRef] public ref int w { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous.w, 1)); + return ref Anonymous.Anonymous.w; } } @@ -1273,7 +1292,8 @@ protected override Task RemapNestedAnonymousTestImpl() }; };"; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -1293,11 +1313,12 @@ public partial struct MyUnion [NativeTypeName(""MyUnion::(anonymous union at ClangUnsavedFile.h:7:5)"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref double a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/FunctionDeclarationBodyImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/FunctionDeclarationBodyImportTest.cs index 04d30018..d3e36461 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/FunctionDeclarationBodyImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/FunctionDeclarationBodyImportTest.cs @@ -1618,7 +1618,7 @@ void MyFunction() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/StructDeclarationTest.cs index 32883c07..b5b77f28 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/StructDeclarationTest.cs @@ -931,19 +931,19 @@ struct MyStruct ref {expectedManagedType} - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref _Anonymous_e__Struct._w_e__Struct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.w, 1)); + return ref Anonymous.w; ref MyUnion - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.u, 1)); + return ref Anonymous.u; @@ -1052,13 +1052,13 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous.w, 1)); + return ref Anonymous.Anonymous.w; @@ -1444,7 +1444,7 @@ protected override Task RemapNestedAnonymousTestImpl() ref double - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/UnionDeclarationTest.cs index f11ed119..5ee6785e 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/UnionDeclarationTest.cs @@ -785,13 +785,13 @@ union MyUnion ref {expectedManagedType} - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; ref MyStruct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.s, 1)); + return ref Anonymous.s; @@ -856,13 +856,13 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous.w, 1)); + return ref Anonymous.Anonymous.w; @@ -1195,7 +1195,7 @@ protected override Task RemapNestedAnonymousTestImpl() ref double - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/FunctionDeclarationBodyImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/FunctionDeclarationBodyImportTest.cs index 0584ff7a..06b23f55 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/FunctionDeclarationBodyImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/FunctionDeclarationBodyImportTest.cs @@ -1618,7 +1618,7 @@ void MyFunction() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/StructDeclarationTest.cs index 4112953e..44b5e788 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/StructDeclarationTest.cs @@ -937,19 +937,19 @@ struct MyStruct ref {expectedManagedType} - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref _Anonymous_e__Struct._w_e__Struct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.w, 1)); + return ref Anonymous.w; ref MyUnion - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.u, 1)); + return ref Anonymous.u; @@ -1058,13 +1058,13 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous.w, 1)); + return ref Anonymous.Anonymous.w; @@ -1450,7 +1450,7 @@ protected override Task RemapNestedAnonymousTestImpl() ref double - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/UnionDeclarationTest.cs index 91d6d748..2e707c41 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/UnionDeclarationTest.cs @@ -791,13 +791,13 @@ union MyUnion ref {expectedManagedType} - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; ref MyStruct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.s, 1)); + return ref Anonymous.s; @@ -862,13 +862,13 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous.w, 1)); + return ref Anonymous.Anonymous.w; @@ -1201,7 +1201,7 @@ protected override Task RemapNestedAnonymousTestImpl() ref double - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a;