mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-17 16:38:33 +00:00
fixes basic type alignement issue on i386 platform. (#6209)
This commit is contained in:
committed by
Andreas Rumpf
parent
f64eee3a1e
commit
837b77b0a1
@@ -1512,9 +1512,26 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||
dec c.inTypeContext
|
||||
|
||||
proc setMagicType(m: PSym, kind: TTypeKind, size: int) =
|
||||
# source : https://en.wikipedia.org/wiki/Data_structure_alignment#x86
|
||||
m.typ.kind = kind
|
||||
m.typ.align = size.int16
|
||||
m.typ.size = size
|
||||
# this usually works for most basic types
|
||||
# Assuming that since ARM, ARM64 don't support unaligned access
|
||||
# data is aligned to type size
|
||||
m.typ.align = size.int16
|
||||
|
||||
# FIXME: proper support for clongdouble should be added.
|
||||
# long double size can be 8, 10, 12, 16 bytes depending on platform & compiler
|
||||
if targetCPU == cpuI386 and size == 8:
|
||||
#on Linux/BSD i386, double are aligned to 4bytes (except with -malign-double)
|
||||
if kind in {tyFloat64, tyFloat} and
|
||||
targetOS in {osLinux, osAndroid, osNetbsd, osFreebsd, osOpenbsd, osDragonfly}:
|
||||
m.typ.align = 4
|
||||
# on i386, all known compiler, 64bits ints are aligned to 4bytes (except with -malign-double)
|
||||
elif kind in {tyInt, tyUInt, tyInt64, tyUInt64}:
|
||||
m.typ.align = 4
|
||||
else:
|
||||
discard
|
||||
|
||||
proc processMagicType(c: PContext, m: PSym) =
|
||||
case m.magic
|
||||
|
||||
Reference in New Issue
Block a user