summary refs log tree commit diff stats
path: root/compiler/destroyer.nim
diff options
context:
space:
mode:
authorcooldome <cdome@bk.ru>2019-01-28 07:32:14 +0000
committerAndreas Rumpf <rumpf_a@web.de>2019-01-28 08:32:14 +0100
commit690f21043d7c1cad321e116fdc666b2951ba1da3 (patch)
treea4e512fbb6cba321b4f3c30fc22b68143018225b /compiler/destroyer.nim
parent5fa8a61a238c08bca12da272f71692f2f103b6d8 (diff)
downloadNim-690f21043d7c1cad321e116fdc666b2951ba1da3.tar.gz
isLastRead regression fix (#10463)
* fixes #10462

* add a test
Diffstat (limited to 'compiler/destroyer.nim')
-rw-r--r--compiler/destroyer.nim10
1 files changed, 6 insertions, 4 deletions
diff --git a/compiler/destroyer.nim b/compiler/destroyer.nim
index 06d4dcbef..e21d532ea 100644
--- a/compiler/destroyer.nim
+++ b/compiler/destroyer.nim
@@ -139,7 +139,7 @@ proc isLastRead(s: PSym; c: var Con; pc, comesFrom: int): int =
     of def:
       if c.g[pc].sym == s:
         # the path lead to a redefinition of 's' --> abandon it.
-        return pc
+        return high(int) 
       inc pc
     of use:
       if c.g[pc].sym == s:
@@ -150,14 +150,16 @@ proc isLastRead(s: PSym; c: var Con; pc, comesFrom: int): int =
       pc = pc + c.g[pc].dest
     of fork:
       # every branch must lead to the last read of the location:
-      let variantA = isLastRead(s, c, pc+1, pc)
+      var variantA = isLastRead(s, c, pc+1, pc)
       if variantA < 0: return -1
       let variantB = isLastRead(s, c, pc + c.g[pc].dest, pc)
       if variantB < 0: return -1
-      pc = variantA+1
+      elif variantA == high(int): 
+        variantA = variantB
+      pc = variantA
     of InstrKind.join:
       let dest = pc + c.g[pc].dest
-      if dest == comesFrom: return pc
+      if dest == comesFrom: return pc + 1
       inc pc
   return pc