Skip to content

Commit abea803

Browse files
authored
fixes #13122 (#13126)
* fixes #13122 * moved tests to where they belong
1 parent bf2e052 commit abea803

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

compiler/ast.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ type
826826
of skLet, skVar, skField, skForVar:
827827
guard*: PSym
828828
bitsize*: int
829-
alignment*: int # for alignas(X) expressions
829+
alignment*: int # for alignment
830830
else: nil
831831
magic*: TMagic
832832
typ*: PType
@@ -1398,6 +1398,8 @@ proc copySym*(s: PSym): PSym =
13981398
result.annex = s.annex # BUGFIX
13991399
if result.kind in {skVar, skLet, skField}:
14001400
result.guard = s.guard
1401+
result.bitsize = s.bitsize
1402+
result.alignment = s.alignment
14011403

14021404
proc createModuleAlias*(s: PSym, newIdent: PIdent, info: TLineInfo;
14031405
options: TOptions): PSym =

compiler/pragmas.nim

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,12 +819,10 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
819819
localError(c.config, it.info, "size may only be 1, 2, 4 or 8")
820820
of wAlign:
821821
let alignment = expectIntLit(c, it)
822-
if alignment == 0:
823-
discard
824-
elif isPowerOfTwo(alignment):
822+
if isPowerOfTwo(alignment) and alignment > 0:
825823
sym.alignment = max(sym.alignment, alignment)
826824
else:
827-
localError(c.config, it.info, "power of two or 0 expected")
825+
localError(c.config, it.info, "power of two expected")
828826
of wNodecl:
829827
noVal(c, it)
830828
incl(sym.loc.flags, lfNoDecl)
File renamed without changes.

tests/misc/talignas.nim renamed to tests/align/talign.nim

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ proc foobar() =
3131
doAssert (cast[uint](addr(toplevel3)) and 31) == 0
3232

3333
# test multiple align expressions
34-
var mylocal1 {.align(0), align(128), align(32).}: int = 123
35-
var mylocal2 {.align(128), align(0), align(32).}: int = 123
36-
var mylocal3 {.align(0), align(32), align(128).}: int = 123
34+
var mylocal1 {.align(128), align(32).}: int = 123
35+
var mylocal2 {.align(128), align(32).}: int = 123
36+
var mylocal3 {.align(32), align(128).}: int = 123
3737

3838
doAssert (cast[uint](addr(mylocal1)) and 127) == 0
3939
doAssert (cast[uint](addr(mylocal2)) and 127) == 0
@@ -42,3 +42,12 @@ proc foobar() =
4242
echo "align ok"
4343

4444
foobar()
45+
46+
# bug #13122
47+
48+
type Bug[T] = object
49+
bug{.align:64.}: T
50+
sideffect{.align:64.}: int
51+
52+
var bug: Bug[int]
53+
doAssert sizeof(bug) == 128, "Oops my size is " & $sizeof(bug) # 16

tests/misc/tillegalalignas.nim renamed to tests/align/tillegalalign.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
discard """
22
cmd: "nim check $options $file"
3-
errormsg: "power of two or 0 expected"
3+
errormsg: "power of two expected"
44
"""
55

66
proc foobar() =

0 commit comments

Comments
 (0)