diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go index 9355174da89b8..8df75b2285f42 100644 --- a/src/cmd/compile/internal/typecheck/iimport.go +++ b/src/cmd/compile/internal/typecheck/iimport.go @@ -508,6 +508,12 @@ func (p *iimporter) typAt(off uint64) *types.Type { base.Fatalf("predeclared type missing from cache: %d", off) } t = p.newReader(off-predeclReserved, nil).typ1() + // Ensure size is calculated for imported types. Since CL 283313, the compiler + // does not compile the function immediately when it sees them. Instead, funtions + // are pushed to compile queue, then draining from the queue for compiling. + // During this process, the size calculation is disabled, so it is not safe for + // calculating size during SSA generation anymore. See issue #44732. + types.CheckSize(t) p.typCache[off] = t } return t diff --git a/test/fixedbugs/issue44732.dir/bar/bar.go b/test/fixedbugs/issue44732.dir/bar/bar.go new file mode 100644 index 0000000000000..fc141616100e0 --- /dev/null +++ b/test/fixedbugs/issue44732.dir/bar/bar.go @@ -0,0 +1,11 @@ +// 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 bar + +import "issue44732.dir/foo" + +type Bar struct { + Foo *foo.Foo +} diff --git a/test/fixedbugs/issue44732.dir/foo/foo.go b/test/fixedbugs/issue44732.dir/foo/foo.go new file mode 100644 index 0000000000000..c8afb0e880e5b --- /dev/null +++ b/test/fixedbugs/issue44732.dir/foo/foo.go @@ -0,0 +1,13 @@ +// 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 foo + +type Foo struct { + updatecb func() +} + +func NewFoo() *Foo { + return &Foo{updatecb: nil} +} diff --git a/test/fixedbugs/issue44732.dir/main.go b/test/fixedbugs/issue44732.dir/main.go new file mode 100644 index 0000000000000..21208ecdd93d8 --- /dev/null +++ b/test/fixedbugs/issue44732.dir/main.go @@ -0,0 +1,15 @@ +// 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 main + +import ( + "issue44732.dir/bar" + "issue44732.dir/foo" +) + +func main() { + _ = bar.Bar{} + _ = foo.NewFoo() +} diff --git a/test/fixedbugs/issue44732.go b/test/fixedbugs/issue44732.go new file mode 100644 index 0000000000000..42106712057c0 --- /dev/null +++ b/test/fixedbugs/issue44732.go @@ -0,0 +1,7 @@ +// runindir + +// 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