summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2023-10-13 16:58:43 +0800
committerGitHub <noreply@github.com>2023-10-13 10:58:43 +0200
commit61145b1d4bd60712dbaeaca19d01f3696546046c (patch)
treea6c881476b8d9c489ab14f4e4b2687293df092c3 /tests
parent8990626ca9715a3687b28331aee4ccf242997aa2 (diff)
downloadNim-61145b1d4bd60712dbaeaca19d01f3696546046c.tar.gz
fixes #22354; Wrong C++ codegen for default parameter values in ORC (#22819)
fixes #22354

It skips `nkHiddenAddr`. No need to hoist `var parameters` without side
effects. Besides, it saves lots of temporary variables in ORC.
Diffstat (limited to 'tests')
-rw-r--r--tests/ccgbugs2/tcodegen.nim75
1 files changed, 47 insertions, 28 deletions
diff --git a/tests/ccgbugs2/tcodegen.nim b/tests/ccgbugs2/tcodegen.nim
index 84cd76e2f..aac1ecaf3 100644
--- a/tests/ccgbugs2/tcodegen.nim
+++ b/tests/ccgbugs2/tcodegen.nim
@@ -1,28 +1,47 @@
-discard """
-  targets: "c cpp"
-"""
-
-# bug #19094
-type
-  X = object
-    filler: array[2048, int]
-    innerAddress: uint
-
-proc initX(): X =
-  result.innerAddress = cast[uint](result.addr)
-
-proc initXInPlace(x: var X) =
-  x.innerAddress = cast[uint](x.addr)
-
-block: # NRVO1
-  var x = initX()
-  let innerAddress = x.innerAddress
-  let outerAddress = cast[uint](x.addr)
-  doAssert(innerAddress == outerAddress) # [OK]
-
-block: # NRVO2
-  var x: X
-  initXInPlace(x)
-  let innerAddress = x.innerAddress
-  let outerAddress = cast[uint](x.addr)
-  doAssert(innerAddress == outerAddress) # [OK]
+discard """

+  targets: "c cpp"

+"""

+

+# bug #19094

+type

+  X = object

+    filler: array[2048, int]

+    innerAddress: uint

+

+proc initX(): X =

+  result.innerAddress = cast[uint](result.addr)

+

+proc initXInPlace(x: var X) =

+  x.innerAddress = cast[uint](x.addr)

+

+block: # NRVO1

+  var x = initX()

+  let innerAddress = x.innerAddress

+  let outerAddress = cast[uint](x.addr)

+  doAssert(innerAddress == outerAddress) # [OK]

+

+block: # NRVO2

+  var x: X

+  initXInPlace(x)

+  let innerAddress = x.innerAddress

+  let outerAddress = cast[uint](x.addr)

+  doAssert(innerAddress == outerAddress) # [OK]

+

+block: # bug #22354

+  type Object = object

+    foo: int

+

+  proc takeFoo(self: var Object): int =

+    result = self.foo

+    self.foo = 999

+

+  proc doSomething(self: var Object; foo: int = self.takeFoo()) =

+    discard

+

+  proc main() =

+    var obj = Object(foo: 2)

+    obj.doSomething()

+    doAssert obj.foo == 999

+

+

+  main()