Skip to content

Dynamic block nodes should not generate non-null assertions #62328

Closed
@SingleAccretion

Description

@SingleAccretion

Reproduction:

using System.Runtime.CompilerServices;

Problem(ref Unsafe.NullRef<byte>(), ref Unsafe.NullRef<byte>(), 0);

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
private static ref int Problem(ref byte dst, ref byte src, uint count)
{
    Unsafe.CopyBlock(ref dst, ref src, count);

    return ref Unsafe.As<byte, StructWithIndex>(ref src).Value;
}

struct StructWithIndex
{
    public int Index;
    public int Value;
}

Expected result: NRE.
Actual result: the program exits normally.

Cause: we make assertion for the IND struct node which is the source for the dynamic block copy:

GenTreeNode creates assertion:
N002 (  3,  2) [000011] ---X---N----              *  IND       struct <l:$1c1, c:$1c0>
In BB01 New Global Constant Assertion: ($81,$0) Value_Number {InitVal($41)} is not 0, index = #01

We cannot make non-null assertions for addresses of dynamic block nodes because in the degenerate case of zero-sized copies, the indirection will not be realized. There is language in ECMA 335 saying that this is what is to be expected:

III.3.30 cpblk – copy data from memory to memory

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

This applies to both source and destination addresses.

category:correctness
theme:assertion-prop

Metadata

Metadata

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIbug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions