Source file test/escape_goto.go

     1  // errorcheck -0 -m -l
     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  // Test escape analysis for goto statements.
     8  
     9  package escape
    10  
    11  var x bool
    12  
    13  func _() {
    14  	var p *int
    15  loop:
    16  	if x {
    17  		goto loop
    18  	}
    19  	// BAD: We should be able to recognize that there
    20  	// aren't any more "goto loop" after here.
    21  	p = new(int) // ERROR "escapes to heap"
    22  	_ = p
    23  }
    24  
    25  func _() {
    26  	var p *int
    27  	if x {
    28  	loop:
    29  		goto loop
    30  	} else {
    31  		p = new(int) // ERROR "does not escape"
    32  	}
    33  	_ = p
    34  }
    35  
    36  func _() {
    37  	var p *int
    38  	if x {
    39  	loop:
    40  		goto loop
    41  	}
    42  	p = new(int) // ERROR "does not escape"
    43  	_ = p
    44  }
    45  

View as plain text