fix #26112: update variable kinds in isPartOf to include skResult (#26114)

fix #26112
This commit is contained in:
ringabout
2026-08-18 05:37:46 +08:00
committed by GitHub
parent 5f5cf8dd03
commit 1201c184d7
2 changed files with 36 additions and 1 deletions

View File

@@ -168,7 +168,7 @@ proc isPartOf*(a, b: PNode; flags: set[PartFlag] = {}): TAnalysisResult =
if a.kind == b.kind:
case a.kind
of nkSym:
const varKinds = {skVar, skTemp, skProc, skFunc}
const varKinds = {skVar, skTemp, skResult, skProc, skFunc}
# same symbol: aliasing:
if a.sym.id == b.sym.id: result = arYes
elif a.sym.kind in varKinds or b.sym.kind in varKinds:

35
tests/ccgbugs/t26112.nim Normal file
View File

@@ -0,0 +1,35 @@
discard """
matrix: "--mm:refc; --mm:orc"
ccodeCheck: "'result.fromScalar = x_p0;'"
ccodeCheck: "'result.fromObject = x_p0.fromObject;'"
ccodeCheck: "'result.nested.fromNested = x_p0.fromNested;'"
"""
# bug #26112: unrelated parameters were considered potential aliases of the
# result location when their types could be contained in the returned object.
type
Inner = object
fromNested: int
P = object
fromScalar: int
fromObject: int
nested: Inner
func fromScalar(x: int): P =
P(fromScalar: x)
proc fromObject(x: P): P =
P(fromObject: x.fromObject)
func fromNested(x: Inner): P =
P(nested: Inner(fromNested: x.fromNested))
proc selfAlias(): P =
result.fromScalar = 42
result = P(fromScalar: result.fromScalar)
doAssert fromScalar(1).fromScalar == 1
doAssert fromObject(P(fromObject: 2)).fromObject == 2
doAssert fromNested(Inner(fromNested: 3)).nested.fromNested == 3
doAssert selfAlias().fromScalar == 42