diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Module.zig | 30 | ||||
| -rw-r--r-- | src/type.zig | 16 |
2 files changed, 33 insertions, 13 deletions
diff --git a/src/Module.zig b/src/Module.zig index 6d2180e8e7..3ae61c264f 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -948,20 +948,28 @@ pub const Struct = struct { switch (layout) { .Packed => return 0, - .Auto => return field.ty.abiAlignment(target), - .Extern => { - // This logic is duplicated in Type.abiAlignmentAdvanced. - const ty_abi_align = field.ty.abiAlignment(target); - - if (field.ty.isAbiInt() and field.ty.intInfo(target).bits >= 128) { - // The C ABI requires 128 bit integer fields of structs - // to be 16-bytes aligned. - return @maximum(ty_abi_align, 16); + .Auto => { + if (target.ofmt == .c) { + return alignmentExtern(field, target); + } else { + return field.ty.abiAlignment(target); } - - return ty_abi_align; }, + .Extern => return alignmentExtern(field, target), + } + } + + pub fn alignmentExtern(field: Field, target: Target) u32 { + // This logic is duplicated in Type.abiAlignmentAdvanced. + const ty_abi_align = field.ty.abiAlignment(target); + + if (field.ty.isAbiInt() and field.ty.intInfo(target).bits >= 128) { + // The C ABI requires 128 bit integer fields of structs + // to be 16-bytes aligned. + return @maximum(ty_abi_align, 16); } + + return ty_abi_align; } }; diff --git a/src/type.zig b/src/type.zig index fb2ca1e3fc..6a66fb9d70 100644 --- a/src/type.zig +++ b/src/type.zig @@ -3019,7 +3019,7 @@ pub const Type = extern union { big_align = @maximum(big_align, field_align); // This logic is duplicated in Module.Struct.Field.alignment. - if (struct_obj.layout == .Extern) { + if (struct_obj.layout == .Extern or target.ofmt == .c) { if (field.ty.isAbiInt() and field.ty.intInfo(target).bits >= 128) { // The C ABI requires 128 bit integer fields of structs // to be 16-bytes aligned. @@ -3348,7 +3348,13 @@ pub const Type = extern union { .f128 => return AbiSizeAdvanced{ .scalar = 16 }, .f80 => switch (target.cpu.arch) { - .i386 => return AbiSizeAdvanced{ .scalar = 12 }, + .i386 => switch (target.os.tag) { + .windows => switch (target.abi) { + .msvc => return AbiSizeAdvanced{ .scalar = 16 }, + else => return AbiSizeAdvanced{ .scalar = 12 }, + }, + else => return AbiSizeAdvanced{ .scalar = 12 }, + }, .x86_64 => return AbiSizeAdvanced{ .scalar = 16 }, else => { var payload: Payload.Bits = .{ @@ -4559,6 +4565,12 @@ pub const Type = extern union { .vector => ty = ty.castTag(.vector).?.data.elem_type, + .@"struct" => { + const struct_obj = ty.castTag(.@"struct").?.data; + assert(struct_obj.layout == .Packed); + ty = struct_obj.backing_int_ty; + }, + else => unreachable, }; } |
