Skip to content

Latest commit

 

History

History
41 lines (22 loc) · 2.07 KB

iii.4.9-ldelema.md

File metadata and controls

41 lines (22 loc) · 2.07 KB

III.4.9 ldelema – load address of an element of an array

Format Assembly Format Description
8F <T> ldelema typeTok Load the address of element at index onto the top of the stack.

Stack Transition:

…, array, index → …, address

Description:

The ldelema instruction loads the address of the element with index index (of type int32 or native int) in the zero-based one-dimensional array array (of element type verifier-assignable-to typeTok) and places it on the top of the stack. Arrays are objects and hence represented by a value of type O. The return address is a managed pointer (type &).

[Note: For one-dimensional arrays that aren't zero-based and for multidimensional arrays, the array class provides an Address method. end note]

If this instruction is prefixed by the readonly. prefix, it produces a controlled-mutability managed pointer (§III.1.8.1.2.2).

Exceptions:

System.NullReferenceException is thrown if array is null.

System.IndexOutOfRangeException is thrown if index is negative, or larger than the bound of array.

System.ArrayTypeMismatchException is thrown if array doesn't hold elements of the required type.

Correctness:

Correct CIL ensures that class is a typeref or typedef or typespec token to a class, and that array is indeed always either null or a zero-based, one-dimensional array whose declared element type is verifier-assignable-to typeTok.

Verifiability:

Verification requires that:

  • the tracked type of array is T[], for some T, or the Null type (§III.1.8.1.2);

  • a managed pointer to T is pointer-element-compatible-withI.8.7.1) a managed pointer to typeTok; and

  • the type of index is int32 or native int.

Verification tracks the type of the result address as a managed pointer to the verification type of typeTok.