From: Andrei Matei Date: Mon, 5 Jun 2023 23:14:01 +0000 (-0400) Subject: ssa: clarify semantics of ID-to-PC translation function X-Git-Tag: go1.22rc1~246 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e6b154defba046609b6a36313298cfc207945df7;p=gostls13.git ssa: clarify semantics of ID-to-PC translation function Make it clear that the `block` argument is not always used, and stop passing it in a case where it didn't really make sense - at the end of a function. Change-Id: I2fa86bed6ceb53a1b1cbfda5c3392e7e9da9579d Reviewed-on: https://go-review.googlesource.com/c/go/+/502115 TryBot-Result: Gopher Robot Reviewed-by: Than McIntosh Run-TryBot: David Chase Reviewed-by: David Chase --- diff --git a/src/cmd/compile/internal/ssa/debug.go b/src/cmd/compile/internal/ssa/debug.go index 7e0e1f34a8..05a72787f3 100644 --- a/src/cmd/compile/internal/ssa/debug.go +++ b/src/cmd/compile/internal/ssa/debug.go @@ -42,7 +42,10 @@ type FuncDebug struct { OptDcl []*ir.Name // Filled in by the user. Translates Block and Value ID to PC. - GetPC func(ID, ID) int64 + // + // NOTE: block is only used if value is BlockStart.ID or BlockEnd.ID. + // Otherwise, it is ignored. + GetPC func(block, value ID) int64 } type BlockDebug struct { @@ -1368,7 +1371,7 @@ func (state *debugState) buildLocationLists(blockLocs []*BlockDebug) { // Flush any leftover entries live at the end of the last block. for varID := range state.lists { - state.writePendingEntry(VarID(varID), state.f.Blocks[len(state.f.Blocks)-1].ID, FuncEnd.ID) + state.writePendingEntry(VarID(varID), -1, FuncEnd.ID) list := state.lists[varID] if state.loggingLevel > 0 { if len(list) == 0 { diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go index 8d1e30e1e6..45bf0e6dc4 100644 --- a/src/cmd/compile/internal/ssagen/ssa.go +++ b/src/cmd/compile/internal/ssagen/ssa.go @@ -7578,9 +7578,9 @@ func genssa(f *ssa.Func, pp *objw.Progs) { for i, b := range f.Blocks { idToIdx[b.ID] = i } - // Note that at this moment, Prog.Pc is a sequence number; it's - // not a real PC until after assembly, so this mapping has to - // be done later. + // Register a callback that will be used later to fill in PCs into location + // lists. At the moment, Prog.Pc is a sequence number; it's not a real PC + // until after assembly, so the translation needs to be deferred. debugInfo.GetPC = func(b, v ssa.ID) int64 { switch v { case ssa.BlockStart.ID: