| ... | ... | @@ -376,7 +376,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_node: NodeIndex, field_nod |
| 376 | 376 | const has_alignment_attributes = record_decl.field_attributes != null or |
| 377 | 377 | raw_record_ty.hasAttribute(.@"packed") or |
| 378 | 378 | 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; |
| 380 | 380 | |
| 381 | 381 | // Iterate over field nodes so that we translate any type decls included in this record decl. |
| 382 | 382 | // 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 { |
| 734 | 734 | } |
| 735 | 735 | } |
| 736 | 736 | |
| 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'. |
| 739 | 745 | fn alignmentForField( |
| 740 | 746 | record_decl: *const Type.Record, |
| 741 | 747 | head_field_alignment: ?c_uint, |