Skip to content

Latest commit

 

History

History
47 lines (25 loc) · 2.45 KB

iii.4.11-ldflda.md

File metadata and controls

47 lines (25 loc) · 2.45 KB

III.4.11 ldflda – load field address

Format Assembly Format Description
7C <T> ldflda field Push the address of field of object obj on the stack.

Stack Transition:

…, obj → …, address

Description:

The ldflda instruction pushes the address of a field of obj. obj is either an object, type O, a managed pointer, type &, or an unmanaged pointer, type native int. The use of an unmanaged pointer is not allowed in verifiable code. The value returned by ldflda is a managed pointer (type &) unless obj is an unmanaged pointer, in which case it is an unmanaged pointer (type native int).

field is a metadata token (a fieldref or fielddef; see Partition II) that shall refer to a field member. The field can be either an instance field (in which case obj shall not be null) or a static field.

Exceptions:

System.FieldAccessException is thrown if field is not accessible.

System.InvalidOperationException is thrown if the obj is not within the application domain from which it is being accessed. The address of a field that is not inside the accessing application domain cannot be loaded.

System.MissingFieldException is thrown if field is not found in the metadata. This is typically checked when CIL is converted to native code, not at runtime.

System.NullReferenceException is thrown if obj is null and the field isn't static.

Correctness:

Correct CIL ensures that field is a valid fieldref token and that the type of obj is compatible-with the Class of field.

Verifiability:

For verifiable code, obj shall not be an unmanaged pointer.

The tracked type of obj shall have, or be a managed pointer to a type which has, a static or instance field.

For verifiable code, field cannot be init-only.

It is not verifiable to access an overlapped object reference field.

A field is accessible only if every field that overlaps it is also accessible.

Verification (§III.1.8) tracks the type of the value loaded onto the stack as a managed pointer to the verification typeI.8.7) of field.

Remark:

Using ldflda to compute the address of a static, init-only field and then using the resulting pointer to modify that value outside the body of the class initializer might lead to unpredictable behavior.