diff options
author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2022-01-05 16:19:19 +0700 |
---|---|---|
committer | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2022-01-07 17:55:52 +0000 |
commit | 98ed91636926b4029bbbbb8c2ab4b66ee15a5734 (patch) | |
tree | bf31fbf031eee32291a9f65d13e91f1d3da45840 /src/cmd | |
parent | 2f45981679551e88880a18684a4d65ca3d9b45d9 (diff) | |
download | go-98ed91636926b4029bbbbb8c2ab4b66ee15a5734.tar.gz go-98ed91636926b4029bbbbb8c2ab4b66ee15a5734.zip |
cmd/compile: fix instantiation of types referenced during inlining
CL 352870 added extra phase for instantiation after inlining, to take
care of the new fully-instantiated types. However, when fetching inlined
body of these types's methods, we need to allow OADDR operations on
untyped expressions, the same as what main inlining phase does.
The problem does not show up, until CL 371554, which made the compiler
do not re-typecheck while importing, thus leaving a OXDOT node to be
marked as address taken when it's not safe to do that.
Fixes #50437
Change-Id: I20076b872182c520075a4f8b84230f5bcb05b341
Reviewed-on: https://go-review.googlesource.com/c/go/+/375574
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd')
-rw-r--r-- | src/cmd/compile/internal/gc/main.go | 5 | ||||
-rw-r--r-- | src/cmd/compile/internal/typecheck/subr.go | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index ed81ef7bc0..669e53d932 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -248,7 +248,12 @@ func Main(archInit func(*ssagen.ArchInfo)) { // If any new fully-instantiated types were referenced during // inlining, we need to create needed instantiations. if len(typecheck.GetInstTypeList()) > 0 { + // typecheck.IncrementalAddrtaken must be false when loading + // an inlined body. See comment in typecheck.ImportedBody function. + old := typecheck.IncrementalAddrtaken + typecheck.IncrementalAddrtaken = false noder.BuildInstantiations(false) + typecheck.IncrementalAddrtaken = old } } noder.MakeWrappers(typecheck.Target) // must happen after inlining diff --git a/src/cmd/compile/internal/typecheck/subr.go b/src/cmd/compile/internal/typecheck/subr.go index 5b5b043715..da5e9645ea 100644 --- a/src/cmd/compile/internal/typecheck/subr.go +++ b/src/cmd/compile/internal/typecheck/subr.go @@ -80,7 +80,7 @@ func markAddrOf(n ir.Node) ir.Node { if IncrementalAddrtaken { // We can only do incremental addrtaken computation when it is ok // to typecheck the argument of the OADDR. That's only safe after the - // main typecheck has completed. + // main typecheck has completed, and not loading the inlined body. // The argument to OADDR needs to be typechecked because &x[i] takes // the address of x if x is an array, but not if x is a slice. // Note: OuterValue doesn't work correctly until n is typechecked. |