Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #13122 #13126

Merged
merged 2 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ type
of skLet, skVar, skField, skForVar:
guard*: PSym
bitsize*: int
alignment*: int # for alignas(X) expressions
alignment*: int # for alignment
else: nil
magic*: TMagic
typ*: PType
Expand Down Expand Up @@ -1398,6 +1398,8 @@ proc copySym*(s: PSym): PSym =
result.annex = s.annex # BUGFIX
if result.kind in {skVar, skLet, skField}:
result.guard = s.guard
result.bitsize = s.bitsize
result.alignment = s.alignment

proc createModuleAlias*(s: PSym, newIdent: PIdent, info: TLineInfo;
options: TOptions): PSym =
Expand Down
6 changes: 2 additions & 4 deletions compiler/pragmas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -819,12 +819,10 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
localError(c.config, it.info, "size may only be 1, 2, 4 or 8")
of wAlign:
let alignment = expectIntLit(c, it)
if alignment == 0:
discard
elif isPowerOfTwo(alignment):
if isPowerOfTwo(alignment) and alignment > 0:
sym.alignment = max(sym.alignment, alignment)
else:
localError(c.config, it.info, "power of two or 0 expected")
localError(c.config, it.info, "power of two expected")
of wNodecl:
noVal(c, it)
incl(sym.loc.flags, lfNoDecl)
Expand Down
File renamed without changes.
15 changes: 12 additions & 3 deletions tests/misc/talignas.nim → tests/align/talign.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ proc foobar() =
doAssert (cast[uint](addr(toplevel3)) and 31) == 0

# test multiple align expressions
var mylocal1 {.align(0), align(128), align(32).}: int = 123
var mylocal2 {.align(128), align(0), align(32).}: int = 123
var mylocal3 {.align(0), align(32), align(128).}: int = 123
var mylocal1 {.align(128), align(32).}: int = 123
var mylocal2 {.align(128), align(32).}: int = 123
var mylocal3 {.align(32), align(128).}: int = 123

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

foobar()

# bug #13122

type Bug[T] = object
bug{.align:64.}: T
sideffect{.align:64.}: int

var bug: Bug[int]
doAssert sizeof(bug) == 128, "Oops my size is " & $sizeof(bug) # 16
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
discard """
cmd: "nim check $options $file"
errormsg: "power of two or 0 expected"
errormsg: "power of two expected"
"""

proc foobar() =
Expand Down