From 617383377f0e870a9258230cf29fd11097b9229a Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Sat, 5 Dec 2020 17:25:28 -0800 Subject: [PATCH] [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 Trust: Dan Scales Run-TryBot: Keith Randall TryBot-Result: Go Bot Reviewed-by: Dan Scales --- src/cmd/compile/internal/gc/alg.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cmd/compile/internal/gc/alg.go b/src/cmd/compile/internal/gc/alg.go index c786a27415..ea57e7398d 100644 --- a/src/cmd/compile/internal/gc/alg.go +++ b/src/cmd/compile/internal/gc/alg.go @@ -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