1
0
mirror of https://github.com/golang/go synced 2024-09-30 04:24:29 -06:00

cmd/compile: ensure init of memclr happens after growslice in extendslice

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 <josharian@gmail.com>
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Martin Möhrmann 2018-05-10 10:10:36 +02:00
parent 6876447952
commit 6495bf1710

View File

@ -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)