From db9341a02424a80a93ad50b362b881544b685e19 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 29 May 2018 10:30:54 -0700 Subject: [PATCH] cmd/compile: update WBLoads during deadcode When we deadcode-remove a block which is a write barrier test, remove that block from the list of write barrier test blocks. Fixes #25516 Change-Id: I1efe732d5476003eab4ad6bf67d0340d7874ff0c Reviewed-on: https://go-review.googlesource.com/115037 Run-TryBot: Keith Randall Reviewed-by: Austin Clements TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/ssa/deadcode.go | 13 ++++++++++++ test/fixedbugs/issue25516.go | 26 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 test/fixedbugs/issue25516.go diff --git a/src/cmd/compile/internal/ssa/deadcode.go b/src/cmd/compile/internal/ssa/deadcode.go index 322ea82c8d..13b7d7e1e8 100644 --- a/src/cmd/compile/internal/ssa/deadcode.go +++ b/src/cmd/compile/internal/ssa/deadcode.go @@ -252,6 +252,19 @@ func deadcode(f *Func) { b.Values = b.Values[:i] } + // Remove dead blocks from WBLoads list. + i = 0 + for _, b := range f.WBLoads { + if reachable[b.ID] { + f.WBLoads[i] = b + i++ + } + } + for j := i; j < len(f.WBLoads); j++ { + f.WBLoads[j] = nil + } + f.WBLoads = f.WBLoads[:i] + // Remove unreachable blocks. Return dead blocks to allocator. i = 0 for _, b := range f.Blocks { diff --git a/test/fixedbugs/issue25516.go b/test/fixedbugs/issue25516.go new file mode 100644 index 0000000000..8326ef953f --- /dev/null +++ b/test/fixedbugs/issue25516.go @@ -0,0 +1,26 @@ +// compile + +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Make sure dead write barriers are handled correctly. + +package main + +func f(p **int) { + // The trick here is to eliminate the block containing the write barrier, + // but only after the write barrier branches are inserted. + // This requires some delicate code. + i := 0 + var b []bool + var s string + for true { + if b[i] { + var a []string + s = a[len(s)] + i = 0 + } + *p = nil + } +} -- 2.50.0