Skip to content

Commit 92c732e

Browse files
committed
cmd/compile: fix load of interface{}-typed OpIData in expand_calls
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 <[email protected]> Run-TryBot: David Chase <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]>
1 parent 782cf56 commit 92c732e

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/cmd/compile/internal/amd64/ssa.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func storeByType(t *types.Type) obj.As {
7676
return x86.AMOVQ
7777
}
7878
}
79-
panic("bad store type")
79+
panic(fmt.Sprintf("bad store type %v", t))
8080
}
8181

8282
// moveByType returns the reg->reg move instruction of the given type.
@@ -101,7 +101,7 @@ func moveByType(t *types.Type) obj.As {
101101
case 16:
102102
return x86.AMOVUPS // int128s are in SSE registers
103103
default:
104-
panic(fmt.Sprintf("bad int register width %d:%s", t.Size(), t))
104+
panic(fmt.Sprintf("bad int register width %d:%v", t.Size(), t))
105105
}
106106
}
107107
}

src/cmd/compile/internal/ssa/expand_calls.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ func expandCalls(f *Func) {
196196
}
197197
if leaf.Op == OpIData {
198198
leafType = removeTrivialWrapperTypes(leaf.Type)
199+
if leafType.IsEmptyInterface() {
200+
leafType = typ.BytePtr
201+
}
199202
}
200203
aux := selector.Aux
201204
auxInt := selector.AuxInt + offset

test/fixedbugs/issue42568.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// compile
2+
3+
// Copyright 2020 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+
// Ensure that late expansion correctly handles an OpIData with type interface{}
8+
9+
package p
10+
11+
type S struct{}
12+
13+
func (S) M() {}
14+
15+
type I interface {
16+
M()
17+
}
18+
19+
func f(i I) {
20+
o := i.(interface{})
21+
if _, ok := i.(*S); ok {
22+
o = nil
23+
}
24+
println(o)
25+
}

0 commit comments

Comments
 (0)