mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
Fixed codegen for constant cstring with --gc:arc (#13326)
* Fixed codegen for constant cstring with --gc:arc, fixes #13321 * Added test for #13321
This commit is contained in:
@@ -2974,7 +2974,7 @@ proc genBracedInit(p: BProc, n: PNode; isConst: bool): Rope =
|
||||
of tyObject:
|
||||
result = genConstObjConstr(p, n, isConst)
|
||||
of tyString, tyCString:
|
||||
if optSeqDestructors in p.config.globalOptions and n.kind != nkNilLit:
|
||||
if optSeqDestructors in p.config.globalOptions and n.kind != nkNilLit and ty == tyString:
|
||||
result = genStringLiteralV2Const(p.module, n, isConst)
|
||||
else:
|
||||
var d: TLoc
|
||||
|
||||
16
tests/arc/tcstring.nim
Normal file
16
tests/arc/tcstring.nim
Normal file
@@ -0,0 +1,16 @@
|
||||
discard """
|
||||
cmd: "nim c --gc:arc -r $file"
|
||||
nimout: '''hello
|
||||
h
|
||||
o
|
||||
'''
|
||||
"""
|
||||
|
||||
# Issue #13321: [codegen] --gc:arc does not properly emit cstring, results in SIGSEGV
|
||||
|
||||
let a = "hello".cstring
|
||||
echo a
|
||||
echo a[0]
|
||||
echo a[4]
|
||||
doAssert a[a.len] == '\0'
|
||||
|
||||
Reference in New Issue
Block a user