Commit 6495bf17 authored by Martin Möhrmann's avatar Martin Möhrmann

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/112595Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 68764479
...@@ -3158,40 +3158,34 @@ func extendslice(n *Node, init *Nodes) *Node { ...@@ -3158,40 +3158,34 @@ func extendslice(n *Node, init *Nodes) *Node {
tmp = nod(OSPTR, s, nil) tmp = nod(OSPTR, s, nil)
nodes = append(nodes, nod(OAS, sptr, tmp)) nodes = append(nodes, nod(OAS, sptr, tmp))
var clr []*Node
// hp := &s[len(l1)] // hp := &s[len(l1)]
hp := temp(types.Types[TUNSAFEPTR]) hp := nod(OINDEX, s, nod(OLEN, l1, nil))
hp.SetBounded(true)
tmp = nod(OINDEX, s, nod(OLEN, l1, nil)) hp = nod(OADDR, hp, nil)
tmp.SetBounded(true) hp = nod(OCONVNOP, hp, nil)
tmp = nod(OADDR, tmp, nil) hp.Type = types.Types[TUNSAFEPTR]
tmp = nod(OCONVNOP, tmp, nil)
tmp.Type = types.Types[TUNSAFEPTR]
clr = append(clr, nod(OAS, hp, tmp))
// hn := l2 * sizeof(elem(s)) // hn := l2 * sizeof(elem(s))
hn := temp(types.Types[TUINTPTR]) hn := nod(OMUL, l2, nodintconst(elemtype.Width))
hn = conv(hn, types.Types[TUINTPTR])
tmp = nod(OMUL, l2, nodintconst(elemtype.Width))
tmp = conv(tmp, types.Types[TUINTPTR])
clr = append(clr, nod(OAS, hn, tmp))
clrname := "memclrNoHeapPointers" clrname := "memclrNoHeapPointers"
hasPointers := types.Haspointers(elemtype) hasPointers := types.Haspointers(elemtype)
if hasPointers { if hasPointers {
clrname = "memclrHasPointers" 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 hasPointers {
// if l1ptr == sptr // if l1ptr == sptr
nifclr := nod(OIF, nod(OEQ, l1ptr, sptr), nil) nifclr := nod(OIF, nod(OEQ, l1ptr, sptr), nil)
nifclr.Nbody.Set(clr) nifclr.Nbody = clr
nodes = append(nodes, nifclr) nodes = append(nodes, nifclr)
} else { } else {
nodes = append(nodes, clr...) nodes = append(nodes, clr.Slice()...)
} }
typecheckslice(nodes, Etop) typecheckslice(nodes, Etop)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment