mirror of
https://github.com/golang/go
synced 2024-11-23 00:40:08 -07:00
cmd/compile: fix -m=2 infinite loop in escape.go
This CL detects infinite loops due to negative dereference cycles during escape analysis, and terminates the loop gracefully. We still fail to print a complete explanation of the escape path, but esc.go didn't print *any* explanation for these test cases, so the release blocking issue here is simply that we don't infinite loop. Updates #35518. Change-Id: I39beed036e5a685706248852f1fa619af3b7abbc Reviewed-on: https://go-review.googlesource.com/c/go/+/206619 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
fc7ee0ba2c
commit
07513d208a
@ -1226,8 +1226,17 @@ func (e *Escape) walkOne(root *EscLocation, walkgen uint32, enqueue func(*EscLoc
|
||||
|
||||
// explainPath prints an explanation of how src flows to the walk root.
|
||||
func (e *Escape) explainPath(root, src *EscLocation) {
|
||||
visited := make(map[*EscLocation]bool)
|
||||
|
||||
pos := linestr(src.n.Pos)
|
||||
for {
|
||||
// Prevent infinite loop.
|
||||
if visited[src] {
|
||||
fmt.Printf("%s: warning: truncated explanation due to assignment cycle; see golang.org/issue/35518\n", pos)
|
||||
break
|
||||
}
|
||||
visited[src] = true
|
||||
|
||||
dst := src.dst
|
||||
edge := &dst.edges[src.dstEdgeIdx]
|
||||
if edge.src != src {
|
||||
|
36
test/fixedbugs/issue35518.go
Normal file
36
test/fixedbugs/issue35518.go
Normal file
@ -0,0 +1,36 @@
|
||||
// errorcheck -0 -l -m=2
|
||||
|
||||
// Copyright 2019 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.
|
||||
|
||||
// This test makes sure that -m=2's escape analysis diagnostics don't
|
||||
// go into an infinite loop when handling negative dereference
|
||||
// cycles. The critical thing being tested here is that compilation
|
||||
// succeeds ("errorcheck -0"), not any particular diagnostic output,
|
||||
// hence the very lax ERROR patterns below.
|
||||
|
||||
package p
|
||||
|
||||
type Node struct {
|
||||
Orig *Node
|
||||
}
|
||||
|
||||
var sink *Node
|
||||
|
||||
func f1() {
|
||||
var n Node // ERROR "."
|
||||
n.Orig = &n
|
||||
|
||||
m := n // ERROR "."
|
||||
sink = &m
|
||||
}
|
||||
|
||||
func f2() {
|
||||
var n1, n2 Node // ERROR "."
|
||||
n1.Orig = &n2
|
||||
n2 = n1
|
||||
|
||||
m := n2 // ERROR "."
|
||||
sink = &m
|
||||
}
|
Loading…
Reference in New Issue
Block a user