Skip to content

Commit bc823b6

Browse files
ringaboutnarimiran
authored andcommitted
nrvo shouldn't touch bycopy object[backport:1.2] (#19385)
fix #19342 (cherry picked from commit 9b9ae8a)
1 parent 3d3d790 commit bc823b6

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

compiler/ccgtypes.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ proc isInvalidReturnType(conf: ConfigRef; rettype: PType): bool =
220220
# such a poor programming language.
221221
# We exclude records with refs too. This enhances efficiency and
222222
# is necessary for proper code generation of assignments.
223-
if rettype == nil or getSize(conf, rettype) > conf.target.floatSize*3:
223+
if rettype == nil or (tfByCopy notin rettype.flags and getSize(conf, rettype) > conf.target.floatSize*3):
224224
result = true
225225
else:
226226
case mapType(conf, rettype, skResult)

tests/objects/m19342.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
struct Node
2+
{
3+
int data[25];
4+
};
5+
6+
7+
struct Node hello(int name) {
8+
struct Node x = {999, 1, 2, 3, 4, 5, 6, 7, 8, 9,
9+
0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,
10+
1, 2, 3, 4, 5};
11+
return x;
12+
}

tests/objects/t19342.nim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
discard """
2+
targets: "c cpp"
3+
"""
4+
5+
{.compile: "m19342.c".}
6+
7+
# bug #19342
8+
type
9+
Node* {.bycopy.} = object
10+
data: array[25, cint]
11+
12+
proc myproc(name: cint): Node {.importc: "hello", cdecl.}
13+
14+
proc parse =
15+
let node = myproc(10)
16+
doAssert node.data[0] == 999
17+
18+
parse()

0 commit comments

Comments
 (0)