fixes #19051 [backport:1.6] (#19133)

This commit is contained in:
Andreas Rumpf 2021-11-12 11:19:24 +01:00 • committed by GitHub
commit c6fc3b2eae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View file

@ -196,6 +196,11 @@ proc computeUnionObjectOffsetsFoldFunction(conf: ConfigRef; n: PNode; packed: bo
accum.offset = szUnknownSize accum.offset = szUnknownSize
proc computeSizeAlign(conf: ConfigRef; typ: PType) = proc computeSizeAlign(conf: ConfigRef; typ: PType) =
template setSize(typ, s) =
typ.size = s
typ.align = s
typ.paddingAtEnd = 0
## computes and sets ``size`` and ``align`` members of ``typ`` ## computes and sets ``size`` and ``align`` members of ``typ``
assert typ != nil assert typ != nil
let hasSize = typ.size != szUncomputedSize let hasSize = typ.size != szUncomputedSize
@ -445,6 +450,16 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) =
typ.size = szUnknownSize typ.size = szUnknownSize
typ.align = szUnknownSize typ.align = szUnknownSize
typ.paddingAtEnd = szUnknownSize typ.paddingAtEnd = szUnknownSize
of tyInt, tyUInt:
setSize typ, conf.target.intSize.int16
of tyBool, tyChar, tyUInt8, tyInt8:
setSize typ, 1
of tyInt16, tyUInt16:
setSize typ, 2
of tyInt32, tyUInt32:
setSize typ, 4
of tyInt64, tyUInt64:
setSize typ, 8
else: else:
typ.size = szUnknownSize typ.size = szUnknownSize
typ.align = szUnknownSize typ.align = szUnknownSize

View file

@ -1,6 +1,7 @@
discard """ discard """
cmd: "nim c -d:release $file" cmd: "nim c -d:release $file"
output: 1 output: '''1
-1'''
""" """
proc bug() : void = proc bug() : void =
@ -12,3 +13,9 @@ proc bug() : void =
echo x echo x
bug() bug()
# bug #19051
type GInt[T] = int
var a = 1
echo -a