summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorPaul Tan <pyokagan@gmail.com>2020-10-07 00:05:31 +0800
committerGitHub <noreply@github.com>2020-10-06 18:05:31 +0200
commitfa841214212cba21ebbf9a0a18a9ce367fab15d2 (patch)
tree746e0026c87b0ddb3c48ac8d471b6d2459976e8b
parent695f955f70bfcbad12e64592583daf28e781c047 (diff)
downloadNim-fa841214212cba21ebbf9a0a18a9ce367fab15d2.tar.gz
effects: exclude swap() from "indirect calls" assumption (#15504)
swap() will never call any procs passed to it, and so it can be safely
excluded from the "assume indirect calls are taken" effects tracking
rule.
-rw-r--r--compiler/sempass2.nim2
-rw-r--r--tests/effects/teffects10.nim12
2 files changed, 13 insertions, 1 deletions
diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim
index 4eac6ef13..f0d6c6c7a 100644
--- a/compiler/sempass2.nim
+++ b/compiler/sempass2.nim
@@ -552,7 +552,7 @@ proc isNoEffectList(n: PNode): bool {.inline.} =
   n.len == 0 or (n[tagEffects] == nil and n[exceptionEffects] == nil)
 
 proc isTrival(caller: PNode): bool {.inline.} =
-  result = caller.kind == nkSym and caller.sym.magic in {mEqProc, mIsNil, mMove, mWasMoved}
+  result = caller.kind == nkSym and caller.sym.magic in {mEqProc, mIsNil, mMove, mWasMoved, mSwap}
 
 proc trackOperandForIndirectCall(tracked: PEffects, n: PNode, paramType: PType; caller: PNode) =
   let a = skipConvAndClosure(n)
diff --git a/tests/effects/teffects10.nim b/tests/effects/teffects10.nim
new file mode 100644
index 000000000..8193b394a
--- /dev/null
+++ b/tests/effects/teffects10.nim
@@ -0,0 +1,12 @@
+discard """
+action: compile
+"""
+
+# https://github.com/nim-lang/Nim/issues/15495
+
+proc f() {.raises: [].} =
+  var a: proc ()
+  var b: proc ()
+  swap(a, b)
+
+f()