]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix load of interface{}-typed OpIData in expand_calls
authorDavid Chase <drchase@google.com>
Fri, 13 Nov 2020 21:54:48 +0000 (16:54 -0500)
committerDavid Chase <drchase@google.com>
Sat, 14 Nov 2020 17:24:37 +0000 (17:24 +0000)
In certain cases, the declkared type of an OpIData is interface{}.
This was not expected (since interface{} is a pair, right?) and
thus caused a crash.  What is intended is that these be treated as
a byteptr, so do that instead (this is what happens in 1.15).

Fixes #42568.

Change-Id: Id7c9e5dc2cbb5d7c71c6748832491ea62b0b339f
Reviewed-on: https://go-review.googlesource.com/c/go/+/270057
Trust: David Chase <drchase@google.com>
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/amd64/ssa.go
src/cmd/compile/internal/ssa/expand_calls.go
test/fixedbugs/issue42568.go [new file with mode: 0644]

index 76e33a3689916c80fd5211d81495c731ca6fed2c..5ff05a0edd16c6b0dab15099d13e9d89d1be7fc0 100644 (file)
@@ -76,7 +76,7 @@ func storeByType(t *types.Type) obj.As {
                        return x86.AMOVQ
                }
        }
-       panic("bad store type")
+       panic(fmt.Sprintf("bad store type %v", t))
 }
 
 // moveByType returns the reg->reg move instruction of the given type.
@@ -101,7 +101,7 @@ func moveByType(t *types.Type) obj.As {
                case 16:
                        return x86.AMOVUPS // int128s are in SSE registers
                default:
-                       panic(fmt.Sprintf("bad int register width %d:%s", t.Size(), t))
+                       panic(fmt.Sprintf("bad int register width %d:%v", t.Size(), t))
                }
        }
 }
index fbde19d94c29927a2a50a0d396ced550fed31dcb..3681af65997cf89aed6694ac56d47bbce8782c07 100644 (file)
@@ -196,6 +196,9 @@ func expandCalls(f *Func) {
                        }
                        if leaf.Op == OpIData {
                                leafType = removeTrivialWrapperTypes(leaf.Type)
+                               if leafType.IsEmptyInterface() {
+                                       leafType = typ.BytePtr
+                               }
                        }
                        aux := selector.Aux
                        auxInt := selector.AuxInt + offset
diff --git a/test/fixedbugs/issue42568.go b/test/fixedbugs/issue42568.go
new file mode 100644 (file)
index 0000000..834fdc5
--- /dev/null
@@ -0,0 +1,25 @@
+// compile
+
+// Copyright 2020 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.
+
+// Ensure that late expansion correctly handles an OpIData with type interface{}
+
+package p
+
+type S struct{}
+
+func (S) M() {}
+
+type I interface {
+       M()
+}
+
+func f(i I) {
+       o := i.(interface{})
+       if _, ok := i.(*S); ok {
+               o = nil
+       }
+       println(o)
+}