diff --git a/cl/_testdefer/loop/out.txt b/cl/_testdefer/loop/out.txt index f8981ee0..e5dba5bf 100644 --- a/cl/_testdefer/loop/out.txt +++ b/cl/_testdefer/loop/out.txt @@ -1,7 +1,7 @@ -0: always -2: loop -4: loop -5: loop -3: cond -6: cond -1: cond + 0: always + 1: cond + 2: loop + 5: loop + 4: loop + 6: cond + 3: cond diff --git a/cl/blocks/block.go b/cl/blocks/block.go index a617c612..afd112b9 100644 --- a/cl/blocks/block.go +++ b/cl/blocks/block.go @@ -26,6 +26,8 @@ type Info struct { Next int } +// var debug = false + // ----------------------------------------------------------------------------- type blockState struct { @@ -62,9 +64,12 @@ func findLoop(states []*blockState, path []int, from, iblk int) []int { if states[succ].fdel { continue } - if succ == from { + if pos := find(path, succ); pos >= 0 { + path = path[pos:] for _, i := range path { - states[i].loop = true + s := states[i] + s.loop = true + s.fdel = true } return path } @@ -153,4 +158,13 @@ func isEnd(blk *ssa.BasicBlock) bool { return len(blk.Succs) == 0 && (len(blk.Preds) > 0 || blk.Index == 0) } +func find(path []int, fv int) int { + for i, v := range path { + if v == fv { + return i + } + } + return -1 +} + // ----------------------------------------------------------------------------- diff --git a/cl/blocks/block_test.go b/cl/blocks/block_test.go index ee171acf..d02c75a8 100644 --- a/cl/blocks/block_test.go +++ b/cl/blocks/block_test.go @@ -38,7 +38,7 @@ import ( func TestTestdefer(t *testing.T) { // debug = true - fromDir(t, "loop", "../_testdefer") + fromDir(t, "print", "../_testdefer") } func fromDir(t *testing.T, sel, relDir string) {