Skip to content

Commit 92363d5

Browse files
committed
cmd/compile: check width of embedded interfaces in expandiface
The code in #20162 contains an embedded interface. It didn't get dowidth'd by the frontend, and during DWARF generation, ngotype asked for a string description of it, which triggered a request for the number of fields in the interface, which triggered a dowidth, which is disallowed in the backend. The other changes in this CL are to support the test. Fixes #20162 Change-Id: I4d0be5bd949c361d4cdc89a8ed28b10977e40cf9 Reviewed-on: https://go-review.googlesource.com/42131 Run-TryBot: Josh Bleecher Snyder <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent e29ea14 commit 92363d5

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/cmd/compile/internal/gc/align.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func expandiface(t *types.Type) {
3131
for _, m := range t.Methods().Slice() {
3232
if m.Sym != nil {
3333
fields = append(fields, m)
34+
checkwidth(m.Type)
3435
continue
3536
}
3637

src/cmd/compile/internal/gc/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,7 @@ func IsAlias(sym *types.Sym) bool {
10761076
var concurrentFlagOK = [256]bool{
10771077
'B': true, // disabled bounds checking
10781078
'C': true, // disable printing of columns in error messages
1079+
'e': true, // no limit on errors; errors all come from non-concurrent code
10791080
'I': true, // add `directory` to import search path
10801081
'N': true, // disable optimizations
10811082
'l': true, // disable inlining

test/fixedbugs/issue20162.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// compile -c=4
2+
3+
// Copyright 2017 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Issue 20162: embedded interfaces weren't dowidth-ed by the front end,
8+
// leading to races in the backend.
9+
10+
package p
11+
12+
func Foo() {
13+
_ = (make([]func() interface {
14+
M(interface{})
15+
}, 1))
16+
}

test/run.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@ func goFiles(dir string) []string {
193193

194194
type runCmd func(...string) ([]byte, error)
195195

196-
func compileFile(runcmd runCmd, longname string) (out []byte, err error) {
196+
func compileFile(runcmd runCmd, longname string, flags []string) (out []byte, err error) {
197197
cmd := []string{"go", "tool", "compile", "-e"}
198+
cmd = append(cmd, flags...)
198199
if *linkshared {
199200
cmd = append(cmd, "-dynlink", "-installsuffix=dynlink")
200201
}
@@ -609,7 +610,7 @@ func (t *test) run() {
609610
return
610611

611612
case "compile":
612-
_, t.err = compileFile(runcmd, long)
613+
_, t.err = compileFile(runcmd, long, flags)
613614

614615
case "compiledir":
615616
// Compile all files in the directory in lexicographic order.

0 commit comments

Comments
 (0)