summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorflywind <xzsflywind@gmail.com>2022-01-14 00:39:17 +0800
committerGitHub <noreply@github.com>2022-01-14 00:39:17 +0800
commit9b9ae8a487c6fbf77c8c72196e2b74f3371382b2 (patch)
treebffc1a7760caadb3192b9e7a432aa0e337c7fc8a
parent5853303be09464832ce0f189513c90c9dd15f4a0 (diff)
downloadNim-9b9ae8a487c6fbf77c8c72196e2b74f3371382b2.tar.gz
nrvo shouldn't touch bycopy object[backport:1.2] (#19385)
fix nim-lang#19342
-rw-r--r--compiler/ccgtypes.nim2
-rw-r--r--tests/objects/m19342.c12
-rw-r--r--tests/objects/t19342.nim18
3 files changed, 31 insertions, 1 deletions
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim
index 740ce5f19..df1874b26 100644
--- a/compiler/ccgtypes.nim
+++ b/compiler/ccgtypes.nim
@@ -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)
diff --git a/tests/objects/m19342.c b/tests/objects/m19342.c
new file mode 100644
index 000000000..113f65309
--- /dev/null
+++ b/tests/objects/m19342.c
@@ -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;
+}
\ No newline at end of file
diff --git a/tests/objects/t19342.nim b/tests/objects/t19342.nim
new file mode 100644
index 000000000..d40d15a4b
--- /dev/null
+++ b/tests/objects/t19342.nim
@@ -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()