mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-23 07:45:23 +00:00
fixes #22553 follow up https://github.com/nim-lang/Nim/pull/21979 which introduced a char dummy member prepended to objs only containing an UncheckedArray
This commit is contained in:
@@ -385,6 +385,13 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) =
|
||||
accum.maxAlign = 1
|
||||
computeObjectOffsetsFoldFunction(conf, typ.n, true, accum)
|
||||
else:
|
||||
if typ.baseClass == nil and lacksMTypeField(typ) and typ.n.len == 1 and
|
||||
typ.n[0].kind == nkSym and
|
||||
typ.n[0].sym.typ.skipTypes(abstractInst).kind == tyUncheckedArray:
|
||||
# a dummy field is generated for an object with a single field
|
||||
# with an UncheckedArray type
|
||||
assert accum.offset == 0
|
||||
accum.offset = 1
|
||||
computeObjectOffsetsFoldFunction(conf, typ.n, false, accum)
|
||||
let paddingAtEnd = int16(accum.finish())
|
||||
if typ.sym != nil and
|
||||
|
||||
@@ -1406,6 +1406,8 @@ proc commonSuperclass*(a, b: PType): PType =
|
||||
return t
|
||||
y = y.baseClass
|
||||
|
||||
proc lacksMTypeField*(typ: PType): bool {.inline.} =
|
||||
(typ.sym != nil and sfPure in typ.sym.flags) or tfFinal in typ.flags
|
||||
|
||||
include sizealignoffsetimpl
|
||||
|
||||
@@ -1854,6 +1856,3 @@ proc isCharArrayPtr*(t: PType; allowPointerToChar: bool): bool =
|
||||
result = false
|
||||
else:
|
||||
result = false
|
||||
|
||||
proc lacksMTypeField*(typ: PType): bool {.inline.} =
|
||||
(typ.sym != nil and sfPure in typ.sym.flags) or tfFinal in typ.flags
|
||||
|
||||
@@ -732,3 +732,11 @@ type
|
||||
|
||||
doAssert sizeof(PackedUnion) == 11
|
||||
doAssert alignof(PackedUnion) == 1
|
||||
|
||||
# bug #22553
|
||||
type
|
||||
ChunkObj = object
|
||||
data: UncheckedArray[byte]
|
||||
|
||||
doAssert sizeof(ChunkObj) == 1
|
||||
doAssert offsetOf(ChunkObj, data) == 1
|
||||
|
||||
Reference in New Issue
Block a user