| ... | @@ -376,7 +376,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_node: NodeIndex, field_nod | ... | @@ -376,7 +376,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_node: NodeIndex, field_nod |
| 376 | const has_alignment_attributes = record_decl.field_attributes != null or | 376 | const has_alignment_attributes = record_decl.field_attributes != null or |
| 377 | raw_record_ty.hasAttribute(.@"packed") or | 377 | raw_record_ty.hasAttribute(.@"packed") or |
| 378 | raw_record_ty.hasAttribute(.aligned); | 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 | // Iterate over field nodes so that we translate any type decls included in this record decl. | 381 | // Iterate over field nodes so that we translate any type decls included in this record decl. |
| 382 | // TODO: Move this logic into `fn transType()` instead of handling decl translation here. | 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,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. | 737 | /// This function inspects the generated layout of a record to determine the alignment for a |
| 738 | /// This can be changed to a u29 after the Clang frontend for translate-c is removed. | 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 | fn alignmentForField( | 745 | fn alignmentForField( |
| 740 | record_decl: *const Type.Record, | 746 | record_decl: *const Type.Record, |
| 741 | head_field_alignment: ?c_uint, | 747 | head_field_alignment: ?c_uint, |