authorgravatar for february.cozzocrea@gmail.comfebruary cozzocrea <february.cozzocrea@gmail.com> 2024-05-16 15:33:44-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-20 07:35:10-04:00
logd67d9fa357d41a747e5a334d30cb5f45fddaa356
tree87e4739a0b7128fcc1cde169fb26d12fd7c19573
parent4239a0d9c3590c89fec1e97611801c6cd00660ad

Minor follow-up improvements to PR #19227 for aro translate-c


1 files changed, 9 insertions(+), 3 deletions(-)

lib/compiler/aro_translate_c.zig+9-3
......@@ -376,7 +376,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_node: NodeIndex, field_nod
376376 const has_alignment_attributes = record_decl.field_attributes != null or
377377 raw_record_ty.hasAttribute(.@"packed") or
378378 raw_record_ty.hasAttribute(.aligned);
379 const head_field_alignment: ?c_uint = headFieldAlignment(record_decl);
379 const head_field_alignment: ?c_uint = if (has_alignment_attributes) headFieldAlignment(record_decl) else null;
380380
381381 // Iterate over field nodes so that we translate any type decls included in this record decl.
382382 // TODO: Move this logic into `fn transType()` instead of handling decl translation here.
......@@ -734,8 +734,14 @@ fn headFieldAlignment(record_decl: *const Type.Record) ?c_uint {
734734 }
735735}
736736
737/// This function returns a ?c_uint to match Clang's behaviour of using c_uint.
738/// This can be changed to a u29 after the Clang frontend for translate-c is removed.
737/// This function inspects the generated layout of a record to determine the alignment for a
738/// particular field. This approach is necessary because unlike Zig, a C compiler is not
739/// required to fulfill the requested alignment, which means we'd risk generating different code
740/// if we only look at the user-requested alignment.
741///
742/// Returns a ?c_uint to match Clang's behaviour of using c_uint. The return type can be changed
743/// after the Clang frontend for translate-c is removed. A null value indicates that a field is
744/// 'naturally aligned'.
739745fn alignmentForField(
740746 record_decl: *const Type.Record,
741747 head_field_alignment: ?c_uint,