diff --git a/src/cmd/compile/internal/gc/gen.go b/src/cmd/compile/internal/gc/gen.go index 22705b47d1..bfc1b0a1a4 100644 --- a/src/cmd/compile/internal/gc/gen.go +++ b/src/cmd/compile/internal/gc/gen.go @@ -10,6 +10,7 @@ import ( "cmd/internal/obj" "cmd/internal/src" "fmt" + "strconv" ) func Sysfunc(name string) *obj.LSym { @@ -182,6 +183,17 @@ func moveToHeap(n *Node) { } } +// autotmpname returns the name for an autotmp variable numbered n. +func autotmpname(n int) string { + // Give each tmp a different name so that they can be registerized. + // Add a preceding . to avoid clashing with legal names. + const prefix = ".autotmp_" + // Start with a buffer big enough to hold a large n. + b := []byte(prefix + " ")[:len(prefix)] + b = strconv.AppendInt(b, int64(n), 10) + return internString(b) +} + // make a new Node off the books func tempname(nn *Node, t *Type) { if Curfn == nil { @@ -191,16 +203,14 @@ func tempname(nn *Node, t *Type) { Dump("tempname", Curfn) Fatalf("adding tempname to wrong closure function") } - if t == nil { Fatalf("tempname called with nil type") } - // give each tmp a different name so that there - // a chance to registerizer them. - // Add a preceding . to avoid clash with legal names. - s := lookupN(".autotmp_", statuniqgen) - statuniqgen++ + s := &Sym{ + Name: autotmpname(len(Curfn.Func.Dcl)), + Pkg: localpkg, + } n := newname(s) s.Def = n n.Type = t diff --git a/src/cmd/compile/internal/gc/go.go b/src/cmd/compile/internal/gc/go.go index 99e481cc87..5d5f5a231c 100644 --- a/src/cmd/compile/internal/gc/go.go +++ b/src/cmd/compile/internal/gc/go.go @@ -242,8 +242,6 @@ var funcsyms []*Sym var dclcontext Class // PEXTERN/PAUTO -var statuniqgen int // name generator for static temps - var Curfn *Node var Widthptr int diff --git a/src/cmd/compile/internal/gc/sinit.go b/src/cmd/compile/internal/gc/sinit.go index cbc3ad9769..fb6570cec1 100644 --- a/src/cmd/compile/internal/gc/sinit.go +++ b/src/cmd/compile/internal/gc/sinit.go @@ -569,6 +569,8 @@ const ( // data statements for the constant // part of the composite literal. +var statuniqgen int // name generator for static temps + // staticname returns a name backed by a static data symbol. // Callers should call n.Name.SetReadonly(true) on the // returned node for readonly nodes.