Skip to content

Latest commit

 

History

History
43 lines (23 loc) · 2.38 KB

iii.4.28-stfld.md

File metadata and controls

43 lines (23 loc) · 2.38 KB

III.4.28 stfld – store into a field of an object

Format Assembly Format Description
7D <T> stfld field Replace the value of field of the object obj with value.

Stack Transition:

…, obj, value → …,

Description:

The stfld instruction replaces the value of a field of an obj (an O) or via a pointer (type native int, or &) with value. field is a metadata token (a fieldref or fielddef; see Partition II) that refers to a field member reference. stfld pops the value and the object reference off the stack and updates the object.

Storing into fields that hold a value smaller than 4 bytes truncates the value as it moves from the stack to the local variable. Floating-point values are rounded from their native size (type F) to the size associated with the argument. (See §III.1.1.1, Numeric data types.)

The stfld instruction can have a prefix of either or both of unaligned. and volatile..

Exceptions:

System.FieldAccessException is thrown if field is not accessible.

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

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.

Correctness:

Correct CIL ensures that field is a valid token referring to a field, and that obj and value will always have types appropriate for the assignment being performed, subject to implicit conversion as specified in §III.1.6.

Verifiability:

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

[Note: Using stfld to change the value of a static, init-only field outside the body of the class initializer can lead to unpredictable behavior. It cannot, however, compromise memory integrity or type safety so it is not tested by verification. end note]

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 also checks that the type of value is verifier-assignable-to the type of the field.