pub struct VlaDef {
pub object: ObjectId,
pub storage: ObjectId,
pub count: Expr,
pub align: Option<u64>,
pub range: SourceRange,
}Expand description
A variably modified object’s definition: T a[n];, T a[n][m];.
C99 6.7.5.2 gives the object automatic storage duration, a size fixed when
the declaration is reached, and the lifetime of the block it is written in;
each bound is evaluated exactly once, where the declaration stands, and
lives in a hidden size_t object the type points at.
This crate emulates the storage with a per-function bump arena on the heap
— the elements are bumped off it, and a hidden frame guard whose Drop
moves the arena back down is that lifetime — so the one definition becomes
a Stmt::Let per bound followed by two more bindings:
let __cinrs_vla_len_a: size_t = <n>; // one per bound
let __cinrs_vla_frame_a = __cinrs_vla.frame(); // frame
let mut a: *mut T = __cinrs_vla.alloc::<T>(count); // objectFrom there the object is a pointer to the first element: decay is the
identity, a[i] is pointer indexing scaled by the run-time size of a row,
and sizeof a is the product of the bounds times the element size — see
Types::vm_step_ty for what “element” means once more than one dimension
is variable.
Fields§
§object: ObjectIdThe object the C program declared, whose type is the array type and whose generated binding is a pointer to the first element.
storage: ObjectIdThe hidden frame that gives the elements back; see
Object::vla_storage.
count: ExprThe number of elements to allocate: the product of every dimension, read out of the hidden bound objects, in units of the storage’s element type.
align: Option<u64>The alignment _Alignas(N) or __attribute__((aligned(N))) asked
for, when it is stricter than the element type’s: the arena then pads
its position to the first address that is a multiple of it.
range: SourceRangeWhere the declarator was written.