Skip to content

Commit db9341a

Browse files
committed
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 <[email protected]> Reviewed-by: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent b65934f commit db9341a

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/cmd/compile/internal/ssa/deadcode.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,19 @@ func deadcode(f *Func) {
252252
b.Values = b.Values[:i]
253253
}
254254

255+
// Remove dead blocks from WBLoads list.
256+
i = 0
257+
for _, b := range f.WBLoads {
258+
if reachable[b.ID] {
259+
f.WBLoads[i] = b
260+
i++
261+
}
262+
}
263+
for j := i; j < len(f.WBLoads); j++ {
264+
f.WBLoads[j] = nil
265+
}
266+
f.WBLoads = f.WBLoads[:i]
267+
255268
// Remove unreachable blocks. Return dead blocks to allocator.
256269
i = 0
257270
for _, b := range f.Blocks {

test/fixedbugs/issue25516.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// compile
2+
3+
// Copyright 2018 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Make sure dead write barriers are handled correctly.
8+
9+
package main
10+
11+
func f(p **int) {
12+
// The trick here is to eliminate the block containing the write barrier,
13+
// but only after the write barrier branches are inserted.
14+
// This requires some delicate code.
15+
i := 0
16+
var b []bool
17+
var s string
18+
for true {
19+
if b[i] {
20+
var a []string
21+
s = a[len(s)]
22+
i = 0
23+
}
24+
*p = nil
25+
}
26+
}

0 commit comments

Comments
 (0)