summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/sempass2.nim3
-rw-r--r--tests/ccgbugs/t5296.nim14
2 files changed, 17 insertions, 0 deletions
diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim
index 437a45817..8193a3537 100644
--- a/compiler/sempass2.nim
+++ b/compiler/sempass2.nim
@@ -577,6 +577,9 @@ proc trackOperand(tracked: PEffects, n: PNode, paramType: PType) =
         markGcUnsafe(tracked, a)
       elif tfNoSideEffect notin op.flags:
         markSideEffect(tracked, a)
+  if paramType != nil and paramType.kind == tyVar:
+    if n.kind == nkSym and isLocalVar(tracked, n.sym):
+      makeVolatile(tracked, n.sym)
   notNilCheck(tracked, n, paramType)
 
 proc breaksBlock(n: PNode): bool =
diff --git a/tests/ccgbugs/t5296.nim b/tests/ccgbugs/t5296.nim
new file mode 100644
index 000000000..990b4bee2
--- /dev/null
+++ b/tests/ccgbugs/t5296.nim
@@ -0,0 +1,14 @@
+discard """
+cmd: "nim c -d:release $file"
+output: 1
+"""
+
+proc bug() : void =
+    var x = 0
+    try:
+        inc x
+        raise new(Exception)
+    except Exception:
+        echo x
+
+bug()