Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1377,16 +1377,11 @@ protected override void AllocAndTransformManagedToNative(ILCodeStream codeStream
{
ILLocalVariable vPinnedFirstElement = emitter.NewLocal(ManagedElementType.MakeByRefType(), true);

LoadManagedValue(codeStream);
codeStream.Emit(ILOpcode.ldlen);
codeStream.Emit(ILOpcode.conv_i4);
codeStream.Emit(ILOpcode.brfalse, lNullArray);

LoadManagedValue(codeStream);
codeStream.Emit(ILOpcode.call, emitter.NewToken(getArrayDataReferenceMethod));
codeStream.EmitStLoc(vPinnedFirstElement);

// Fall through. If array didn't have elements, vPinnedFirstElement is zeroinit.
// Fall through. If array is null, vPinnedFirstElement is zeroinit.
codeStream.EmitLabel(lNullArray);
codeStream.EmitLdLoc(vPinnedFirstElement);
codeStream.Emit(ILOpcode.conv_i);
Expand Down
6 changes: 6 additions & 0 deletions src/tests/nativeaot/SmokeTests/PInvoke/PInvoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ private static void TestArrays()

ThrowIfNotEquals(0, CheckIncremental(arr, ArraySize), "Array marshalling failed");

int[] empty = new int[0];
ThrowIfNotEquals(0, CheckIncremental(empty, 0), "Empty array marshalling failed");

int[] nullArray = null;
ThrowIfNotEquals(1, CheckIncremental(nullArray, 0), "Null array marshalling failed");

Console.WriteLine("Testing marshalling blittable struct arrays");

Foo[] arr_foo = null;
Expand Down