1
0
mirror of https://github.com/golang/go synced 2024-11-11 19:21:37 -07:00

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 <josharian@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Josh Bleecher Snyder 2017-04-28 07:28:49 -07:00
parent e29ea14100
commit 92363d52c0
4 changed files with 21 additions and 2 deletions

View File

@ -31,6 +31,7 @@ func expandiface(t *types.Type) {
for _, m := range t.Methods().Slice() {
if m.Sym != nil {
fields = append(fields, m)
checkwidth(m.Type)
continue
}

View File

@ -1076,6 +1076,7 @@ func IsAlias(sym *types.Sym) bool {
var concurrentFlagOK = [256]bool{
'B': true, // disabled bounds checking
'C': true, // disable printing of columns in error messages
'e': true, // no limit on errors; errors all come from non-concurrent code
'I': true, // add `directory` to import search path
'N': true, // disable optimizations
'l': true, // disable inlining

View File

@ -0,0 +1,16 @@
// compile -c=4
// Copyright 2017 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.
// Issue 20162: embedded interfaces weren't dowidth-ed by the front end,
// leading to races in the backend.
package p
func Foo() {
_ = (make([]func() interface {
M(interface{})
}, 1))
}

View File

@ -193,8 +193,9 @@ func goFiles(dir string) []string {
type runCmd func(...string) ([]byte, error)
func compileFile(runcmd runCmd, longname string) (out []byte, err error) {
func compileFile(runcmd runCmd, longname string, flags []string) (out []byte, err error) {
cmd := []string{"go", "tool", "compile", "-e"}
cmd = append(cmd, flags...)
if *linkshared {
cmd = append(cmd, "-dynlink", "-installsuffix=dynlink")
}
@ -609,7 +610,7 @@ func (t *test) run() {
return
case "compile":
_, t.err = compileFile(runcmd, long)
_, t.err = compileFile(runcmd, long, flags)
case "compiledir":
// Compile all files in the directory in lexicographic order.