Skip to content

Commit fa90aac

Browse files
cuonglmaclements
authored andcommitted
cmd/compile: fix late expand_calls leaf type for OpStructSelect/OpArraySelect
For the example in #43551, before late call expansion, the OpArg type is decomposed to int64. But the late call expansion is currently decompose it to "x.Key" instead. This CL make expand_calls decompose further for struct { 1-field type } and array [1]elem. This matches the previous rules for early decompose args: (StructSelect (StructMake1 x)) => x (ArraySelect (ArrayMake1 x)) => x Fixes #43551 Change-Id: I2f1ebe18cb81cb967f494331c3d237535d2859e7 Reviewed-on: https://go-review.googlesource.com/c/go/+/282332 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
1 parent 7cee66d commit fa90aac

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ func expandCalls(f *Func) {
194194
}
195195
break
196196
}
197-
if leaf.Op == OpIData {
197+
switch leaf.Op {
198+
case OpIData, OpStructSelect, OpArraySelect:
198199
leafType = removeTrivialWrapperTypes(leaf.Type)
199200
}
200201
aux := selector.Aux

test/fixedbugs/issue43551.dir/a.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package a
2+
3+
type S struct {
4+
a Key
5+
}
6+
7+
func (s S) A() Key {
8+
return s.a
9+
}
10+
11+
type Key struct {
12+
key int64
13+
}

test/fixedbugs/issue43551.dir/b.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package b
6+
7+
import "./a"
8+
9+
type S a.S
10+
type Key a.Key
11+
12+
func (s S) A() Key {
13+
return Key(a.S(s).A())
14+
}

test/fixedbugs/issue43551.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// compiledir
2+
3+
// Copyright 2021 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+
package ignored

0 commit comments

Comments
 (0)