diff --git a/Src/ILGPU.Tests/MemoryBufferOperations.tt b/Src/ILGPU.Tests/MemoryBufferOperations.tt index 7bd5a6ec9..5b8ae7b1a 100644 --- a/Src/ILGPU.Tests/MemoryBufferOperations.tt +++ b/Src/ILGPU.Tests/MemoryBufferOperations.tt @@ -109,6 +109,27 @@ namespace ILGPU.Tests { output[index] = input[index]; } + + internal static void EmptyView_Kernel( + Index1D index, + ArrayView1D output) + where T : unmanaged + { + if (index < output.Length) + output[index] = default(T); + } + +<# foreach (var type in copyTypes) { #> + [Fact] + [KernelMethod(nameof(EmptyView_Kernel))] + public void EmptyView_<#= type.Name #>() + { + Execute>( + 42, + ArrayView1D<<#= type.Type #>, Stride1D.Dense>.Empty); + } + +<# } #> internal static void ZeroLength_Kernel( Index1D index, diff --git a/Src/ILGPU/Backends/PointerViews/Utilities.cs b/Src/ILGPU/Backends/PointerViews/Utilities.cs index 370fae61a..79eb0957e 100644 --- a/Src/ILGPU/Backends/PointerViews/Utilities.cs +++ b/Src/ILGPU/Backends/PointerViews/Utilities.cs @@ -92,7 +92,7 @@ public static FieldInfo GetLengthField(Type implType) => /// The underlying native pointer. private static IntPtr GetNativePtr(in ArrayView view) where T : unmanaged => - view.Buffer.NativePtr; + view.Buffer?.NativePtr ?? IntPtr.Zero; /// /// Gets the native-pointer method for the given element type.