don't generate memset calls for C++ objects
This commit is contained in:
parent
ca22dfcdc2
commit
1fc590b6ea
5 changed files with 448 additions and 440 deletions
|
|
@ -956,6 +956,9 @@ proc genAsmStmt(p: BProc, t: PNode) =
|
|||
assert(t.kind == nkAsmStmt)
|
||||
genLineDir(p, t)
|
||||
var s = genAsmOrEmitStmt(p, t, isAsmStmt=true)
|
||||
# see bug #2362, "top level asm statements" seem to be a mis-feature
|
||||
# but even if we don't do this, the example in #2362 cannot possibly
|
||||
# work:
|
||||
if p.prc == nil:
|
||||
# top level asm statement?
|
||||
appf(p.module.s[cfsProcHeaders], CC[cCompiler].asmStmtFrmt, [s])
|
||||
|
|
|
|||
|
|
@ -261,7 +261,9 @@ proc isComplexValueType(t: PType): bool {.inline.} =
|
|||
|
||||
proc resetLoc(p: BProc, loc: var TLoc) =
|
||||
let containsGcRef = containsGarbageCollectedRef(loc.t)
|
||||
if not isComplexValueType(skipTypes(loc.t, abstractVarRange)):
|
||||
let typ = skipTypes(loc.t, abstractVarRange)
|
||||
if isImportedCppType(typ): return
|
||||
if not isComplexValueType(typ):
|
||||
if containsGcRef:
|
||||
var nilLoc: TLoc
|
||||
initLoc(nilLoc, locTemp, loc.t, OnStack)
|
||||
|
|
@ -287,15 +289,17 @@ proc resetLoc(p: BProc, loc: var TLoc) =
|
|||
genObjectInit(p, cpsStmts, loc.t, loc, true)
|
||||
|
||||
proc constructLoc(p: BProc, loc: TLoc, isTemp = false) =
|
||||
if not isComplexValueType(skipTypes(loc.t, abstractRange)):
|
||||
let typ = skipTypes(loc.t, abstractRange)
|
||||
if not isComplexValueType(typ):
|
||||
linefmt(p, cpsStmts, "$1 = 0;$n", rdLoc(loc))
|
||||
else:
|
||||
if not isTemp or containsGarbageCollectedRef(loc.t):
|
||||
# don't use memset for temporary values for performance if we can
|
||||
# avoid it:
|
||||
useStringh(p.module)
|
||||
linefmt(p, cpsStmts, "memset((void*)$1, 0, sizeof($2));$n",
|
||||
addrLoc(loc), rdLoc(loc))
|
||||
if not isImportedCppType(typ):
|
||||
useStringh(p.module)
|
||||
linefmt(p, cpsStmts, "memset((void*)$1, 0, sizeof($2));$n",
|
||||
addrLoc(loc), rdLoc(loc))
|
||||
genObjectInit(p, cpsStmts, loc.t, loc, true)
|
||||
|
||||
proc initLocalVar(p: BProc, v: PSym, immediateAsgn: bool) =
|
||||
|
|
|
|||
|
|
@ -87,14 +87,14 @@ proc searchInScopes*(c: PContext, s: PIdent): PSym =
|
|||
if result != nil: return
|
||||
result = nil
|
||||
|
||||
proc debugScopes*(c: PContext) {.deprecated.} =
|
||||
proc debugScopes*(c: PContext; limit=0) {.deprecated.} =
|
||||
var i = 0
|
||||
for scope in walkScopes(c.currentScope):
|
||||
echo "scope ", i
|
||||
for h in 0 .. high(scope.symbols.data):
|
||||
if scope.symbols.data[h] != nil:
|
||||
echo scope.symbols.data[h].name.s
|
||||
if i == 2: break
|
||||
if i == limit: break
|
||||
inc i
|
||||
|
||||
proc searchInScopes*(c: PContext, s: PIdent, filter: TSymKinds): PSym =
|
||||
|
|
|
|||
1
todo.txt
1
todo.txt
|
|
@ -5,6 +5,7 @@ version 0.10.4
|
|||
- make 'nil' work for 'add' and 'len'
|
||||
- disallow negative indexing
|
||||
- improve the parser; deal with echo $foo gotcha
|
||||
- add "all threads are blocked" detection to 'spawn'
|
||||
|
||||
|
||||
version 1.0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue