Skip to content

Latest commit

 

History

History
39 lines (21 loc) · 2.49 KB

iii.4.10-ldfld.md

File metadata and controls

39 lines (21 loc) · 2.49 KB

III.4.10 ldfld – load field of an object

Format Assembly Format Description
7B <T> ldfld field Push the value of field of object (or value type) obj, onto the stack.

Stack Transition:

…, obj → …, value

Description:

The ldfld instruction pushes onto the stack the value of a field of obj. obj shall be an object (type O), a managed pointer (type &), an unmanaged pointer (type native int), or an instance of a value type. The use of an unmanaged pointer is not permitted in verifiable code. field is a metadata token (a fieldref or fielddef see Partition II) that shall refer to a field member. The return type is that associated with field. ldfld pops the object reference off the stack and pushes the value for the field in its place. The field can be either an instance field (in which case obj shall not be null) or a static field.

The ldfld instruction can be preceded by either or both of the unaligned. and volatile. prefixes. If required field values are converted to the representation of their intermediate typeI.8.7) when loaded onto the stack (§III.1.1.1).

[Note: That is field values that are smaller than 4 bytes, a boolean or a character are converted to 4 bytes by sign or zero-extension as appropriate. Floating-point values are converted to their native size (type F). end note]

Exceptions:

System.FieldAccessException is thrown if field is not accessible.

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 is not static.

Correctness:

Correct CIL ensures that field is a valid token referring to a field, 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.

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 tracks the type of the value on the stack as the intermediate typeI.8.7) of the field type.