mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
nrvo shouldn't touch bycopy object[backport:1.2] (#19385)
fix nim-lang#19342
This commit is contained in:
@@ -220,7 +220,7 @@ proc isInvalidReturnType(conf: ConfigRef; rettype: PType): bool =
|
||||
# such a poor programming language.
|
||||
# We exclude records with refs too. This enhances efficiency and
|
||||
# is necessary for proper code generation of assignments.
|
||||
if rettype == nil or getSize(conf, rettype) > conf.target.floatSize*3:
|
||||
if rettype == nil or (tfByCopy notin rettype.flags and getSize(conf, rettype) > conf.target.floatSize*3):
|
||||
result = true
|
||||
else:
|
||||
case mapType(conf, rettype, skResult)
|
||||
|
||||
12
tests/objects/m19342.c
Normal file
12
tests/objects/m19342.c
Normal file
@@ -0,0 +1,12 @@
|
||||
struct Node
|
||||
{
|
||||
int data[25];
|
||||
};
|
||||
|
||||
|
||||
struct Node hello(int name) {
|
||||
struct Node x = {999, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
||||
0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,
|
||||
1, 2, 3, 4, 5};
|
||||
return x;
|
||||
}
|
||||
18
tests/objects/t19342.nim
Normal file
18
tests/objects/t19342.nim
Normal file
@@ -0,0 +1,18 @@
|
||||
discard """
|
||||
targets: "c cpp"
|
||||
"""
|
||||
|
||||
{.compile: "m19342.c".}
|
||||
|
||||
# bug #19342
|
||||
type
|
||||
Node* {.bycopy.} = object
|
||||
data: array[25, cint]
|
||||
|
||||
proc myproc(name: cint): Node {.importc: "hello", cdecl.}
|
||||
|
||||
proc parse =
|
||||
let node = myproc(10)
|
||||
doAssert node.data[0] == 999
|
||||
|
||||
parse()
|
||||
Reference in New Issue
Block a user