implement sizeof and alignof operator (manually squashed #5664) (#9356)

This commit is contained in:
Timothee Cour 2018-10-13 15:52:28 -07:00 • committed by Andreas Rumpf
commit 745f1642d6
18 changed files with 906 additions and 236 deletions

View file

@ -803,9 +803,11 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
if sym.typ == nil: invalidPragma(c, it)
var size = expectIntLit(c, it)
if not isPowerOfTwo(size) or size <= 0 or size > 8:
localError(c.config, it.info, "power of two expected")
localError(c.config, it.info, "size may only be 1, 2, 4 or 8")
else:
sym.typ.size = size
# TODO, this is not correct
sym.typ.align = int16(size)
of wNodecl:
noVal(c, it)
incl(sym.loc.flags, lfNoDecl)