]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: check width of embedded interfaces in expandiface
authorJosh Bleecher Snyder <josharian@gmail.com>
Fri, 28 Apr 2017 14:28:49 +0000 (07:28 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 28 Apr 2017 20:07:38 +0000 (20:07 +0000)
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>
src/cmd/compile/internal/gc/align.go
src/cmd/compile/internal/gc/main.go
test/fixedbugs/issue20162.go [new file with mode: 0644]
test/run.go

index 6f7e67ca93b5a8d99f6e2f563377aa5d006f820e..f29c587877bf9067c2d58a46b6149486059f14c6 100644 (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
                }
 
index d4ac4a2315421843ff51d2a5205a2edcc1bb6311..495baebcc4c1991ba9a08beb0fcb3cb52e8c6bda 100644 (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
diff --git a/test/fixedbugs/issue20162.go b/test/fixedbugs/issue20162.go
new file mode 100644 (file)
index 0000000..41f156e
--- /dev/null
@@ -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))
+}
index 3cd5352259d0556ee0afaed94ff38d9d2a2a2a5c..dc86ab743891f0f3901d731930709e0af32321be 100644 (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.