mirror of
https://github.com/golang/go
synced 2024-11-11 19:31:37 -07:00
[dev.regabi] cmd/compile: reorg generated array hash loop
The ORANGE structure that is being replaced by this CL was causing trouble with another CL (CL 275695). The problem occurs if you typecheck i in the middle of generating the body of the ORANGE loop. If you typecheck i, it ends up typechecking its definition, which secretly typechecks the containing ORANGE. If you then add other items to the ORANGE body, those items will never get typechecked, as the ORANGE is already marked as typechecked. Instead, just steal the loop we use for the equality code. Might as well use the same pattern in both places. Change-Id: Idb1ac77881d2cc9da08c7437a652b50d3ee45e2e Reviewed-on: https://go-review.googlesource.com/c/go/+/275713 Trust: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
This commit is contained in:
parent
89f38323fa
commit
617383377f
@ -310,13 +310,13 @@ func genhash(t *types.Type) *obj.LSym {
|
||||
// pure memory.
|
||||
hashel := hashfor(t.Elem())
|
||||
|
||||
n := ir.Nod(ir.ORANGE, nil, ir.Nod(ir.ODEREF, np, nil))
|
||||
ni := ir.Node(NewName(lookup("i")))
|
||||
ni.SetType(types.Types[types.TINT])
|
||||
n.PtrList().Set1(ni)
|
||||
n.SetColas(true)
|
||||
colasdefn(n.List().Slice(), n)
|
||||
ni = n.List().First()
|
||||
// for i := 0; i < nelem; i++
|
||||
ni := temp(types.Types[types.TINT])
|
||||
init := ir.Nod(ir.OAS, ni, nodintconst(0))
|
||||
cond := ir.Nod(ir.OLT, ni, nodintconst(t.NumElem()))
|
||||
post := ir.Nod(ir.OAS, ni, ir.Nod(ir.OADD, ni, nodintconst(1)))
|
||||
loop := ir.Nod(ir.OFOR, cond, post)
|
||||
loop.PtrInit().Append(init)
|
||||
|
||||
// h = hashel(&p[i], h)
|
||||
call := ir.Nod(ir.OCALL, hashel, nil)
|
||||
@ -326,9 +326,9 @@ func genhash(t *types.Type) *obj.LSym {
|
||||
na := ir.Nod(ir.OADDR, nx, nil)
|
||||
call.PtrList().Append(na)
|
||||
call.PtrList().Append(nh)
|
||||
n.PtrBody().Append(ir.Nod(ir.OAS, nh, call))
|
||||
loop.PtrBody().Append(ir.Nod(ir.OAS, nh, call))
|
||||
|
||||
fn.PtrBody().Append(n)
|
||||
fn.PtrBody().Append(loop)
|
||||
|
||||
case types.TSTRUCT:
|
||||
// Walk the struct using memhash for runs of AMEM
|
||||
|
Loading…
Reference in New Issue
Block a user