sizeof for empty objects/tuples should be 1; fixes #14690 (#14751)

This commit is contained in:
Andreas Rumpf 2020-06-21 19:58:37 +02:00 • committed by GitHub
commit 3ba0c30758
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -330,7 +330,7 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) =
sym.offset = accum.offset sym.offset = accum.offset
accum.inc(int(child.size)) accum.inc(int(child.size))
typ.paddingAtEnd = int16(accum.finish()) typ.paddingAtEnd = int16(accum.finish())
typ.size = accum.offset typ.size = if accum.offset == 0: 1 else: accum.offset
typ.align = int16(accum.maxAlign) typ.align = int16(accum.maxAlign)
except IllegalTypeRecursionError: except IllegalTypeRecursionError:
typ.paddingAtEnd = szIllegalRecursion typ.paddingAtEnd = szIllegalRecursion
@ -388,7 +388,7 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) =
typ.align = szUnknownSize typ.align = szUnknownSize
typ.paddingAtEnd = szUnknownSize typ.paddingAtEnd = szUnknownSize
else: else:
typ.size = accum.offset typ.size = if accum.offset == 0: 1 else: accum.offset
typ.align = int16(accum.maxAlign) typ.align = int16(accum.maxAlign)
typ.paddingAtEnd = paddingAtEnd typ.paddingAtEnd = paddingAtEnd
except IllegalTypeRecursionError: except IllegalTypeRecursionError:

View file

@ -686,3 +686,11 @@ reject:
reject: reject:
const off8 = offsetof(MyPackedCaseObject, val5) const off8 = offsetof(MyPackedCaseObject, val5)
type
O0 = object
T0 = tuple[]
doAssert sizeof(O0) == 1
doAssert sizeof(T0) == 1