summary refs log tree commit diff stats
path: root/tests/effects/tgcsafe.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/effects/tgcsafe.nim')
-rw-r--r--tests/effects/tgcsafe.nim26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/effects/tgcsafe.nim b/tests/effects/tgcsafe.nim
new file mode 100644
index 000000000..cfac3ddd8
--- /dev/null
+++ b/tests/effects/tgcsafe.nim
@@ -0,0 +1,26 @@
+discard """
+  errormsg: "'mainUnsafe' is not GC-safe as it performs an indirect call here"
+  line: 26
+  cmd: "nim $target --hints:on --threads:on $options $file"
+"""
+
+# bug #6955
+var global_proc: proc(a: string): int {.nimcall.} = nil
+
+proc myproc(i: int) {.gcsafe.} =
+  if global_proc != nil:
+    echo "a"
+  if isNil(global_proc):
+    return
+
+proc mymap(x: proc ()) {.effectsOf: x.} =
+  x()
+
+var
+  myglob: string
+
+proc mainSafe() {.gcsafe.} =
+  mymap(proc () = echo "foo")
+
+proc mainUnsafe() {.gcsafe.} =
+  mymap(proc () = myglob = "bar"; echo "foo", myglob)
^
f15fcfe8 ^
417a05ee ^



f15fcfe8 ^





417a05ee ^
be609279 ^
417a05ee ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97