From ed5233166fd75541d9d2464e1b165079ee948a53 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Fri, 10 Apr 2020 21:33:27 -0700 Subject: [PATCH] cmd/compile: simplify slicebytes Use slicesym to implement. Remove len param. Passes toolstash-check. Change-Id: Ia6d4fb2a3b476eceeba60979b4dd82b634b43939 Reviewed-on: https://go-review.googlesource.com/c/go/+/228887 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Cuong Manh Le Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/obj.go | 11 ++++------- src/cmd/compile/internal/gc/sinit.go | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/cmd/compile/internal/gc/obj.go b/src/cmd/compile/internal/gc/obj.go index b8fb7494053..95a1a3664ce 100644 --- a/src/cmd/compile/internal/gc/obj.go +++ b/src/cmd/compile/internal/gc/obj.go @@ -365,11 +365,12 @@ func stringsym(pos src.XPos, s string) (data *obj.LSym) { var slicebytes_gen int -func slicebytes(nam *Node, s string, len int) { +func slicebytes(nam *Node, s string) { slicebytes_gen++ symname := fmt.Sprintf(".gobytes.%d", slicebytes_gen) sym := localpkg.Lookup(symname) - sym.Def = asTypesNode(newname(sym)) + symnode := newname(sym) + sym.Def = asTypesNode(symnode) lsym := sym.Linksym() off := dsname(lsym, 0, s, nam.Pos, "slice") @@ -378,11 +379,7 @@ func slicebytes(nam *Node, s string, len int) { if nam.Op != ONAME { Fatalf("slicebytes %v", nam) } - nsym := nam.Sym.Linksym() - off = int(nam.Xoffset) - off = dsymptr(nsym, off, lsym, 0) - off = duintptr(nsym, off, uint64(len)) - duintptr(nsym, off, uint64(len)) + slicesym(nam, symnode, int64(len(s))) } func dsname(s *obj.LSym, off int, t string, pos src.XPos, what string) int { diff --git a/src/cmd/compile/internal/gc/sinit.go b/src/cmd/compile/internal/gc/sinit.go index 4dbf6169377..01645765463 100644 --- a/src/cmd/compile/internal/gc/sinit.go +++ b/src/cmd/compile/internal/gc/sinit.go @@ -208,7 +208,7 @@ func (s *InitSchedule) staticassign(l *Node, r *Node) bool { case OSTR2BYTES: if l.Class() == PEXTERN && r.Left.Op == OLITERAL { sval := strlit(r.Left) - slicebytes(l, sval, len(sval)) + slicebytes(l, sval) return true }