diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 1c4bbd885d176..479c701487a98 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -254,11 +254,11 @@ proc genGenericAsgn(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = if (dest.storage == OnStack and p.config.selectedGC != gcGo) or not usesWriteBarrier(p.config): let rad = addrLoc(p.config, dest) let ras = addrLoc(p.config, src) - let rd = rdLoc(dest) + let td = getTypeDesc(p.module, dest.t) p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "nimCopyMem"), cCast("void*", rad), cCast(ptrConstType("void"), ras), - cSizeof(rd)) + cSizeof(td)) else: let rad = addrLoc(p.config, dest) let ras = addrLoc(p.config, src) @@ -2549,7 +2549,7 @@ proc genCast(p: BProc, e: PNode, d: var TLoc) = p.s(cpsLocals).addField(name = "source", typ = srcTyp) p.s(cpsLocals).addCallStmt(cgsymValue(p.module, "nimZeroMem"), cAddr("LOC" & lbl), - cSizeof("LOC" & lbl)) + cIntValue(destsize)) else: p.s(cpsLocals).addVarWithType(kind = Local, name = "LOC" & lbl): p.s(cpsLocals).addUnionType(): @@ -3051,7 +3051,8 @@ proc genSetConstr(p: BProc, e: PNode, d: var TLoc) = putIntoDest(p, d, e, extract(elem)) else: if d.k == locNone: d = getTemp(p, e.typ) - if getSize(p.config, e.typ) > 8: + let size = getSize(p.config, e.typ) + if size > 8: # big set: p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "nimZeroMem"), rdLoc(d), @@ -3099,7 +3100,7 @@ proc genSetConstr(p: BProc, e: PNode, d: var TLoc) = p.s(cpsStmts).addForRangeInclusive(ri, aa, bb): p.s(cpsStmts).addInPlaceOp(BitOr, ts, rd, cOp(Shl, ts, cCast(ts, cIntValue(1)), - cOp(Mod, ts, ri, cOp(Mul, ts, cSizeof(ts), cIntValue(8))))) + cOp(Mod, ts, ri, cOp(Mul, ts, cIntValue(size), cIntValue(8))))) else: a = initLocExpr(p, it) var aa: Snippet = "" @@ -3107,7 +3108,7 @@ proc genSetConstr(p: BProc, e: PNode, d: var TLoc) = let rd = rdLoc(d) p.s(cpsStmts).addInPlaceOp(BitOr, ts, rd, cOp(Shl, ts, cCast(ts, cIntValue(1)), - cOp(Mod, ts, aa, cOp(Mul, ts, cSizeof(ts), cIntValue(8))))) + cOp(Mod, ts, aa, cOp(Mul, ts, cIntValue(size), cIntValue(8))))) proc genTupleConstr(p: BProc, n: PNode, d: var TLoc) = var rec: TLoc diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 5512ed01c8f1c..f5c9c79dc0989 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -161,13 +161,13 @@ proc genVarTuple(p: BProc, n: PNode) = typ = "NIM_BOOL", initializer = "NIM_FALSE") for curr in hcrGlobals: - let rc = rdLoc(curr.loc) + let tc = getTypeDesc(p.module, curr.loc.t) p.s(cpsLocals).addInPlaceOp(BitOr, "NIM_BOOL", hcrCond, cCall("hcrRegisterGlobal", getModuleDllPath(p.module, n[0].sym), '"' & curr.loc.snippet & '"', - cSizeof(rc), + cSizeof(tc), curr.tp, cCast("void**", cAddr(curr.loc.snippet)))) @@ -434,11 +434,11 @@ proc genSingleVar(p: BProc, v: PSym; vn, value: PNode) = if forHcr and targetProc.blocks.len > 3 and v.owner.kind == skModule: # put it in the locals section - mainly because of loops which # use the var in a call to resetLoc() in the statements section - let rv = rdLoc(v.loc) + let tv = getTypeDesc(p.module, v.loc.t) p.s(cpsLocals).addCallStmt("hcrRegisterGlobal", getModuleDllPath(p.module, v), '"' & v.loc.snippet & '"', - cSizeof(rv), + cSizeof(tv), traverseProc, cCast("void**", cAddr(v.loc.snippet))) # nothing special left to do later on - let's avoid closing and reopening blocks @@ -449,12 +449,13 @@ proc genSingleVar(p: BProc, v: PSym; vn, value: PNode) = # be able to re-run it but without the top level code - just the init of globals var hcrInit = default(IfBuilder) if forHcr: + let tv = getTypeDesc(p.module, v.loc.t) startBlockWith(targetProc): hcrInit = initIfStmt(p.s(cpsStmts)) initElifBranch(p.s(cpsStmts), hcrInit, cCall("hcrRegisterGlobal", getModuleDllPath(p.module, v), '"' & v.loc.snippet & '"', - cSizeof(rdLoc(v.loc)), + cSizeof(tv), traverseProc, cCast("void**", cAddr(v.loc.snippet)))) if value.kind != nkEmpty and valueAsRope.len == 0: diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 4b7d2e14344a9..43c76be671edb 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -1984,18 +1984,20 @@ proc registerModuleToMain(g: BModuleList; m: BModule) = # bug #16265. let osModulePath = ($systemModulePath).replace("stdlib_system", "stdlib_os").rope g.mainDatInit.addCallStmt("hcrAddModule", osModulePath) - g.mainDatInit.addVar(name = "cmd_count", typ = ptrType("int")) - g.mainDatInit.addVar(name = "cmd_line", typ = ptrType(ptrType(ptrType("char")))) + let cmdCountTyp = ptrType("int") + let cmdLineTyp = ptrType(ptrType(ptrType("char"))) + g.mainDatInit.addVar(name = "cmd_count", typ = cmdCountTyp) + g.mainDatInit.addVar(name = "cmd_line", typ = cmdLineTyp) g.mainDatInit.addCallStmt("hcrRegisterGlobal", osModulePath, "\"cmdCount\"", - cSizeof("cmd_count"), + cSizeof(cmdCountTyp), "NULL", cCast("void**", cAddr("cmd_count"))) g.mainDatInit.addCallStmt("hcrRegisterGlobal", osModulePath, "\"cmdLine\"", - cSizeof("cmd_line"), + cSizeof(cmdLineTyp), "NULL", cCast("void**", cAddr("cmd_line"))) g.mainDatInit.addAssignment(cDeref("cmd_count"), "cmdCount")