From f2ff1c6074b1591c231f8f6b3394f9700cac7fad Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Sun, 31 Oct 2021 00:20:13 +0700 Subject: [PATCH] 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 Run-TryBot: Cuong Manh Le TryBot-Result: Go Bot Reviewed-by: Cherry Mui Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/escape/call.go | 6 +++++- test/fixedbugs/issue49240.go | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/issue49240.go diff --git a/src/cmd/compile/internal/escape/call.go b/src/cmd/compile/internal/escape/call.go index 9e5abed591..63e790a786 100644 --- a/src/cmd/compile/internal/escape/call.go +++ b/src/cmd/compile/internal/escape/call.go @@ -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) diff --git a/test/fixedbugs/issue49240.go b/test/fixedbugs/issue49240.go new file mode 100644 index 0000000000..26929fe1a2 --- /dev/null +++ b/test/fixedbugs/issue49240.go @@ -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{}) +}