]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use block starting position for phi line number
authorKeith Randall <khr@golang.org>
Wed, 8 Oct 2025 22:33:19 +0000 (15:33 -0700)
committerKeith Randall <khr@golang.org>
Wed, 15 Oct 2025 16:13:12 +0000 (09:13 -0700)
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>

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

index 8cd11e9828e0f9b92f41836d4b4a9f375ae23539..d0f09da86ffce2b36b8cba4fc5b3c5f88d400fa0 100644 (file)
@@ -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() {
index 19b6920913d83c9f0bdd42a9bebb92cc8d01393d..0dcf353bf4308932692a71f916b38194d0994518 100644 (file)
@@ -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
index e2ef33274577cce8b489886e43ac0ee73a0ae718..ae7d57566f7e0defe86b3de2591e0dc739f00ed5 100644 (file)
@@ -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)
 }