* fixes #13122

* moved tests to where they belong
This commit is contained in:
Andreas Rumpf 2020-01-13 14:11:51 +01:00 • committed by GitHub
commit abea80376a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 9 deletions

View file

@ -826,7 +826,7 @@ type
of skLet, skVar, skField, skForVar: of skLet, skVar, skField, skForVar:
guard*: PSym guard*: PSym
bitsize*: int bitsize*: int
alignment*: int # for alignas(X) expressions alignment*: int # for alignment
else: nil else: nil
magic*: TMagic magic*: TMagic
typ*: PType typ*: PType
@ -1398,6 +1398,8 @@ proc copySym*(s: PSym): PSym =
result.annex = s.annex # BUGFIX result.annex = s.annex # BUGFIX
if result.kind in {skVar, skLet, skField}: if result.kind in {skVar, skLet, skField}:
result.guard = s.guard result.guard = s.guard
result.bitsize = s.bitsize
result.alignment = s.alignment
proc createModuleAlias*(s: PSym, newIdent: PIdent, info: TLineInfo; proc createModuleAlias*(s: PSym, newIdent: PIdent, info: TLineInfo;
options: TOptions): PSym = options: TOptions): PSym =

View file

@ -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") localError(c.config, it.info, "size may only be 1, 2, 4 or 8")
of wAlign: of wAlign:
let alignment = expectIntLit(c, it) let alignment = expectIntLit(c, it)
if alignment == 0: if isPowerOfTwo(alignment) and alignment > 0:
discard
elif isPowerOfTwo(alignment):
sym.alignment = max(sym.alignment, alignment) sym.alignment = max(sym.alignment, alignment)
else: else:
localError(c.config, it.info, "power of two or 0 expected") localError(c.config, it.info, "power of two expected")
of wNodecl: of wNodecl:
noVal(c, it) noVal(c, it)
incl(sym.loc.flags, lfNoDecl) incl(sym.loc.flags, lfNoDecl)

View file

@ -31,9 +31,9 @@ proc foobar() =
doAssert (cast[uint](addr(toplevel3)) and 31) == 0 doAssert (cast[uint](addr(toplevel3)) and 31) == 0
# test multiple align expressions # test multiple align expressions
var mylocal1 {.align(0), align(128), align(32).}: int = 123 var mylocal1 {.align(128), align(32).}: int = 123
var mylocal2 {.align(128), align(0), align(32).}: int = 123 var mylocal2 {.align(128), align(32).}: int = 123
var mylocal3 {.align(0), align(32), align(128).}: int = 123 var mylocal3 {.align(32), align(128).}: int = 123
doAssert (cast[uint](addr(mylocal1)) and 127) == 0 doAssert (cast[uint](addr(mylocal1)) and 127) == 0
doAssert (cast[uint](addr(mylocal2)) and 127) == 0 doAssert (cast[uint](addr(mylocal2)) and 127) == 0
@ -42,3 +42,12 @@ proc foobar() =
echo "align ok" echo "align ok"
foobar() 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

View file

@ -1,6 +1,6 @@
discard """ discard """
cmd: "nim check $options $file" cmd: "nim check $options $file"
errormsg: "power of two or 0 expected" errormsg: "power of two expected"
""" """
proc foobar() = proc foobar() =