summary refs log tree commit diff stats
path: root/tests/ccgbugs
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2022-03-20 14:02:44 +0100
committerGitHub <noreply@github.com>2022-03-20 14:02:44 +0100
commit731eabc9309997775c8be41f3e5eb5512460aad0 (patch)
tree6a9ee1b3695e221f591d7165097bb4b870a3f408 /tests/ccgbugs
parent3e83d73f272afe8de85189da7d6d513916cc2efd (diff)
downloadNim-731eabc9309997775c8be41f3e5eb5512460aad0.tar.gz
fixes #19631 (#19618)
Aliasing is hard and we have to watch out not to compile 'x = f(x.a)' into 'f(x.a, addr x)'
Diffstat (limited to 'tests/ccgbugs')
-rw-r--r--tests/ccgbugs/tcgbug.nim31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/ccgbugs/tcgbug.nim b/tests/ccgbugs/tcgbug.nim
index db9c116be..0fe4b8852 100644
--- a/tests/ccgbugs/tcgbug.nim
+++ b/tests/ccgbugs/tcgbug.nim
@@ -91,3 +91,34 @@ proc test(c: Helper): string =
   c.formatted
 
 echo test(Helper(isKind: true, formatted: "ok"))
+
+
+# bug #19613
+
+type
+  Eth2Digest = object
+    data: array[42, byte]
+
+  BlockId* = object
+    root*: Eth2Digest
+
+  BlockSlotId* = object
+    bid*: BlockId
+    slot*: uint64
+
+func init*(T: type BlockSlotId, bid: BlockId, slot: uint64): T =
+  #debugecho "init ", bid, " ", slot
+  BlockSlotId(bid: bid, slot: slot)
+
+proc bug19613 =
+  var x: BlockSlotId
+  x.bid.root.data[0] = 42
+
+  x =
+    if x.slot > 0:
+      BlockSlotId.init(x.bid, x.slot)
+    else:
+      BlockSlotId.init(x.bid, x.slot)
+  doAssert x.bid.root.data[0] == 42
+
+bug19613()