]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix rewriting slice literal call argument
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Sat, 30 Oct 2021 17:20:13 +0000 (00:20 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 2 Nov 2021 16:19:45 +0000 (16:19 +0000)
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>
src/cmd/compile/internal/escape/call.go
test/fixedbugs/issue49240.go [new file with mode: 0644]

index 9e5abed59142edaf7b6dba120d733f765e4cf6cb..63e790a78670abeac0f9c0f96c24eccfe5913e4b 100644 (file)
@@ -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 (file)
index 0000000..26929fe
--- /dev/null
@@ -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{})
+}