Skip to content

Commit

Permalink
fixes #24141; Calling algorithm reverse causes a SIGSEGV on ORC (#24142)
Browse files Browse the repository at this point in the history
fixes #24141
  • Loading branch information
ringabout authored Sep 19, 2024
1 parent 05a7a48 commit 755307b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/transf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions tests/arc/tarcmisc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 755307b

Please sign in to comment.