Skip to content

Commit 61d1ff6

Browse files
committed
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>
1 parent 5b29875 commit 61d1ff6

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/cmd/compile/internal/ssa/stmtlines_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,17 @@ func TestStmtLines(t *testing.T) {
137137
}
138138
}
139139

140-
var m int
140+
var m float64
141141
if runtime.GOARCH == "amd64" {
142-
m = 1 // > 99% obtained on amd64, no backsliding
142+
m = 0.011 // > 98.9% obtained on amd64, no backsliding
143143
} else if runtime.GOARCH == "riscv64" {
144-
m = 3 // XXX temporary update threshold to 97% for regabi
144+
m = 0.03 // XXX temporary update threshold to 97% for regabi
145145
} else {
146-
m = 2 // expect 98% elsewhere.
146+
m = 0.02 // expect 98% elsewhere.
147147
}
148148

149-
if len(nonStmtLines)*100 > m*len(lines) {
150-
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))
149+
if float64(len(nonStmtLines)) > m*float64(len(lines)) {
150+
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))
151151
}
152152
t.Logf("Saw %d out of %d lines without statement marks", len(nonStmtLines), len(lines))
153153
if testing.Verbose() {

src/cmd/compile/internal/ssagen/phi.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func (s *phiState) insertVarPhis(n int, var_ ir.Node, defs []*ssa.Block, typ *ty
253253
}
254254
// Add a phi to block c for variable n.
255255
hasPhi.add(c.ID)
256-
v := c.NewValue0I(currentRoot.Pos, ssa.OpPhi, typ, int64(n)) // TODO: line number right?
256+
v := c.NewValue0I(s.s.blockStarts[b.ID], ssa.OpPhi, typ, int64(n))
257257
// Note: we store the variable number in the phi's AuxInt field. Used temporarily by phi building.
258258
if var_.Op() == ir.ONAME {
259259
s.s.addNamedValue(var_.(*ir.Name), v)
@@ -513,6 +513,7 @@ loop:
513513
v.Op = ssa.OpPhi
514514
v.AddArgs(args...)
515515
v.Aux = nil
516+
v.Pos = s.s.blockStarts[b.ID]
516517
continue loop
517518
}
518519
w = a // save witness

src/cmd/compile/internal/ssagen/ssa.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,9 @@ type state struct {
10881088

10891089
// First argument of append calls that could be stack allocated.
10901090
appendTargets map[ir.Node]bool
1091+
1092+
// Block starting position, indexed by block id.
1093+
blockStarts []src.XPos
10911094
}
10921095

10931096
type funcLine struct {
@@ -1146,6 +1149,9 @@ func (s *state) startBlock(b *ssa.Block) {
11461149
s.curBlock = b
11471150
s.vars = map[ir.Node]*ssa.Value{}
11481151
clear(s.fwdVars)
1152+
for len(s.blockStarts) <= int(b.ID) {
1153+
s.blockStarts = append(s.blockStarts, src.NoXPos)
1154+
}
11491155
}
11501156

11511157
// endBlock marks the end of generating code for the current block.
@@ -1172,6 +1178,9 @@ func (s *state) endBlock() *ssa.Block {
11721178
b.Pos = src.NoXPos
11731179
} else {
11741180
b.Pos = s.lastPos
1181+
if s.blockStarts[b.ID] == src.NoXPos {
1182+
s.blockStarts[b.ID] = s.lastPos
1183+
}
11751184
}
11761185
return b
11771186
}
@@ -1188,6 +1197,11 @@ func (s *state) pushLine(line src.XPos) {
11881197
} else {
11891198
s.lastPos = line
11901199
}
1200+
// The first position we see for a new block is its starting position
1201+
// (the line number for its phis, if any).
1202+
if b := s.curBlock; b != nil && s.blockStarts[b.ID] == src.NoXPos {
1203+
s.blockStarts[b.ID] = line
1204+
}
11911205

11921206
s.line = append(s.line, line)
11931207
}

0 commit comments

Comments
 (0)