aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-08-18 20:34:36 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-08-18 20:34:36 -0700
commitcee82c7ce4fb8beb39042f9dba16a1a391803fa4 (patch)
treeea2a12b10b3742acc3f343a36bf14a8c34246776 /src/Module.zig
parentb975f7a56fec9e0e7aca9832282bc772c743d731 (diff)
downloadzig-cee82c7ce4fb8beb39042f9dba16a1a391803fa4.tar.gz
zig-cee82c7ce4fb8beb39042f9dba16a1a391803fa4.zip
improved ABI alignment/size for >= 128-bit integers
* riscv64: adjust alignment and size of 128-bit integers. * take ofmt=c into account for ABI alignment of 128-bit integers and structs. * Type: make packed struct support intInfo * fix f80 alignment for i386-windows-msvc
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig30
1 files changed, 19 insertions, 11 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;
}
};