Source file test/fixedbugs/issue35518.go
1 // errorcheck -0 -l -m=2 2 3 // Copyright 2019 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 // This test makes sure that -m=2's escape analysis diagnostics don't 8 // go into an infinite loop when handling negative dereference 9 // cycles. The critical thing being tested here is that compilation 10 // succeeds ("errorcheck -0"), not any particular diagnostic output, 11 // hence the very lax ERROR patterns below. 12 13 package p 14 15 type Node struct { 16 Orig *Node 17 } 18 19 var sink *Node 20 21 func f1() { 22 var n Node // ERROR "." 23 n.Orig = &n 24 25 m := n // ERROR "." 26 sink = &m 27 } 28 29 func f2() { 30 var n1, n2 Node // ERROR "." 31 n1.Orig = &n2 32 n2 = n1 33 34 m := n2 // ERROR "." 35 sink = &m 36 } 37 38 func f3() { 39 var n1, n2 Node // ERROR "." 40 n1.Orig = &n1 41 n1.Orig = &n2 42 43 sink = n1.Orig.Orig 44 } 45