bugfix: s[1..n] = @[] produced wrong C code
This commit is contained in:
parent
395b05f911
commit
bec06a0649
4 changed files with 33 additions and 15 deletions
|
|
@ -1213,7 +1213,8 @@ proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
|
|||
InitLocExpr(p, e.sons[1], a)
|
||||
InitLocExpr(p, e.sons[2], b)
|
||||
var t = skipTypes(e.sons[1].typ, abstractVar)
|
||||
appcg(p, cpsStmts, "$1 = ($3) #setLengthSeq(&($1)->Sup, sizeof($4), $2);$n", [
|
||||
appcg(p, cpsStmts,
|
||||
"$1 = ($3) #setLengthSeq(&($1)->Sup, sizeof($4), $2);$n", [
|
||||
rdLoc(a), rdLoc(b), getTypeDesc(p.module, t),
|
||||
getTypeDesc(p.module, t.sons[0])])
|
||||
|
||||
|
|
@ -1316,7 +1317,7 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
|||
of mIncl:
|
||||
var ts = "NI" & $(size * 8)
|
||||
binaryStmtInExcl(p, e, d,
|
||||
"$1 |=(1<<((" & ts & ")($2)%(sizeof(" & ts & ")*8)));$n")
|
||||
"$1 |=(1<<((" & ts & ")($2)%(sizeof(" & ts & ")*8)));$n")
|
||||
of mExcl:
|
||||
var ts = "NI" & $(size * 8)
|
||||
binaryStmtInExcl(p, e, d, "$1 &= ~(1 << ((" & ts & ")($2) % (sizeof(" &
|
||||
|
|
@ -1375,10 +1376,10 @@ proc genCast(p: BProc, e: PNode, d: var TLoc) =
|
|||
if (skipTypes(e.typ, abstractRange).kind in ValueTypes) and
|
||||
not (lfIndirect in a.flags):
|
||||
putIntoDest(p, d, e.typ, ropef("(*($1*) ($2))",
|
||||
[getTypeDesc(p.module, e.typ), addrLoc(a)]))
|
||||
[getTypeDesc(p.module, e.typ), addrLoc(a)]))
|
||||
else:
|
||||
putIntoDest(p, d, e.typ, ropef("(($1) ($2))",
|
||||
[getTypeDesc(p.module, e.typ), rdCharLoc(a)]))
|
||||
[getTypeDesc(p.module, e.typ), rdCharLoc(a)]))
|
||||
|
||||
proc genRangeChck(p: BProc, n: PNode, d: var TLoc, magic: string) =
|
||||
var a: TLoc
|
||||
|
|
@ -1386,7 +1387,7 @@ proc genRangeChck(p: BProc, n: PNode, d: var TLoc, magic: string) =
|
|||
if optRangeCheck notin p.options:
|
||||
InitLocExpr(p, n.sons[0], a)
|
||||
putIntoDest(p, d, n.typ, ropef("(($1) ($2))",
|
||||
[getTypeDesc(p.module, dest), rdCharLoc(a)]))
|
||||
[getTypeDesc(p.module, dest), rdCharLoc(a)]))
|
||||
else:
|
||||
InitLocExpr(p, n.sons[0], a)
|
||||
putIntoDest(p, d, dest, ropecg(p.module, "(($1)#$5($2, $3, $4))", [
|
||||
|
|
@ -1403,7 +1404,8 @@ proc genConv(p: BProc, e: PNode, d: var TLoc) =
|
|||
proc convStrToCStr(p: BProc, n: PNode, d: var TLoc) =
|
||||
var a: TLoc
|
||||
initLocExpr(p, n.sons[0], a)
|
||||
putIntoDest(p, d, skipTypes(n.typ, abstractVar), ropef("$1->data", [rdLoc(a)]))
|
||||
putIntoDest(p, d, skipTypes(n.typ, abstractVar), ropef("$1->data",
|
||||
[rdLoc(a)]))
|
||||
|
||||
proc convCStrToStr(p: BProc, n: PNode, d: var TLoc) =
|
||||
var a: TLoc
|
||||
|
|
|
|||
|
|
@ -318,16 +318,25 @@ proc fixAbstractType(c: PContext, n: PNode) =
|
|||
for i in countup(1, sonsLen(n) - 1):
|
||||
var it = n.sons[i]
|
||||
case it.kind
|
||||
of nkHiddenStdConv, nkHiddenSubConv:
|
||||
if it.sons[1].kind == nkBracket:
|
||||
of nkHiddenStdConv, nkHiddenSubConv:
|
||||
if it.sons[1].kind == nkBracket:
|
||||
it.sons[1] = semArrayConstr(c, it.sons[1])
|
||||
if skipTypes(it.typ, abstractVar).kind == tyOpenArray:
|
||||
#if n.sons[0].kind == nkSym and IdentEq(n.sons[0].sym.name, "[]="):
|
||||
# debug(n)
|
||||
|
||||
var s = skipTypes(it.sons[1].typ, abstractVar)
|
||||
if (s.kind == tyArrayConstr) and (s.sons[1].kind == tyEmpty):
|
||||
if s.kind == tyArrayConstr and s.sons[1].kind == tyEmpty:
|
||||
s = copyType(s, getCurrOwner(), false)
|
||||
skipTypes(s, abstractVar).sons[1] = elemType(
|
||||
skipTypes(it.typ, abstractVar))
|
||||
it.sons[1].typ = s
|
||||
elif s.kind == tySequence and s.sons[0].kind == tyEmpty:
|
||||
s = copyType(s, getCurrOwner(), false)
|
||||
skipTypes(s, abstractVar).sons[0] = elemType(
|
||||
skipTypes(it.typ, abstractVar))
|
||||
it.sons[1].typ = s
|
||||
|
||||
elif skipTypes(it.sons[1].typ, abstractVar).kind in
|
||||
{tyNil, tyArrayConstr, tyTuple, tySet}:
|
||||
var s = skipTypes(it.typ, abstractVar)
|
||||
|
|
@ -338,7 +347,7 @@ proc fixAbstractType(c: PContext, n: PNode) =
|
|||
n.sons[i] = semArrayConstr(c, it)
|
||||
else:
|
||||
if (it.typ == nil):
|
||||
InternalError(it.info, "fixAbstractType: " & renderTree(it))
|
||||
InternalError(it.info, "fixAbstractType: " & renderTree(it))
|
||||
|
||||
proc skipObjConv(n: PNode): PNode =
|
||||
case n.kind
|
||||
|
|
|
|||
|
|
@ -504,19 +504,19 @@ proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, a: PType,
|
|||
result = copyTree(arg)
|
||||
result.typ = getInstantiatedType(c, arg, m, f)
|
||||
# BUG: f may not be the right key!
|
||||
if (skipTypes(result.typ, abstractVar).kind in {tyTuple}):
|
||||
if skipTypes(result.typ, abstractVar).kind in {tyTuple}:
|
||||
result = implicitConv(nkHiddenStdConv, f, copyTree(arg), m, c)
|
||||
# BUGFIX: use ``result.typ`` and not `f` here
|
||||
of isEqual:
|
||||
inc(m.exactMatches)
|
||||
result = copyTree(arg)
|
||||
if (skipTypes(f, abstractVar).kind in {tyTuple}):
|
||||
if skipTypes(f, abstractVar).kind in {tyTuple}:
|
||||
result = implicitConv(nkHiddenStdConv, f, copyTree(arg), m, c)
|
||||
of isNone:
|
||||
result = userConvMatch(c, m, f, a, arg)
|
||||
# check for a base type match, which supports openarray[T] without []
|
||||
# constructor in a call:
|
||||
if (result == nil) and (f.kind == tyOpenArray):
|
||||
if result == nil and f.kind == tyOpenArray:
|
||||
r = typeRel(m.bindings, base(f), a)
|
||||
if r >= isGeneric:
|
||||
inc(m.convMatches)
|
||||
|
|
@ -525,7 +525,7 @@ proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, a: PType,
|
|||
m.baseTypeMatch = true
|
||||
else:
|
||||
result = userConvMatch(c, m, base(f), a, arg)
|
||||
|
||||
|
||||
proc ParamTypesMatch(c: PContext, m: var TCandidate, f, a: PType,
|
||||
arg: PNode): PNode =
|
||||
if arg == nil or arg.kind != nkSymChoice:
|
||||
|
|
@ -711,3 +711,11 @@ proc matches*(c: PContext, n: PNode, m: var TCandidate) =
|
|||
setSon(m.call, formal.position + 1, copyTree(formal.ast))
|
||||
inc(f)
|
||||
|
||||
when false:
|
||||
if sfSystemModule notin c.module.flags:
|
||||
if includeFilename("temp.nim") == c.module.info.fileIndex:
|
||||
echo "########################"
|
||||
echo m.call.renderTree
|
||||
for i in 1..m.call.len-1:
|
||||
debug m.call[i].typ
|
||||
|
||||
|
|
|
|||
1
todo.txt
1
todo.txt
|
|
@ -1,7 +1,6 @@
|
|||
Version 0.8.14
|
||||
==============
|
||||
|
||||
- bug: s[1..n] = @[] produces wrong C code
|
||||
- optimize unused constants away (affected by HLO)
|
||||
- fix actors.nim: fix thread local storage emulation
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue