fixes #24141; Calling algorithm reverse causes a SIGSEGV on ORC (#24142)

fixes #24141
This commit is contained in:
ringabout
2024-09-19 21:17:25 +08:00
committed by GitHub
parent 05a7a48a2b
commit 755307be61
2 changed files with 20 additions and 1 deletions

View File

@@ -511,7 +511,12 @@ proc transformAddrDeref(c: PTransf, n: PNode, kinds: TNodeKinds): PNode =
if n[0].kind in kinds and
not (n[0][0].kind == nkSym and n[0][0].sym.kind == skForVar and
n[0][0].typ.skipTypes(abstractVar).kind == tyTuple
): # elimination is harmful to `for tuple unpack` because of newTupleAccess
) and not (n[0][0].kind == nkSym and n[0][0].sym.kind == skParam and
n.typ.kind == tyVar and
n.typ.skipTypes(abstractVar).kind == tyOpenArray and
n[0][0].typ.skipTypes(abstractVar).kind == tyString)
: # elimination is harmful to `for tuple unpack` because of newTupleAccess
# it is also harmful to openArrayLoc (var openArray) for strings
# addr ( deref ( x )) --> x
result = n[0][0]
if n.typ.skipTypes(abstractVar).kind != tyOpenArray:

View File

@@ -820,3 +820,17 @@ block: # bug #23973
doAssert t == a
n()
block: # bug #24141
func reverse(s: var openArray[char]) =
s[0] = 'f'
func rev(s: var string) =
s.reverse
proc main =
var abc = "abc"
abc.rev
doAssert abc == "fbc"
main()