From 6495bf17105fbf5c76a719bdea3f383eea8b28db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Thu, 10 May 2018 10:10:36 +0200 Subject: [PATCH] cmd/compile: ensure init of memclr happens after growslice in extendslice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using the extendslice init node list to add the init nodes for the memclr call could add init nodes for memclr function before the growslice call created by extendslice. As all arguments of the memclr were explicitly set in OAS nodes before the memclr call this does not change the generated code currently. ./all.bash runs fine when replacing memclr init with nil suggesting there are currently no additional nodes added to the init of extendslice by the memclr call. Add the init nodes for the memclr call directly before the node of the memclr call to prevent additional future init nodes for function calls and argument evaluations to be evaluated too early when other compiler code is added. passes toolstash -cmp Updates #21266 Change-Id: I44bd396fe864bfda315175aa1064f9d51c5fb57a Reviewed-on: https://go-review.googlesource.com/112595 Reviewed-by: Josh Bleecher Snyder Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/gc/walk.go | 32 ++++++++++++----------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index 69e9d5b4e1..257e84cc95 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -3158,40 +3158,34 @@ func extendslice(n *Node, init *Nodes) *Node { tmp = nod(OSPTR, s, nil) nodes = append(nodes, nod(OAS, sptr, tmp)) - var clr []*Node - // hp := &s[len(l1)] - hp := temp(types.Types[TUNSAFEPTR]) - - tmp = nod(OINDEX, s, nod(OLEN, l1, nil)) - tmp.SetBounded(true) - tmp = nod(OADDR, tmp, nil) - tmp = nod(OCONVNOP, tmp, nil) - tmp.Type = types.Types[TUNSAFEPTR] - clr = append(clr, nod(OAS, hp, tmp)) + hp := nod(OINDEX, s, nod(OLEN, l1, nil)) + hp.SetBounded(true) + hp = nod(OADDR, hp, nil) + hp = nod(OCONVNOP, hp, nil) + hp.Type = types.Types[TUNSAFEPTR] // hn := l2 * sizeof(elem(s)) - hn := temp(types.Types[TUINTPTR]) - - tmp = nod(OMUL, l2, nodintconst(elemtype.Width)) - tmp = conv(tmp, types.Types[TUINTPTR]) - clr = append(clr, nod(OAS, hn, tmp)) + hn := nod(OMUL, l2, nodintconst(elemtype.Width)) + hn = conv(hn, types.Types[TUINTPTR]) clrname := "memclrNoHeapPointers" hasPointers := types.Haspointers(elemtype) if hasPointers { clrname = "memclrHasPointers" } - clrfn := mkcall(clrname, nil, init, hp, hn) - clr = append(clr, clrfn) + + var clr Nodes + clrfn := mkcall(clrname, nil, &clr, hp, hn) + clr.Append(clrfn) if hasPointers { // if l1ptr == sptr nifclr := nod(OIF, nod(OEQ, l1ptr, sptr), nil) - nifclr.Nbody.Set(clr) + nifclr.Nbody = clr nodes = append(nodes, nifclr) } else { - nodes = append(nodes, clr...) + nodes = append(nodes, clr.Slice()...) } typecheckslice(nodes, Etop)