32 bit fixes (#10608)

This commit is contained in:
Arne Döring 2019-02-12 22:00:31 +01:00 • committed by Andreas Rumpf
commit 6870345cd2
26 changed files with 165 additions and 135 deletions

View file

@ -271,6 +271,10 @@ type
# language; for interfacing with Objective C
sfDiscardable, # returned value may be discarded implicitly
sfOverriden, # proc is overriden
sfCallSideLineinfo# A flag for template symbols to tell the
# compiler it should use line information from
# the calling side of the macro, not from the
# implementation.
sfGenSym # symbol is 'gensym'ed; do not add to symbol table
TSymFlags* = set[TSymFlag]
@ -1265,7 +1269,10 @@ proc `$`*(x: TLockLevel): string =
else: result = $int16(x)
proc `$`*(s: PSym): string =
result = s.name.s & "@" & $s.id
if s != nil:
result = s.name.s & "@" & $s.id
else:
result = "<nil>"
proc newType*(kind: TTypeKind, owner: PSym): PType =
new(result)

View file

@ -1997,6 +1997,11 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
of mSizeOf:
let t = e.sons[1].typ.skipTypes({tyTypeDesc})
putIntoDest(p, d, e, "((NI)sizeof($1))" % [getTypeDesc(p.module, t)])
of mAlignOf:
let t = e.sons[1].typ.skipTypes({tyTypeDesc})
if not p.module.compileToCpp:
p.module.includeHeader("<stdalign.h>")
putIntoDest(p, d, e, "((NI)alignof($1))" % [getTypeDesc(p.module, t)])
of mChr: genSomeCast(p, e, d)
of mOrd: genOrd(p, e, d)
of mLengthArray, mHigh, mLengthStr, mLengthSeq, mLengthOpenArray:

View file

@ -186,9 +186,9 @@ proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym;
renderTree(result, {renderNoComments}))
else:
result = copyNode(body)
#ctx.instLines = body.kind notin {nkStmtList, nkStmtListExpr,
# nkBlockStmt, nkBlockExpr}
#if ctx.instLines: result.info = n.info
ctx.instLines = sfCallSideLineinfo in tmpl.flags
if ctx.instLines:
result.info = n.info
for i in countup(0, safeLen(body) - 1):
evalTemplateAux(body.sons[i], args, ctx, result)
result.flags.incl nfFromTemplate
@ -196,4 +196,3 @@ proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym;
#if ctx.debugActive:
# echo "instantion of ", renderTree(result, {renderIds})
dec(conf.evalTemplateCounter)

View file

@ -803,12 +803,15 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
of wSize:
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, "size may only be 1, 2, 4 or 8")
else:
case size
of 1, 2, 4, 8:
sym.typ.size = size
# TODO, this is not correct
sym.typ.align = int16(size)
if size == 8 and c.config.target.targetCPU == cpuI386:
sym.typ.align = 4
else:
sym.typ.align = int16(size)
else:
localError(c.config, it.info, "size may only be 1, 2, 4 or 8")
of wNodecl:
noVal(c, it)
incl(sym.loc.flags, lfNoDecl)

View file

@ -353,9 +353,17 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode,
localError(c.config, n.info, "cannot evaluate 'sizeof' because its type is not defined completely, type: " & n[1].typ.typeToString)
result = n
of mAlignOf:
result = newIntNode(nkIntLit, getAlign(c.config, n[1].typ))
result.info = n.info
result.typ = n.typ
# this is 100% analog to mSizeOf, could be made more dry.
let align = getAlign(c.config, n[1].typ)
if align == szUnknownSize:
result = n
elif align >= 0:
result = newIntNode(nkIntLit, align)
result.info = n.info
result.typ = n.typ
else:
localError(c.config, n.info, "cannot evaluate 'alignof' because its type is not defined completely, type: " & n[1].typ.typeToString)
result = n
of mOffsetOf:
var dotExpr: PNode

View file

@ -558,6 +558,10 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
incl(s.flags, sfGlobal)
else:
s = semIdentVis(c, skTemplate, n.sons[0], {})
if s.owner != nil and s.owner.name.s == "system" and s.name.s in ["!=", ">=", ">", "incl", "excl", "in", "notin", "isnot"]:
incl(s.flags, sfCallSideLineinfo)
styleCheckDef(c.config, s)
onDef(n[0].info, s)
# check parameter list:

View file

@ -495,7 +495,7 @@ proc suggestSym*(conf: ConfigRef; info: TLineInfo; s: PSym; usageSym: var PSym;
proc extractPragma(s: PSym): PNode =
if s.kind in routineKinds:
result = s.ast[pragmasPos]
elif s.kind in {skType, skVar, skLet}:
elif s.kind in {skType, skVar, skLet} and s.ast[0].kind == nkPragmaExpr:
# s.ast = nkTypedef / nkPragmaExpr / [nkSym, nkPragma]
result = s.ast[0][1]
doAssert result == nil or result.kind == nkPragma