summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2024-09-19 21:17:25 +0800
committerGitHub <noreply@github.com>2024-09-19 15:17:25 +0200
commit755307be61e4ee7b32c8354b2c303d04bdfc3a3e (patch)
treec7f05dc59ec5e9f8e546b90207dc2e337282b7fc
parent05a7a48a2bcc21c772bd35703fa52e374d25febe (diff)
downloadNim-755307be61e4ee7b32c8354b2c303d04bdfc3a3e.tar.gz
fixes #24141; Calling algorithm reverse causes a SIGSEGV on ORC (#24142)
fixes #24141
-rw-r--r--compiler/transf.nim7
-rw-r--r--tests/arc/tarcmisc.nim14
2 files changed, 20 insertions, 1 deletions
diff --git a/compiler/transf.nim b/compiler/transf.nim
index 0a4579171..8dd24e090 100644
--- a/compiler/transf.nim
+++ b/compiler/transf.nim
@@ -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:
diff --git a/tests/arc/tarcmisc.nim b/tests/arc/tarcmisc.nim
index 49f1b80ce..b4476ef4f 100644
--- a/tests/arc/tarcmisc.nim
+++ b/tests/arc/tarcmisc.nim
@@ -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()