]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: ensure init of memclr happens after growslice in extendslice
authorMartin Möhrmann <moehrmann@google.com>
Thu, 10 May 2018 08:10:36 +0000 (10:10 +0200)
committerMartin Möhrmann <moehrmann@google.com>
Sun, 13 May 2018 14:45:58 +0000 (14:45 +0000)
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>

src/cmd/compile/internal/gc/walk.go

index 69e9d5b4e1fcca3158785ebbc166f18ce1fdf16e..257e84cc9514a2d57161b4003bd171ec6081daaa 100644 (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)