compiler: fix incorrect unsafe.Alignof on some 32-bit architectures

This should fix https://github.com/tinygo-org/tinygo/issues/2643
This commit is contained in:
Ayke van Laethem
2022-03-01 14:50:28 +01:00
committed by Ayke
parent ecb7eebcff
commit 29c1d7c68d
3 changed files with 21 additions and 1 deletions
+6 -1
View File
@@ -234,10 +234,15 @@ func Sizes(machine llvm.TargetMachine) types.Sizes {
panic("unknown pointer size")
}
// Construct a complex128 type because that's likely the type with the
// biggest alignment on most/all ABIs.
ctx := llvm.NewContext()
defer ctx.Dispose()
complex128Type := ctx.StructType([]llvm.Type{ctx.DoubleType(), ctx.DoubleType()}, false)
return &stdSizes{
IntSize: int64(intWidth / 8),
PtrSize: int64(targetData.PointerSize()),
MaxAlign: int64(targetData.PrefTypeAlignment(targetData.IntPtrType())),
MaxAlign: int64(targetData.ABITypeAlignment(complex128Type)),
}
}