mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-26 00:21:42 +00:00
fixes #26123 `cast[T](x)` is a transparent path expression for compiler analysis. Previously, move/alias analysis could fail to see a later use through a cast and incorrectly mark the source as moved, causing the issue’s segmentation fault. for views, https://nim-lang.org/docs/manual_experimental.html#view-types-path-expressions: A cast expression cast[T](e) is a path expression. It also affects skipConvDfa, isAnalysableFieldAccess, and aliases. And I might narrow it down for the two cases above mentioned if it causes problems
This commit is contained in:
@@ -8,7 +8,7 @@ const
|
||||
nkBracketExpr, nkDerefExpr, nkHiddenDeref,
|
||||
nkAddr, nkHiddenAddr,
|
||||
nkObjDownConv, nkObjUpConv}
|
||||
PathKinds1* = {nkHiddenStdConv, nkHiddenSubConv}
|
||||
PathKinds1* = {nkHiddenStdConv, nkHiddenSubConv, nkCast}
|
||||
|
||||
proc skipConvDfa*(n: PNode): PNode =
|
||||
result = n
|
||||
@@ -125,4 +125,3 @@ proc aliases*(obj, field: PNode): AliasKind =
|
||||
else:
|
||||
result = maybe
|
||||
else: assert false # unreachable
|
||||
|
||||
|
||||
@@ -454,7 +454,7 @@ proc gen(c: var Con; n: PNode) =
|
||||
of nkPragmaBlock: gen(c, n.lastSon)
|
||||
of nkDiscardStmt, nkObjDownConv, nkObjUpConv, nkStringToCString, nkCStringToString:
|
||||
gen(c, n[0])
|
||||
of nkConv, nkExprColonExpr, nkExprEqExpr, nkCast, PathKinds1:
|
||||
of nkConv, nkExprColonExpr, nkExprEqExpr, PathKinds1:
|
||||
gen(c, n[1])
|
||||
of nkVarSection, nkLetSection: genVarSection(c, n)
|
||||
of nkDefer: raiseAssert "dfa construction pass requires the elimination of 'defer'"
|
||||
|
||||
@@ -1931,7 +1931,7 @@ proc borrowCheck(c: PContext, n, le, ri: PNode) =
|
||||
PathKinds0 = {nkDotExpr, nkCheckedFieldExpr,
|
||||
nkBracketExpr, nkAddr, nkHiddenAddr,
|
||||
nkObjDownConv, nkObjUpConv}
|
||||
PathKinds1 = {nkHiddenStdConv, nkHiddenSubConv}
|
||||
PathKinds1 = {nkHiddenStdConv, nkHiddenSubConv, nkCast}
|
||||
|
||||
proc getRoot(n: PNode; followDeref: bool): PNode =
|
||||
result = n
|
||||
|
||||
28
tests/destructor/t26123.nim
Normal file
28
tests/destructor/t26123.nim
Normal file
@@ -0,0 +1,28 @@
|
||||
discard """
|
||||
matrix: "--mm:orc"
|
||||
output: "destroy b"
|
||||
"""
|
||||
|
||||
# bug #26123
|
||||
|
||||
type
|
||||
A = ptr AObj
|
||||
|
||||
AObj = object
|
||||
b: B
|
||||
|
||||
B = distinct ptr BObj
|
||||
|
||||
BObj = object
|
||||
a: A
|
||||
|
||||
proc `=destroy`(r: var B) =
|
||||
echo "destroy b"
|
||||
|
||||
proc main() =
|
||||
var a = create(AObj)
|
||||
var b = B(create(BObj))
|
||||
a.b = b
|
||||
cast[ptr BObj](b).a = a
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user