aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2024-03-07 14:49:30 +0700
committerGopher Robot <gobot@golang.org>2024-03-08 02:00:33 +0000
commit5a329c3bfb6328a66812e21bd1a5a32f8a5c76b0 (patch)
tree887921d1bd903fafdde40d893d0d3f2ba8416acd /test
parent8590f0aef30d1e4d242af97ae15266facb26493b (diff)
downloadgo-5a329c3bfb6328a66812e21bd1a5a32f8a5c76b0.tar.gz
go-5a329c3bfb6328a66812e21bd1a5a32f8a5c76b0.zip
cmd/compile: fix copying SSA-able variables optimization
CL 541715 added an optimization to copy SSA-able variables. When handling m[k] = append(m[k], ...) case, it uses ir.SameSafeExpr to check that m[k] expressions are the same, then doing type assertion to convert the map index to ir.IndexExpr node. However, this assertion is not safe for m[k] expression in append(m[k], ...), since it may be wrapped by ir.OCONVNOP node. Fixing this by un-wrapping any ir.OCONVNOP before doing type assertion. Fixes #66096 Change-Id: I9ff7165ab97bc7f88d0e9b7b31604da19a8ca206 Reviewed-on: https://go-review.googlesource.com/c/go/+/569716 Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/issue66096.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/fixedbugs/issue66096.go b/test/fixedbugs/issue66096.go
new file mode 100644
index 0000000000..f8621a18b4
--- /dev/null
+++ b/test/fixedbugs/issue66096.go
@@ -0,0 +1,17 @@
+// compile
+
+// Copyright 2024 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
+
+type Message struct {
+ Header map[string][]string
+}
+
+func f() {
+ m := Message{Header: map[string][]string{}}
+ m.Header[""] = append([]string(m.Header[""]), "")
+ _ = m
+}