diff options
author | Araq <rumpf_a@web.de> | 2013-12-03 01:59:38 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2013-12-03 01:59:38 +0100 |
commit | fe983b13099dd8d8a93ebefc00174e98eb048dea (patch) | |
tree | 2d437512f120011dd4be4215bcc9e37d7aa29ac6 /compiler/cgen.nim | |
parent | 5dcfa97fb959eda3cb8a41e2bd39e998c30052c8 (diff) | |
download | Nim-fe983b13099dd8d8a93ebefc00174e98eb048dea.tar.gz |
fixes a regression where memset was used without including <string.h>
Diffstat (limited to 'compiler/cgen.nim')
-rw-r--r-- | compiler/cgen.nim | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 910e675e1..24d3c2923 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -72,6 +72,11 @@ proc isSimpleConst(typ: PType): bool = {tyTuple, tyObject, tyArray, tyArrayConstr, tySet, tySequence} and not (t.kind == tyProc and t.callConv == ccClosure) +proc useStringh(m: BModule) = + if not m.includesStringh: + m.includesStringh = true + discard lists.IncludeStr(m.headerFiles, "<string.h>") + proc useHeader(m: BModule, sym: PSym) = if lfHeader in sym.loc.Flags: assert(sym.annex != nil) @@ -358,6 +363,7 @@ proc resetLoc(p: BProc, loc: var TLoc) = # field, so disabling this should be safe: genObjectInit(p, cpsStmts, loc.t, loc, true) else: + useStringh(p.module) linefmt(p, cpsStmts, "memset((void*)$1, 0, sizeof($2));$n", addrLoc(loc), rdLoc(loc)) # XXX: We can be extra clever here and call memset only @@ -368,6 +374,7 @@ proc constructLoc(p: BProc, loc: TLoc, section = cpsStmts) = if not isComplexValueType(skipTypes(loc.t, abstractRange)): linefmt(p, section, "$1 = 0;$n", rdLoc(loc)) else: + useStringh(p.module) linefmt(p, section, "memset((void*)$1, 0, sizeof($2));$n", addrLoc(loc), rdLoc(loc)) genObjectInit(p, section, loc.t, loc, true) @@ -418,6 +425,7 @@ proc keepAlive(p: BProc, toKeepAlive: TLoc) = if not isComplexValueType(skipTypes(toKeepAlive.t, abstractVarRange)): linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(result), rdLoc(toKeepAlive)) else: + useStringh(p.module) linefmt(p, cpsStmts, "memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n", addrLoc(result), addrLoc(toKeepAlive), rdLoc(result)) |