* fix #20997 calling system.card[T](x: set[T]) with T of int8 or uint8 uses mismatched C array sizes * fullfil set variant
This commit is contained in:
parent
ca9c74391a
commit
0b319fee3d
3 changed files with 24 additions and 4 deletions
|
|
@ -2126,7 +2126,7 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
of mCard:
|
of mCard:
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
initLocExpr(p, e[1], a)
|
initLocExpr(p, e[1], a)
|
||||||
putIntoDest(p, d, e, ropecg(p.module, "#cardSet($1, $2)", [rdCharLoc(a), size]))
|
putIntoDest(p, d, e, ropecg(p.module, "#cardSet($1, $2)", [addrLoc(p.config, a), size]))
|
||||||
of mLtSet, mLeSet:
|
of mLtSet, mLeSet:
|
||||||
getTemp(p, getSysType(p.module.g.graph, unknownLineInfo, tyInt), i) # our counter
|
getTemp(p, getSysType(p.module.g.graph, unknownLineInfo, tyInt), i) # our counter
|
||||||
initLocExpr(p, e[1], a)
|
initLocExpr(p, e[1], a)
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,9 @@
|
||||||
# set handling
|
# set handling
|
||||||
|
|
||||||
type
|
type
|
||||||
NimSet = array[0..4*2048-1, uint8]
|
NimSet = array[0..8192-1, uint8]
|
||||||
|
|
||||||
|
proc cardSetImpl(s: openArray[uint8], len: int): int {.inline.} =
|
||||||
proc cardSet(s: NimSet, len: int): int {.compilerproc, inline.} =
|
|
||||||
var i = 0
|
var i = 0
|
||||||
result = 0
|
result = 0
|
||||||
when defined(x86) or defined(amd64):
|
when defined(x86) or defined(amd64):
|
||||||
|
|
@ -24,3 +23,6 @@ proc cardSet(s: NimSet, len: int): int {.compilerproc, inline.} =
|
||||||
while i < len:
|
while i < len:
|
||||||
inc(result, countBits32(uint32(s[i])))
|
inc(result, countBits32(uint32(s[i])))
|
||||||
inc(i, 1)
|
inc(i, 1)
|
||||||
|
|
||||||
|
proc cardSet(s: NimSet, len: int): int {.compilerproc, inline.} =
|
||||||
|
result = cardSetImpl(s, len)
|
||||||
|
|
|
||||||
18
tests/sets/t20997.nim
Normal file
18
tests/sets/t20997.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
discard """
|
||||||
|
joinable: false
|
||||||
|
"""
|
||||||
|
|
||||||
|
{.passC: "-flto".}
|
||||||
|
{.passL: "-flto".}
|
||||||
|
|
||||||
|
template f(n: int) = discard card(default(set[range[0 .. (1 shl n) - 1]]))
|
||||||
|
f( 7)
|
||||||
|
f( 8)
|
||||||
|
f( 9)
|
||||||
|
f(10)
|
||||||
|
f(11)
|
||||||
|
f(12)
|
||||||
|
f(13)
|
||||||
|
f(14)
|
||||||
|
f(15)
|
||||||
|
f(16)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue