cmd/compile: fix rewriting slice literal call argument

When seeing Key:Value expression in slice literal, the compiler only
needs to emit tmp var for the Value, not the whole expression.

Fixes #49240

Change-Id: I7bda3c796a93c0fa1974f7c5930f38025dfa665c
Reviewed-on: https://go-review.googlesource.com/c/go/+/360055
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: Cherry Mui <cherryyz@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Cuong Manh Le 2021-10-31 00:20:13 +07:00
Родитель c6a0b6f2de
Коммит f2ff1c6074
2 изменённых файлов: 16 добавлений и 1 удалений

Просмотреть файл

@ -337,7 +337,11 @@ func (e *escape) rewriteArgument(argp *ir.Node, init *ir.Nodes, call ir.Node, fn
if arg := *argp; arg.Op() == ir.OSLICELIT {
list := arg.(*ir.CompLitExpr).List
for i := range list {
visit(arg.Pos(), &list[i])
el := &list[i]
if list[i].Op() == ir.OKEY {
el = &list[i].(*ir.KeyExpr).Value
}
visit(arg.Pos(), el)
}
} else {
visit(call.Pos(), argp)

Просмотреть файл

@ -0,0 +1,11 @@
// compile
// Copyright 2021 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.
package p
func f() {
go copy([]int{1: 0}, []int{})
}