Fix codegen for set[T] parameters

Sometimes sets are materialized as arrays and we must treat them as
such: the CPP backend is pickier than the C one and would sometimes
produce invalid code.

Fixes #8967
This commit is contained in:
LemonBoy 2018-09-15 00:09:50 +02:00
commit 6af6ca6351
3 changed files with 20 additions and 8 deletions

View file

@ -1596,10 +1596,11 @@ proc genSwap(p: BProc, e: PNode, d: var TLoc) =
genAssignment(p, a, b, {})
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
# before the set operation
result = rdCharLoc(a)
let setType = typ.skipTypes(abstractPtrs)
assert(setType.kind == tySet)
if firstOrd(conf, setType) != 0:
result = "($1- $2)" % [result, rope(firstOrd(conf, setType))]