zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 11911f55a73a49e2fda85bddd38d1993b93547c9 (tree)
parent 9d098657a069b36e3eed9bc63c3421c031be7348
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Wed, 27 Apr 2022 23:33:16 -0700

stage1: fix incorrect struct padding

Before this change, struct {f80, f80} targeting i386-windows-msvc lowers
to

```llvm
%"std.testing.struct:78:61.6" = type { x86_fp80, [6 x i8], x86_fp80, [6 x i8] }
```

which has an incorrect ABI size of 40. After this change, the struct
lowers to

```llvm
%"std.testing.struct:78:61.6" = type { x86_fp80, [4 x i8], x86_fp80, [4 x i8] }
```

which has the correct ABI size of 32, and properly aligns the second
field to 16 bytes.

The other place that calculates field padding (lowering of constant
values in codegen.cpp) already correctly calls LLVMABISizeOfType
rather than LLVMStoreSizeOfType.

This fixes the compiler-rt tests for i386-windows in this branch.

Diffstat:
Msrc/stage1/analyze.cpp | 2+-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp @@ -8928,7 +8928,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS assert(next_offset >= llvm_next_offset); if (next_offset > llvm_next_offset) { - size_t pad_bytes = next_offset - (field->offset + LLVMStoreSizeOfType(g->target_data_ref, llvm_type)); + size_t pad_bytes = next_offset - (field->offset + LLVMABISizeOfType(g->target_data_ref, llvm_type)); if (pad_bytes != 0) { LLVMTypeRef pad_llvm_type = LLVMArrayType(LLVMInt8Type(), pad_bytes); element_types[gen_field_index] = pad_llvm_type;