-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/analysis/passes/copylock: fix infinite recursion
Generalize the 'seenTParams' map to short-circuit all forms of infinite recursion in the lockPath function, not just through type parameters. For invalid code, it is possible to have infinite recursion through named types. Fixes golang/go#61678 Change-Id: I59d39c6fcaf3dd8bbd4f989516e2fb373b277889 Reviewed-on: https://go-review.googlesource.com/c/tools/+/514818 Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
- Loading branch information
Showing
2 changed files
with
40 additions
and
16 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,30 @@ | ||
package a | ||
|
||
import "sync" | ||
|
||
// These examples are taken from golang/go#61678, modified so that A and B | ||
// contain a mutex. | ||
|
||
type A struct { | ||
a A | ||
mu sync.Mutex | ||
} | ||
|
||
type B struct { | ||
a A | ||
b B | ||
mu sync.Mutex | ||
} | ||
|
||
func okay(x A) {} | ||
func sure() { var x A; nop(x) } | ||
|
||
var fine B | ||
|
||
func what(x B) {} // want `passes lock by value` | ||
func bad() { var x B; nop(x) } // want `copies lock value` | ||
func good() { nop(B{}) } | ||
func stillgood() { nop(B{b: B{b: B{b: B{}}}}) } | ||
func nope() { nop(B{}.b) } // want `copies lock value` | ||
|
||
func nop(any) {} // only used to get around unused variable errors |