]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use fake package for allocating autos
authorKeith Randall <khr@golang.org>
Mon, 6 Jun 2016 17:56:42 +0000 (10:56 -0700)
committerKeith Randall <khr@golang.org>
Tue, 7 Jun 2016 06:04:23 +0000 (06:04 +0000)
Make sure auto names don't conflict with function names. Before this CL,
we confused name a.len (the len field of the slice a) with a.len (the function
len declared on a).

Fixes #15961

Change-Id: I14913de697b521fb35db9a1b10ba201f25d552bb
Reviewed-on: https://go-review.googlesource.com/23789
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/go.go
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/gc/ssa.go
test/fixedbugs/issue15961.go [new file with mode: 0644]

index b6b858c0d980c86c3c3c78b50b8b1c50450d5779..2e4caca15597f9402c4ac6fe1f73014033423f7a 100644 (file)
@@ -156,6 +156,8 @@ var Debug_typeassert int
 
 var localpkg *Pkg // package being compiled
 
+var autopkg *Pkg // fake package for allocating auto variables
+
 var importpkg *Pkg // package being imported
 
 var itabpkg *Pkg // fake pkg for itab entries
index 8ad3300dbed3e249f63f77c6e3cc5f10a329f37a..b4df7ed20f70ea19396edad10cd65234bf9e22ca 100644 (file)
@@ -108,6 +108,8 @@ func Main() {
 
        localpkg = mkpkg("")
        localpkg.Prefix = "\"\""
+       autopkg = mkpkg("")
+       autopkg.Prefix = "\"\""
 
        // pseudo-package, for scoping
        builtinpkg = mkpkg("go.builtin")
index b604044cb73642cb2b22f7c3393f03d00e637479..d27ac4392f78f754239e9f0f2116b063fc846272 100644 (file)
@@ -4378,7 +4378,7 @@ func (e *ssaExport) SplitStruct(name ssa.LocalSlot, i int) ssa.LocalSlot {
 // namedAuto returns a new AUTO variable with the given name and type.
 func (e *ssaExport) namedAuto(name string, typ ssa.Type) ssa.GCNode {
        t := typ.(*Type)
-       s := Lookup(name)
+       s := &Sym{Name: name, Pkg: autopkg}
        n := Nod(ONAME, nil, nil)
        s.Def = n
        s.Def.Used = true
diff --git a/test/fixedbugs/issue15961.go b/test/fixedbugs/issue15961.go
new file mode 100644 (file)
index 0000000..db3d662
--- /dev/null
@@ -0,0 +1,21 @@
+// compile
+
+// 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 y
+
+type symSet []int
+
+//go:noinline
+func (s symSet) len() (r int) {
+       return 0
+}
+
+func f(m map[int]symSet) {
+       var symSet []int
+       for _, x := range symSet {
+               m[x] = nil
+       }
+}