Merge pull request #8971 from LemonBoy/fix-8967
Fix codegen for set[T] parameters
This commit is contained in:
commit
4342b79a3c
3 changed files with 20 additions and 8 deletions
|
|
@ -1596,10 +1596,11 @@ proc genSwap(p: BProc, e: PNode, d: var TLoc) =
|
||||||
genAssignment(p, a, b, {})
|
genAssignment(p, a, b, {})
|
||||||
genAssignment(p, b, tmp, {})
|
genAssignment(p, b, tmp, {})
|
||||||
|
|
||||||
proc rdSetElemLoc(conf: ConfigRef; a: TLoc, setType: PType): Rope =
|
proc rdSetElemLoc(conf: ConfigRef; a: TLoc, typ: PType): Rope =
|
||||||
# read a location of an set element; it may need a subtraction operation
|
# read a location of an set element; it may need a subtraction operation
|
||||||
# before the set operation
|
# before the set operation
|
||||||
result = rdCharLoc(a)
|
result = rdCharLoc(a)
|
||||||
|
let setType = typ.skipTypes(abstractPtrs)
|
||||||
assert(setType.kind == tySet)
|
assert(setType.kind == tySet)
|
||||||
if firstOrd(conf, setType) != 0:
|
if firstOrd(conf, setType) != 0:
|
||||||
result = "($1- $2)" % [result, rope(firstOrd(conf, setType))]
|
result = "($1- $2)" % [result, rope(firstOrd(conf, setType))]
|
||||||
|
|
|
||||||
|
|
@ -162,9 +162,9 @@ proc mapType(conf: ConfigRef; typ: PType): TCTypeKind =
|
||||||
var base = skipTypes(typ.lastSon, typedescInst)
|
var base = skipTypes(typ.lastSon, typedescInst)
|
||||||
case base.kind
|
case base.kind
|
||||||
of tyOpenArray, tyArray, tyVarargs: result = ctPtrToArray
|
of tyOpenArray, tyArray, tyVarargs: result = ctPtrToArray
|
||||||
#of tySet:
|
of tySet:
|
||||||
# if mapSetType(base) == ctArray: result = ctPtrToArray
|
if mapSetType(conf, base) == ctArray: result = ctPtrToArray
|
||||||
# else: result = ctPtr
|
else: result = ctPtr
|
||||||
# XXX for some reason this breaks the pegs module
|
# XXX for some reason this breaks the pegs module
|
||||||
else: result = ctPtr
|
else: result = ctPtr
|
||||||
of tyPointer: result = ctPtr
|
of tyPointer: result = ctPtr
|
||||||
|
|
@ -641,9 +641,10 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
|
||||||
compileToCpp(m): "&" else: "*"
|
compileToCpp(m): "&" else: "*"
|
||||||
var et = origTyp.skipTypes(abstractInst).lastSon
|
var et = origTyp.skipTypes(abstractInst).lastSon
|
||||||
var etB = et.skipTypes(abstractInst)
|
var etB = et.skipTypes(abstractInst)
|
||||||
if etB.kind in {tyArray, tyOpenArray, tyVarargs}:
|
if mapType(m.config, t) == ctPtrToArray:
|
||||||
# this is correct! sets have no proper base type, so we treat
|
if etB.kind == tySet:
|
||||||
# ``var set[char]`` in `getParamTypeDesc`
|
et = getSysType(m.g.graph, unknownLineInfo(), tyUInt8)
|
||||||
|
else:
|
||||||
et = elemType(etB)
|
et = elemType(etB)
|
||||||
etB = et.skipTypes(abstractInst)
|
etB = et.skipTypes(abstractInst)
|
||||||
star[0] = '*'
|
star[0] = '*'
|
||||||
|
|
|
||||||
10
tests/ccgbugs/t8967.nim
Normal file
10
tests/ccgbugs/t8967.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
discard """
|
||||||
|
targets: "c cpp"
|
||||||
|
"""
|
||||||
|
|
||||||
|
import marshal
|
||||||
|
|
||||||
|
let orig: set[char] = {'A'..'Z'}
|
||||||
|
let m = $$orig
|
||||||
|
let old = to[set[char]](m)
|
||||||
|
doAssert orig - old == {}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue