Skip to content

Commit 167881b

Browse files
Araqnarimiran
authored andcommitted
fixes #19051 [backport:1.6] (#19133)
(cherry picked from commit c6fc3b2)
1 parent 73366c0 commit 167881b

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

compiler/sizealignoffsetimpl.nim

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ proc computeUnionObjectOffsetsFoldFunction(conf: ConfigRef; n: PNode; packed: bo
196196
accum.offset = szUnknownSize
197197

198198
proc computeSizeAlign(conf: ConfigRef; typ: PType) =
199+
template setSize(typ, s) =
200+
typ.size = s
201+
typ.align = s
202+
typ.paddingAtEnd = 0
203+
199204
## computes and sets ``size`` and ``align`` members of ``typ``
200205
assert typ != nil
201206
let hasSize = typ.size != szUncomputedSize
@@ -258,14 +263,14 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) =
258263

259264
of tyArray:
260265
computeSizeAlign(conf, typ[1])
261-
let elemSize = typ[1].size
266+
let elemSize = typ[1].size
262267
let len = lengthOrd(conf, typ[0])
263268
if elemSize < 0:
264269
typ.size = elemSize
265270
typ.align = int16(elemSize)
266271
elif len < 0:
267272
typ.size = szUnknownSize
268-
typ.align = szUnknownSize
273+
typ.align = szUnknownSize
269274
else:
270275
typ.size = toInt64Checked(len * int32(elemSize), szTooBigSize)
271276
typ.align = typ[1].align
@@ -445,6 +450,16 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) =
445450
typ.size = szUnknownSize
446451
typ.align = szUnknownSize
447452
typ.paddingAtEnd = szUnknownSize
453+
of tyInt, tyUInt:
454+
setSize typ, conf.target.intSize.int16
455+
of tyBool, tyChar, tyUInt8, tyInt8:
456+
setSize typ, 1
457+
of tyInt16, tyUInt16:
458+
setSize typ, 2
459+
of tyInt32, tyUInt32:
460+
setSize typ, 4
461+
of tyInt64, tyUInt64:
462+
setSize typ, 8
448463
else:
449464
typ.size = szUnknownSize
450465
typ.align = szUnknownSize

tests/ccgbugs/t5296.nim

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
discard """
22
cmd: "nim c -d:release $file"
3-
output: 1
3+
output: '''1
4+
-1'''
45
"""
56

67
proc bug() : void =
@@ -12,3 +13,9 @@ proc bug() : void =
1213
echo x
1314

1415
bug()
16+
17+
# bug #19051
18+
type GInt[T] = int
19+
20+
var a = 1
21+
echo -a

0 commit comments

Comments
 (0)