]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: prevent Noalg from breaking user types
authorMatthew Dempsky <mdempsky@google.com>
Thu, 3 Nov 2016 22:58:55 +0000 (15:58 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 4 Nov 2016 00:11:28 +0000 (00:11 +0000)
Use a separate symbol for reflect metadata for types with Noalg set.

Fixes #17752.

Change-Id: Icb6cade7e3004fc4108f67df61105dc4085cd7e2
Reviewed-on: https://go-review.googlesource.com/32679
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/walk.go
test/fixedbugs/issue17752.go [new file with mode: 0644]

index 14f7ab66ee32e4934ed6820e56a0ab5c83e95934..3554dc2e99f30b50717365cf7735a0b49237e1f5 100644 (file)
@@ -928,7 +928,14 @@ func dcommontype(s *Sym, ot int, t *Type) int {
 }
 
 func typesym(t *Type) *Sym {
-       return Pkglookup(t.tconv(FmtLeft), typepkg)
+       name := t.tconv(FmtLeft)
+
+       // Use a separate symbol name for Noalg types for #17752.
+       if a, bad := algtype1(t); a == ANOEQ && bad.Noalg {
+               name = "noalg." + name
+       }
+
+       return Pkglookup(name, typepkg)
 }
 
 // tracksym returns the symbol for tracking use of field/method f, assumed
index cfb65ebb402984761eb916ad30d32795537b0210..c1caa47480b194e4ec6b07aca527398eac331cb8 100644 (file)
@@ -1785,7 +1785,6 @@ func mkdotargslice(lr0, nn []*Node, l *Field, fp int, init *Nodes, ddd *Node) []
        }
 
        tslice := typSlice(l.Type.Elem())
-       tslice.Noalg = true
 
        var n *Node
        if len(lr0) == 0 {
diff --git a/test/fixedbugs/issue17752.go b/test/fixedbugs/issue17752.go
new file mode 100644 (file)
index 0000000..83283ad
--- /dev/null
@@ -0,0 +1,20 @@
+// run
+
+// Copyright 2016 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
+
+func f(m map[string]int) int {
+       return m["a"]
+}
+
+func g(m map[[8]string]int) int {
+       return m[[8]string{"a", "a", "a", "a", "a", "a", "a", "a"}]
+}
+
+func main() {
+       m := map[[8]string]int{}
+       g(m)
+}