-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/compile: preserve loop depth when evaluating block
Add block method to preserve loop depth when evaluating statements in a block, so escape analysis can handle looping label more precisely. Updates #22438 Change-Id: I39b306544a6c0ee3fcbebbe0d0ee735cb71773e6 Reviewed-on: https://go-review.googlesource.com/c/go/+/193517 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
- Loading branch information
Showing
2 changed files
with
58 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// errorcheck -0 -m -l | ||
|
||
// 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. | ||
|
||
// Test escape analysis for goto statements. | ||
|
||
package escape | ||
|
||
var x bool | ||
|
||
func _() { | ||
var p *int | ||
loop: | ||
if x { | ||
goto loop | ||
} | ||
// BAD: We should be able to recognize that there | ||
// aren't any more "goto loop" after here. | ||
p = new(int) // ERROR "escapes to heap" | ||
_ = p | ||
} | ||
|
||
func _() { | ||
var p *int | ||
if x { | ||
loop: | ||
goto loop | ||
} else { | ||
p = new(int) // ERROR "does not escape" | ||
} | ||
_ = p | ||
} | ||
|
||
func _() { | ||
var p *int | ||
if x { | ||
loop: | ||
goto loop | ||
} | ||
p = new(int) // ERROR "does not escape" | ||
_ = p | ||
} |