]> Cypherpunks repositories - gostls13.git/commit
cmd/compile/internal/ir: prevent NewClosureVar misuse
authorMatthew Dempsky <mdempsky@google.com>
Mon, 8 Aug 2022 19:40:49 +0000 (12:40 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 9 Aug 2022 16:41:24 +0000 (16:41 +0000)
commitbd901af30bcc8b92c5ce708b5b7d6352b17b54e8
treea40b48360d8e557266da798e7d80d2fb53a94bf7
parentb911771f129c599c4f5a6f9b866d300c4fa42159
cmd/compile/internal/ir: prevent NewClosureVar misuse

NewClosureVar should only be called to capture locally declared
variables in the enclosing function scope. This CL adds a check to
make sure it's used that way, in particular to make sure it's not
called to capture global variables.

This came up because for generic method values, we desugar the method
value into a function literal that captures the receiver value after
evaluating it. However, due to compiler backend limitations, for
package-scope generic method values we spill the receiver value into a
global variable rather than capturing it normally.

To prevent confusing backend issues when misusing NewClosureVar with
global variables, this CL adds an extra check.

Change-Id: I80f0f083dc80f70c7f0298020efe56dba00b67d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/422195
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/cmd/compile/internal/ir/name.go