Function rustc::middle::trans::adt::trans_const[src]
pub fn trans_const(ccx: &CrateContext, r: &Repr, discr: Disr, vals: &[ValueRef]) -> ValueRef
Construct a constant value, suitable for initializing a
GlobalVariable, given a case and constant values for its fields.
Note that this may have a different LLVM type (and different
alignment!) from the representation's type_of, so it needs a
pointer cast before use.
The LLVM type system does not directly support unions, and only pointers can be bitcast, so a constant (and, by extension, the GlobalVariable initialized by it) will have a type that can vary depending on which case of an enum it is.
To understand the alignment situation, consider enum E { V64(u64),
V32(u32, u32) } on win32. The type has 8-byte alignment to
accommodate the u64, but V32(x, y) would have LLVM type {i32,
i32, i32}, which is 4-byte aligned.
Currently the returned value has the same size as the type, but this could be changed in the future to avoid allocating unnecessary space after values of shorter-than-maximum cases.