diff options
Diffstat (limited to 'compiler/sizealignoffsetimpl.nim')
-rw-r--r-- | compiler/sizealignoffsetimpl.nim | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/compiler/sizealignoffsetimpl.nim b/compiler/sizealignoffsetimpl.nim index 573b27094..4791788fa 100644 --- a/compiler/sizealignoffsetimpl.nim +++ b/compiler/sizealignoffsetimpl.nim @@ -1,3 +1,12 @@ +# +# +# The Nim Compiler +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# +## code owner: Arne Döring +## e-mail: arne.doering@gmx.net proc align(address, alignment: BiggestInt): BiggestInt = result = (address + (alignment - 1)) and not (alignment - 1) @@ -118,9 +127,14 @@ proc computeObjectOffsetsFoldFunction(conf: ConfigRef; n: PNode, initialOffset: result.offset = align(offset, result.align) of nkSym: - computeSizeAlign(conf, n.sym.typ) - let size = n.sym.typ.size - let align = n.sym.typ.align + var size = szUnknownSize + var align = szUnknownSize + + if n.sym.bitsize == 0: # 0 represents bitsize not set + computeSizeAlign(conf, n.sym.typ) + size = n.sym.typ.size.int + align = n.sym.typ.align.int + result.align = align if initialOffset == szUnknownSize or size == szUnknownSize: n.sym.offset = szUnknownSize @@ -309,16 +323,24 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) = var headerAlign: int16 if typ.sons[0] != nil: # compute header size - var st = typ.sons[0] - while st.kind in skipPtrs: - st = st.sons[^1] - computeSizeAlign(conf, st) - if st.size == szIllegalRecursion: - typ.size = st.size - typ.align = st.align - return - headerSize = st.size - headerAlign = st.align + + if conf.cmd == cmdCompileToCpp: + # if the target is C++ the members of this type are written + # into the padding byets at the end of the parent type. At the + # moment it is not supported to calculate that. + headerSize = szUnknownSize + headerAlign = szUncomputedSize + else: + var st = typ.sons[0] + while st.kind in skipPtrs: + st = st.sons[^1] + computeSizeAlign(conf, st) + if st.size == szIllegalRecursion: + typ.size = st.size + typ.align = st.align + return + headerSize = st.size + headerAlign = st.align elif isObjectWithTypeFieldPredicate(typ): # this branch is taken for RootObj headerSize = conf.target.intSize |