diff --git a/compiler/backend/ccgexprs.nim b/compiler/backend/ccgexprs.nim index 1acf76957f5..c766ad5dd76 100644 --- a/compiler/backend/ccgexprs.nim +++ b/compiler/backend/ccgexprs.nim @@ -1451,7 +1451,7 @@ proc fewCmps(conf: ConfigRef; s: PNode): bool = # this function estimates whether it is better to emit code # for constructing the set or generating a bunch of comparisons directly if s.kind != nkCurly: return false - if (getSize(conf, s.typ) <= conf.target.intSize) and (nfAllConst in s.flags): + if (getSize(conf, s.typ) <= conf.target.intSize) and isDeepConstExpr(s): result = false # it is better to emit the set generation code elif elemType(s.typ).kind in {tyInt, tyInt16..tyInt64}: result = true # better not emit the set if int is basetype! @@ -1952,9 +1952,7 @@ proc genSetConstr(p: BProc, e: PNode, d: var TLoc) = # incl(tmp, d); incl(tmp, e); inclRange(tmp, f, g); var a, b, idx: TLoc - if nfAllConst in e.flags: - putIntoDest(p, d, e, genSetNode(p, e)) - else: + if true: if d.k == locNone: getTemp(p, e.typ, d) if getSize(p.config, e.typ) > 8: # big set: diff --git a/tests/ccgbugs/tsmall_set_contains.nim b/tests/ccgbugs/tsmall_set_contains.nim new file mode 100644 index 00000000000..a3fa5396f9a --- /dev/null +++ b/tests/ccgbugs/tsmall_set_contains.nim @@ -0,0 +1,14 @@ +discard """ + targets: "c" + description: ''' + Ensure that no '||' chain is emitted for `contains` where the set operand + is a small set literal + ''' + action: compile + ccodecheck: "\\i !@('||')" +""" + +type T = range[0..7] + +var elem = T(1) +doAssert contains({T(1), T(3)}, elem) \ No newline at end of file