Skip to content

Unify semantics of cpblk and initblk of zero size between Mono and CoreCLR #63038

@SingleAccretion

Description

@SingleAccretion

It was discovered in a CI run (Mono monointerpreter Pri0 Runtime Tests Run OSX x64 release) that (at least when using the interpreter) Mono throws a NullReferenceException when executing a cpblk with a size of zero (I suspect it is the same for initblk).

Reproduction:

using System;
using System.Runtime.CompilerServices;

Console.WriteLine(TestCpBlk(ref Unsafe.NullRef<byte>(), ref Unsafe.NullRef<byte>(), 0));

[MethodImpl(MethodImplOptions.NoInlining)]
static bool TestCpBlk(ref byte dst, ref byte src, uint size)
{
    Unsafe.CopyBlock(ref dst, ref src, size);

    return Unsafe.AreSame(ref dst, ref Unsafe.NullRef<byte>());
}

In ECMA 335, III.3.30 cpblk/III.3.36 initblk, we can find under Exceptions:

System.NullReferenceException can be thrown if an invalid address is detected.

Suggesting that both throwing and not throwing are legal behaviors (and they both seem reasonable). But it would be nice to have the two runtimes behave the same.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions