This commit is contained in:
Araq 2018-12-05 16:16:58 +01:00
commit 1711a60f7b
3 changed files with 23 additions and 1 deletions

View file

@ -1975,6 +1975,22 @@ proc setMs(n: PNode, s: PSym): PNode =
n.sons[0] = newSymNode(s) n.sons[0] = newSymNode(s)
n.sons[0].info = n.info n.sons[0].info = n.info
proc semSizeof(c: PContext, n: PNode): PNode =
if sonsLen(n) != 2:
localError(c.config, n.info, errXExpectsTypeOrValue % "sizeof")
else:
n.sons[1] = semExprWithType(c, n.sons[1], {efDetermineType})
#restoreOldStyleType(n.sons[1])
n.typ = getSysType(c.graph, n.info, tyInt)
let size = getSize(c.config, n[1].typ)
if size >= 0:
result = newIntNode(nkIntLit, size)
result.info = n.info
result.typ = n.typ
else:
result = n
proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode = proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
# this is a hotspot in the compiler! # this is a hotspot in the compiler!
result = n result = n
@ -2060,6 +2076,7 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
result = setMs(n, s) result = setMs(n, s)
else: else:
result = c.graph.emptyNode result = c.graph.emptyNode
of mSizeOf: result = semSizeof(c, setMs(n, s))
of mOmpParFor: of mOmpParFor:
checkMinSonsLen(n, 3, c.config) checkMinSonsLen(n, 3, c.config)
result = semDirectOp(c, n, flags) result = semDirectOp(c, n, flags)

View file

@ -52,6 +52,7 @@ proc computeSubObjectAlign(conf: ConfigRef; n: PNode): BiggestInt =
proc computeObjectOffsetsFoldFunction(conf: ConfigRef; n: PNode, initialOffset: BiggestInt): tuple[offset, align: BiggestInt] = proc computeObjectOffsetsFoldFunction(conf: ConfigRef; n: PNode, initialOffset: BiggestInt): tuple[offset, align: BiggestInt] =
## ``offset`` is the offset within the object, after the node has been written, no padding bytes added ## ``offset`` is the offset within the object, after the node has been written, no padding bytes added
## ``align`` maximum alignment from all sub nodes ## ``align`` maximum alignment from all sub nodes
assert n != nil
if n.typ != nil and n.typ.size == szIllegalRecursion: if n.typ != nil and n.typ.size == szIllegalRecursion:
result.offset = szIllegalRecursion result.offset = szIllegalRecursion
result.align = szIllegalRecursion result.align = szIllegalRecursion
@ -177,7 +178,7 @@ proc computePackedObjectOffsetsFoldFunction(conf: ConfigRef; n: PNode, initialOf
proc computeSizeAlign(conf: ConfigRef; typ: PType) = proc computeSizeAlign(conf: ConfigRef; typ: PType) =
## computes and sets ``size`` and ``align`` members of ``typ`` ## computes and sets ``size`` and ``align`` members of ``typ``
assert typ != nil
let hasSize = typ.size != szUncomputedSize let hasSize = typ.size != szUncomputedSize
let hasAlign = typ.align != szUncomputedSize let hasAlign = typ.align != szUncomputedSize

View file

@ -9,3 +9,7 @@ type
const i = sizeof(MyStruct) const i = sizeof(MyStruct)
echo i echo i
# bug #9868
proc foo(a: SomeInteger): array[sizeof(a), byte] =
discard