Skip to content

Commit 95be547

Browse files
mdempskygopherbot
authored andcommitted
Revert "cmd/compile: use ONAME node directly from generated hash func"
This reverts commit 25f5d9d. Causes ICE on valid code. Updates #58572. Change-Id: Ib276c87d9b0362bbd2a760ac2a242f82d4e20400 Reviewed-on: https://go-review.googlesource.com/c/go/+/468879 Reviewed-by: Cuong Manh Le <[email protected]> Run-TryBot: Matthew Dempsky <[email protected]> Auto-Submit: Matthew Dempsky <[email protected]> Reviewed-by: Keith Randall <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 21f4340 commit 95be547

File tree

1 file changed

+20
-11
lines changed
  • src/cmd/compile/internal/reflectdata

1 file changed

+20
-11
lines changed

src/cmd/compile/internal/reflectdata/alg.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,6 @@ func genhash(t *types.Type) *obj.LSym {
134134
}
135135

136136
func hashFunc(t *types.Type) *ir.Func {
137-
sym := TypeSymPrefix(".hash", t)
138-
if sym.Def != nil {
139-
return sym.Def.(*ir.Name).Func
140-
}
141-
142137
base.Pos = base.AutogeneratedPos // less confusing than end of input
143138
typecheck.DeclContext = ir.PEXTERN
144139

@@ -149,8 +144,8 @@ func hashFunc(t *types.Type) *ir.Func {
149144
}
150145
results := []*ir.Field{ir.NewField(base.Pos, nil, types.Types[types.TUINTPTR])}
151146

147+
sym := TypeSymPrefix(".hash", t)
152148
fn := typecheck.DeclFunc(sym, nil, args, results)
153-
sym.Def = fn.Nname
154149
np := ir.AsNode(fn.Type().Params().Field(0).Nname)
155150
nh := ir.AsNode(fn.Type().Params().Field(1).Nname)
156151

@@ -236,9 +231,9 @@ func hashFunc(t *types.Type) *ir.Func {
236231
fn.SetDupok(true)
237232
typecheck.Func(fn)
238233

239-
ir.WithFunc(fn, func() {
240-
typecheck.Stmts(fn.Body)
241-
})
234+
ir.CurFunc = fn
235+
typecheck.Stmts(fn.Body)
236+
ir.CurFunc = nil
242237

243238
fn.SetNilCheckDisabled(true)
244239
typecheck.Target.Decls = append(typecheck.Target.Decls, fn)
@@ -254,6 +249,8 @@ func runtimeHashFor(name string, t *types.Type) *ir.Name {
254249

255250
// hashfor returns the function to compute the hash of a value of type t.
256251
func hashfor(t *types.Type) *ir.Name {
252+
var sym *types.Sym
253+
257254
switch a, _ := types.AlgType(t); a {
258255
case types.AMEM:
259256
base.Fatalf("hashfor with AMEM type")
@@ -271,10 +268,22 @@ func hashfor(t *types.Type) *ir.Name {
271268
return runtimeHashFor("c64hash", t)
272269
case types.ACPLX128:
273270
return runtimeHashFor("c128hash", t)
271+
default:
272+
// Note: the caller of hashfor ensured that this symbol
273+
// exists and has a body by calling genhash for t.
274+
sym = TypeSymPrefix(".hash", t)
274275
}
275276

276-
fn := hashFunc(t)
277-
return fn.Nname
277+
// TODO(austin): This creates an ir.Name with a nil Func.
278+
n := typecheck.NewName(sym)
279+
ir.MarkFunc(n)
280+
n.SetType(types.NewSignature(nil, []*types.Field{
281+
types.NewField(base.Pos, nil, types.NewPtr(t)),
282+
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
283+
}, []*types.Field{
284+
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
285+
}))
286+
return n
278287
}
279288

280289
// sysClosure returns a closure which will call the

0 commit comments

Comments
 (0)