summary refs log tree commit diff stats
path: root/tests/ccgbugs2
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ccgbugs2')
-rw-r--r--tests/ccgbugs2/tcodegen.nim47
-rw-r--r--tests/ccgbugs2/tinefficient_const_table.nim27
2 files changed, 74 insertions, 0 deletions
diff --git a/tests/ccgbugs2/tcodegen.nim b/tests/ccgbugs2/tcodegen.nim
new file mode 100644
index 000000000..aac1ecaf3
--- /dev/null
+++ b/tests/ccgbugs2/tcodegen.nim
@@ -0,0 +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]

+

+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()

diff --git a/tests/ccgbugs2/tinefficient_const_table.nim b/tests/ccgbugs2/tinefficient_const_table.nim
new file mode 100644
index 000000000..8ab895cb0
--- /dev/null
+++ b/tests/ccgbugs2/tinefficient_const_table.nim
@@ -0,0 +1,27 @@
+discard """
+  output: '''a
+long
+list
+of
+words'''
+  cmd: r"nim c --hints:on $options -d:release $file"
+  ccodecheck: "! @'genericSeqAssign'"
+  targets: "c"
+"""
+
+# bug #4354
+import tables
+import sets
+import strutils
+
+#const FRUITS = ["banana", "apple", "grapes"]
+#let FRUITS = ["banana", "apple", "grapes"].toHashSet
+const FRUITS = {"banana":0, "apple":0, "grapes":0}.toTable
+
+proc main() =
+    let L = "a long list of words".split()
+    for word in L:
+        if word notin FRUITS:
+            echo(word)
+
+main()