aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMartin Möhrmann <martin@golang.org>2021-07-06 21:45:02 +0200
committerMartin Möhrmann <martin@golang.org>2021-08-23 19:49:23 +0000
commit0a7f00ae239570d664488085f9c395919bc69066 (patch)
treef22eaba8bf470e8968be6f761fdd2fe86a7c5a09 /test
parent6b9e3f883e6820a1e94448ca81eba62341cd4836 (diff)
downloadgo-0a7f00ae239570d664488085f9c395919bc69066.tar.gz
go-0a7f00ae239570d664488085f9c395919bc69066.zip
cmd/compile: do not mark arrays used for map initialization noalg
Arrays marked noalg are created by the compiler to hold keys and values to initialize map literals. The ssa backend creates a pointer type for the array type when creating an OpAddr while processing the loop that initializes the map from the arrays. The pointer type does not inherit the noalg property but points to the noalg array type. This causes values created through reflect of types that should be equal to compare unequal because the noalg and alg type might be compared and these are not the same. A similar problem occurred in #32595 for argument arrays of defer structs. Created #47904 to track improve noalg handling to be able to reintroduce this optimization again. Fixes #47068 Change-Id: I87549342bd404b98d71a3c0f33e3c169e9d4efc8 Reviewed-on: https://go-review.googlesource.com/c/go/+/344349 Trust: Martin Möhrmann <martin@golang.org> Run-TryBot: Martin Möhrmann <martin@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/issue47068.dir/a.go15
-rw-r--r--test/fixedbugs/issue47068.dir/b.go15
-rw-r--r--test/fixedbugs/issue47068.dir/main.go15
-rw-r--r--test/fixedbugs/issue47068.go7
4 files changed, 52 insertions, 0 deletions
diff --git a/test/fixedbugs/issue47068.dir/a.go b/test/fixedbugs/issue47068.dir/a.go
new file mode 100644
index 0000000000..f7b780d459
--- /dev/null
+++ b/test/fixedbugs/issue47068.dir/a.go
@@ -0,0 +1,15 @@
+// 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 a
+
+func A() {
+ var m map[int]int = map[int]int{
+ 0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0,
+ 10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0, 17: 0, 18: 0, 19: 0,
+ 20: 0, 21: 0, 22: 0, 23: 0, 24: 0, 25: 0, 26: 0, 27: 0, 28: 0, 29: 0}
+ if len(m) != 30 {
+ panic("unepexted map length")
+ }
+}
diff --git a/test/fixedbugs/issue47068.dir/b.go b/test/fixedbugs/issue47068.dir/b.go
new file mode 100644
index 0000000000..d341a4a395
--- /dev/null
+++ b/test/fixedbugs/issue47068.dir/b.go
@@ -0,0 +1,15 @@
+// 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 b
+
+import "reflect"
+
+func B() {
+ t1 := reflect.TypeOf([30]int{})
+ t2 := reflect.TypeOf(new([30]int)).Elem()
+ if t1 != t2 {
+ panic("[30]int types do not match")
+ }
+}
diff --git a/test/fixedbugs/issue47068.dir/main.go b/test/fixedbugs/issue47068.dir/main.go
new file mode 100644
index 0000000000..16ef5b780b
--- /dev/null
+++ b/test/fixedbugs/issue47068.dir/main.go
@@ -0,0 +1,15 @@
+// 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 main
+
+import (
+ "a"
+ "b"
+)
+
+func main() {
+ a.A()
+ b.B()
+}
diff --git a/test/fixedbugs/issue47068.go b/test/fixedbugs/issue47068.go
new file mode 100644
index 0000000000..af6f134172
--- /dev/null
+++ b/test/fixedbugs/issue47068.go
@@ -0,0 +1,7 @@
+// rundir
+
+// Copyright 2019 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 ignored