mirror of
https://github.com/golang/go
synced 2024-11-26 08:07:57 -07:00
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>
This commit is contained in:
parent
6b9e3f883e
commit
0a7f00ae23
@ -440,8 +440,8 @@ func maplit(n *ir.CompLitExpr, m ir.Node, init *ir.Nodes) {
|
||||
tk := types.NewArray(n.Type().Key(), int64(len(entries)))
|
||||
te := types.NewArray(n.Type().Elem(), int64(len(entries)))
|
||||
|
||||
tk.SetNoalg(true)
|
||||
te.SetNoalg(true)
|
||||
// TODO(#47904): mark tk and te NoAlg here once the
|
||||
// compiler/linker can handle NoAlg types correctly.
|
||||
|
||||
types.CalcSize(tk)
|
||||
types.CalcSize(te)
|
||||
|
15
test/fixedbugs/issue47068.dir/a.go
Normal file
15
test/fixedbugs/issue47068.dir/a.go
Normal file
@ -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")
|
||||
}
|
||||
}
|
15
test/fixedbugs/issue47068.dir/b.go
Normal file
15
test/fixedbugs/issue47068.dir/b.go
Normal file
@ -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")
|
||||
}
|
||||
}
|
15
test/fixedbugs/issue47068.dir/main.go
Normal file
15
test/fixedbugs/issue47068.dir/main.go
Normal file
@ -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()
|
||||
}
|
7
test/fixedbugs/issue47068.go
Normal file
7
test/fixedbugs/issue47068.go
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user