Skip to content

Commit

Permalink
fixes #23354; fixes #12340; sink parameters sometimes not copied even…
Browse files Browse the repository at this point in the history
… when there are later reads
  • Loading branch information
ringabout committed Feb 29, 2024
1 parent 1e7ca2d commit 32c032c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions compiler/sempass2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ proc collectObjectTree(graph: ModuleGraph, n: PNode) =
else:
graph.objectTree[root].add (depthLevel, typ)

proc createTypeBoundOps(tracked: PEffects, typ: PType; info: TLineInfo) =
proc createTypeBoundOps(tracked: PEffects, typ: PType; info: TLineInfo; fromSinkParam = false) =
if typ == nil or sfGeneratedOp in tracked.owner.flags:
# don't create type bound ops for anything in a function with a `nodestroy` pragma
# bug #21987
Expand All @@ -132,7 +132,8 @@ proc createTypeBoundOps(tracked: PEffects, typ: PType; info: TLineInfo) =

createTypeBoundOps(tracked.graph, tracked.c, typ, info, tracked.c.idgen)
if (tfHasAsgn in typ.flags) or
optSeqDestructors in tracked.config.globalOptions:
optSeqDestructors in tracked.config.globalOptions or
(tracked.config.selectedGC == gcRefc and fromSinkParam):
tracked.owner.flags.incl sfInjectDestructors

proc isLocalSym(a: PEffects, s: PSym): bool =
Expand Down Expand Up @@ -1016,7 +1017,7 @@ proc trackCall(tracked: PEffects; n: PNode) =
let paramType = op[i]
case paramType.kind
of tySink:
createTypeBoundOps(tracked, paramType.elementType, n.info)
createTypeBoundOps(tracked, paramType.elementType, n.info, fromSinkParam = true)
checkForSink(tracked, n[i])
of tyVar:
if isOutParam(paramType):
Expand Down

0 comments on commit 32c032c

Please sign in to comment.