Look ahead through the fields of the record to determine what the alignment of the record
would be without any align/packed/etc. attributes. This helps us determine whether or not
the fields with 0 offset need an align qualifier. Strictly speaking, we could just
pedantically assign those fields the same alignment as the parent's pointer alignment,
but this helps the generated code to be a little less verbose.
fn headFieldAlignment(t: *Translator, record_decl: aro.Type.Record) ?c_uint
fn headFieldAlignment(t: *Translator, record_decl: aro.Type.Record) ?c_uint {
const bits_per_byte = 8;
const parent_ptr_alignment_bits = record_decl.layout.?.pointer_alignment_bits;
const parent_ptr_alignment = parent_ptr_alignment_bits / bits_per_byte;
var max_field_alignment_bits: u64 = 0;
for (record_decl.fields) |field|
max_field_alignment_bits = @max(max_field_alignment_bits, bits_per_byte * field.qt.alignof(t.comp));
if (max_field_alignment_bits != parent_ptr_alignment_bits) {
return parent_ptr_alignment;
} else {
return null;
}
}