diff options
| author | Keith Randall <khr@golang.org> | 2025-10-08 15:33:19 -0700 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2025-10-15 09:13:12 -0700 |
| commit | 61d1ff61adb3febdbae21da7721b7cd5389efe4a (patch) | |
| tree | b7bae4fb314b44dbfe48c0b8b16d1a5563162930 /src/cmd/compile/internal | |
| parent | 5b29875c8eb1002c4509eb9ebd9a4d32cfd7d494 (diff) | |
| download | go-61d1ff61adb3febdbae21da7721b7cd5389efe4a.tar.xz | |
cmd/compile: use block starting position for phi line number
Fixes #75615
Change-Id: I2c7f0ea1203e8a97749c9f780c29a66050f0159d
Reviewed-on: https://go-review.googlesource.com/c/go/+/710355
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd/compile/internal')
| -rw-r--r-- | src/cmd/compile/internal/ssa/stmtlines_test.go | 12 | ||||
| -rw-r--r-- | src/cmd/compile/internal/ssagen/phi.go | 3 | ||||
| -rw-r--r-- | src/cmd/compile/internal/ssagen/ssa.go | 14 |
3 files changed, 22 insertions, 7 deletions
diff --git a/src/cmd/compile/internal/ssa/stmtlines_test.go b/src/cmd/compile/internal/ssa/stmtlines_test.go index 8cd11e9828..d0f09da86f 100644 --- a/src/cmd/compile/internal/ssa/stmtlines_test.go +++ b/src/cmd/compile/internal/ssa/stmtlines_test.go @@ -137,17 +137,17 @@ func TestStmtLines(t *testing.T) { } } - var m int + var m float64 if runtime.GOARCH == "amd64" { - m = 1 // > 99% obtained on amd64, no backsliding + m = 0.011 // > 98.9% obtained on amd64, no backsliding } else if runtime.GOARCH == "riscv64" { - m = 3 // XXX temporary update threshold to 97% for regabi + m = 0.03 // XXX temporary update threshold to 97% for regabi } else { - m = 2 // expect 98% elsewhere. + m = 0.02 // expect 98% elsewhere. } - if len(nonStmtLines)*100 > m*len(lines) { - t.Errorf("Saw too many (%s, > %d%%) lines without statement marks, total=%d, nostmt=%d ('-run TestStmtLines -v' lists failing lines)\n", runtime.GOARCH, m, len(lines), len(nonStmtLines)) + if float64(len(nonStmtLines)) > m*float64(len(lines)) { + t.Errorf("Saw too many (%s, > %.1f%%) lines without statement marks, total=%d, nostmt=%d ('-run TestStmtLines -v' lists failing lines)\n", runtime.GOARCH, m*100, len(lines), len(nonStmtLines)) } t.Logf("Saw %d out of %d lines without statement marks", len(nonStmtLines), len(lines)) if testing.Verbose() { diff --git a/src/cmd/compile/internal/ssagen/phi.go b/src/cmd/compile/internal/ssagen/phi.go index 19b6920913..0dcf353bf4 100644 --- a/src/cmd/compile/internal/ssagen/phi.go +++ b/src/cmd/compile/internal/ssagen/phi.go @@ -253,7 +253,7 @@ func (s *phiState) insertVarPhis(n int, var_ ir.Node, defs []*ssa.Block, typ *ty } // Add a phi to block c for variable n. hasPhi.add(c.ID) - v := c.NewValue0I(currentRoot.Pos, ssa.OpPhi, typ, int64(n)) // TODO: line number right? + v := c.NewValue0I(s.s.blockStarts[b.ID], ssa.OpPhi, typ, int64(n)) // Note: we store the variable number in the phi's AuxInt field. Used temporarily by phi building. if var_.Op() == ir.ONAME { s.s.addNamedValue(var_.(*ir.Name), v) @@ -513,6 +513,7 @@ loop: v.Op = ssa.OpPhi v.AddArgs(args...) v.Aux = nil + v.Pos = s.s.blockStarts[b.ID] continue loop } w = a // save witness diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go index e2ef332745..ae7d57566f 100644 --- a/src/cmd/compile/internal/ssagen/ssa.go +++ b/src/cmd/compile/internal/ssagen/ssa.go @@ -1088,6 +1088,9 @@ type state struct { // First argument of append calls that could be stack allocated. appendTargets map[ir.Node]bool + + // Block starting position, indexed by block id. + blockStarts []src.XPos } type funcLine struct { @@ -1146,6 +1149,9 @@ func (s *state) startBlock(b *ssa.Block) { s.curBlock = b s.vars = map[ir.Node]*ssa.Value{} clear(s.fwdVars) + for len(s.blockStarts) <= int(b.ID) { + s.blockStarts = append(s.blockStarts, src.NoXPos) + } } // endBlock marks the end of generating code for the current block. @@ -1172,6 +1178,9 @@ func (s *state) endBlock() *ssa.Block { b.Pos = src.NoXPos } else { b.Pos = s.lastPos + if s.blockStarts[b.ID] == src.NoXPos { + s.blockStarts[b.ID] = s.lastPos + } } return b } @@ -1188,6 +1197,11 @@ func (s *state) pushLine(line src.XPos) { } else { s.lastPos = line } + // The first position we see for a new block is its starting position + // (the line number for its phis, if any). + if b := s.curBlock; b != nil && s.blockStarts[b.ID] == src.NoXPos { + s.blockStarts[b.ID] = line + } s.line = append(s.line, line) } |
