summary refs log tree commit diff stats
path: root/tests/ccgbugs/tunsafeaddr.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ccgbugs/tunsafeaddr.nim')
-rw-r--r--tests/ccgbugs/tunsafeaddr.nim19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/ccgbugs/tunsafeaddr.nim b/tests/ccgbugs/tunsafeaddr.nim
new file mode 100644
index 000000000..4f05c7c21
--- /dev/null
+++ b/tests/ccgbugs/tunsafeaddr.nim
@@ -0,0 +1,19 @@
+discard """
+  output: '''12'''
+"""
+
+{.emit: """
+long sum(long* a, long len) {
+  long i, result = 0;
+  for (i = 0; i < len; ++i) result += a[i];
+  return result;
+}
+""".}
+
+proc sum(a: ptr int; len: int): int {.importc, nodecl.}
+
+proc main =
+  let foo = [8, 3, 1]
+  echo sum(unsafeAddr foo[0], foo.len)
+
+main()