Commit 92363d52 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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: 's avatarMatthew Dempsky <mdempsky@google.com>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent e29ea141
......@@ -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
}
......
......@@ -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
......
// 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))
}
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment