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

make all sizeof calls in codegen use types #24433

Draft
wants to merge 1 commit into
base: devel
Choose a base branch
from
Draft
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
6 changes: 3 additions & 3 deletions compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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(CPointer, rad),
cCast(CConstPointer, ras),
cSizeof(rd))
cSizeof(td))
else:
let rad = addrLoc(p.config, dest)
let ras = addrLoc(p.config, src)
Expand Down Expand Up @@ -2553,7 +2553,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():
Expand Down
11 changes: 6 additions & 5 deletions compiler/ccgstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ proc genVarTuple(p: BProc, n: PNode) =
typ = NimBool,
initializer = NimFalse)
for curr in hcrGlobals:
let rc = rdLoc(curr.loc)
let tc = getTypeDesc(p.module, curr.loc.t)
p.s(cpsLocals).addInPlaceOp(BitOr, NimBool,
hcrCond,
cCall("hcrRegisterGlobal",
getModuleDllPath(p.module, n[0].sym),
'"' & curr.loc.snippet & '"',
cSizeof(rc),
cSizeof(tc),
curr.tp,
cCast(ptrType(CPointer), cAddr(curr.loc.snippet))))

Expand Down Expand Up @@ -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(ptrType(CPointer), cAddr(v.loc.snippet)))
# nothing special left to do later on - let's avoid closing and reopening blocks
Expand All @@ -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(ptrType(CPointer), cAddr(v.loc.snippet))))
if value.kind != nkEmpty and valueAsRope.len == 0:
Expand Down