for {
switch nn := n; nn.Op() {
case OXDOT:
- base.FatalfAt(n.Pos(), "OXDOT in walk: %v", n)
+ base.FatalfAt(n.Pos(), "OXDOT in OuterValue: %v", n)
case ODOT:
nn := nn.(*SelectorExpr)
n = nn.X
// main round of inlining)
for _, fun := range g.newInsts {
inline.InlineCalls(fun.(*ir.Func))
+ // New instantiations created during inlining should run
+ // ComputeAddrTaken directly, since we are past the main pass
+ // that did ComputeAddrTaken(). We could instead do this
+ // incrementally during stenciling (for all instantiations,
+ // including main ones before inlining), since we have the
+ // type information.
+ typecheck.ComputeAddrtaken(fun.(*ir.Func).Body)
}
}
assert(l == len(g.newInsts))
IncrementalAddrtaken = false
defer func() {
if DirtyAddrtaken {
- ComputeAddrtaken(fn.Inl.Body) // compute addrtaken marks once types are available
+ // We do ComputeAddrTaken on function instantiations, but not
+ // generic functions (since we may not yet know if x in &x[i]
+ // is an array or a slice).
+ if !fn.Type().HasTParam() {
+ ComputeAddrtaken(fn.Inl.Body) // compute addrtaken marks once types are available
+ }
DirtyAddrtaken = false
}
IncrementalAddrtaken = true
--- /dev/null
+// Copyright 2021 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.
+
+package a
+
+type A[T any] struct {
+ a int
+}
+
+func (a A[T]) F() {
+ _ = &a.a
+}
--- /dev/null
+// Copyright 2021 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.
+
+package b
+
+import "a"
+
+type B[T any] struct {
+ v a.A[T]
+}
+
+func (b B[T]) F() {
+ b.v.F()
+}
--- /dev/null
+// compiledir -G=3
+
+// Copyright 2021 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.
+
+package ignored
--- /dev/null
+// run -gcflags=-G=3
+
+// Copyright 2021 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.
+
+// Testing that AddrTaken logic doesn't cause problems for function instantiations
+
+package main
+
+type A[T interface{ []int | [5]int }] struct {
+ val T
+}
+
+//go:noinline
+func (a A[T]) F() {
+ _ = &a.val[2]
+}
+
+func main() {
+ var x A[[]int]
+ x.val = make([]int, 4)
+ _ = &x.val[3]
+ x.F()
+ var y A[[5]int]
+ _ = &y.val[3]
+ y.F()
+}