aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cmd/compile/internal/escape/escape.go11
-rw-r--r--src/cmd/compile/internal/ssa/debug_lines_test.go21
-rw-r--r--src/cmd/compile/internal/ssa/testdata/i74576a.go17
-rw-r--r--src/cmd/compile/internal/ssa/testdata/i74576b.go15
-rw-r--r--src/cmd/compile/internal/ssa/testdata/i74576c.go19
5 files changed, 77 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/escape/escape.go b/src/cmd/compile/internal/escape/escape.go
index ae6941a097..6b34830b3d 100644
--- a/src/cmd/compile/internal/escape/escape.go
+++ b/src/cmd/compile/internal/escape/escape.go
@@ -539,9 +539,8 @@ func (b *batch) rewriteWithLiterals(n ir.Node, fn *ir.Func) {
return
}
- assignTemp := func(n ir.Node, init *ir.Nodes) {
+ assignTemp := func(pos src.XPos, n ir.Node, init *ir.Nodes) {
// Preserve any side effects of n by assigning it to an otherwise unused temp.
- pos := n.Pos()
tmp := typecheck.TempAt(pos, fn, n.Type())
init.Append(typecheck.Stmt(ir.NewDecl(pos, ir.ODCL, tmp)))
init.Append(typecheck.Stmt(ir.NewAssignStmt(pos, tmp, n)))
@@ -575,8 +574,8 @@ func (b *batch) rewriteWithLiterals(n ir.Node, fn *ir.Func) {
return
}
// Preserve any side effects of the original expression, then replace it.
- assignTemp(*r, n.PtrInit())
- *r = lit
+ assignTemp(n.Pos(), *r, n.PtrInit())
+ *r = ir.NewBasicLit(n.Pos(), (*r).Type(), lit.Val())
}
}
}
@@ -601,9 +600,9 @@ func (b *batch) rewriteWithLiterals(n ir.Node, fn *ir.Func) {
base.WarnfAt(n.Pos(), "rewriting OCONVIFACE value from %v (%v) to %v (%v)", conv.X, conv.X.Type(), v, v.Type())
}
// Preserve any side effects of the original expression, then replace it.
- assignTemp(conv.X, conv.PtrInit())
+ assignTemp(conv.Pos(), conv.X, conv.PtrInit())
v := v.(*ir.BasicLit)
- conv.X = ir.NewBasicLit(conv.X.Pos(), conv.X.Type(), v.Val())
+ conv.X = ir.NewBasicLit(conv.Pos(), conv.X.Type(), v.Val())
typecheck.Expr(conv)
}
}
diff --git a/src/cmd/compile/internal/ssa/debug_lines_test.go b/src/cmd/compile/internal/ssa/debug_lines_test.go
index 857cce785f..5ca844403e 100644
--- a/src/cmd/compile/internal/ssa/debug_lines_test.go
+++ b/src/cmd/compile/internal/ssa/debug_lines_test.go
@@ -115,6 +115,24 @@ func TestDebugLines_53456(t *testing.T) {
testDebugLinesDefault(t, "-N -l", "b53456.go", "(*T).Inc", []int{15, 16, 17, 18}, true)
}
+func TestDebugLines_74576(t *testing.T) {
+ tests := []struct {
+ file string
+ wantStmts []int
+ }{
+ {"i74576a.go", []int{12, 13, 13, 14}},
+ {"i74576b.go", []int{12, 13, 13, 14}},
+ {"i74576c.go", []int{12, 13, 13, 14}},
+ }
+ t.Parallel()
+ for _, test := range tests {
+ t.Run(test.file, func(t *testing.T) {
+ t.Parallel()
+ testDebugLines(t, "-N -l", test.file, "main", test.wantStmts, false)
+ })
+ }
+}
+
func compileAndDump(t *testing.T, file, function, moreGCFlags string) []byte {
testenv.MustHaveGoBuild(t)
@@ -223,6 +241,9 @@ func testInlineStack(t *testing.T, file, function string, wantStacks [][]int) {
// then verifies that the statement-marked lines in that file are the same as those in wantStmts
// These files must all be short because this is super-fragile.
// "go build" is run in a temporary directory that is normally deleted, unless -test.v
+//
+// TODO: the tests calling this are somewhat expensive; perhaps more tests can be marked t.Parallel,
+// or perhaps the mechanism here can be made more efficient.
func testDebugLines(t *testing.T, gcflags, file, function string, wantStmts []int, ignoreRepeats bool) {
dumpBytes := compileAndDump(t, file, function, gcflags)
dump := bufio.NewScanner(bytes.NewReader(dumpBytes))
diff --git a/src/cmd/compile/internal/ssa/testdata/i74576a.go b/src/cmd/compile/internal/ssa/testdata/i74576a.go
new file mode 100644
index 0000000000..40bb7b6069
--- /dev/null
+++ b/src/cmd/compile/internal/ssa/testdata/i74576a.go
@@ -0,0 +1,17 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+ "runtime"
+)
+
+func main() {
+ a := 1
+ runtime.Breakpoint()
+ sink = a
+}
+
+var sink any
diff --git a/src/cmd/compile/internal/ssa/testdata/i74576b.go b/src/cmd/compile/internal/ssa/testdata/i74576b.go
new file mode 100644
index 0000000000..fa89063299
--- /dev/null
+++ b/src/cmd/compile/internal/ssa/testdata/i74576b.go
@@ -0,0 +1,15 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+ "runtime"
+)
+
+func main() {
+ a := 1
+ runtime.Breakpoint()
+ _ = make([]int, a)
+}
diff --git a/src/cmd/compile/internal/ssa/testdata/i74576c.go b/src/cmd/compile/internal/ssa/testdata/i74576c.go
new file mode 100644
index 0000000000..92cacaf0d7
--- /dev/null
+++ b/src/cmd/compile/internal/ssa/testdata/i74576c.go
@@ -0,0 +1,19 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+ "runtime"
+)
+
+func main() {
+ s := S{1, 1}
+ runtime.Breakpoint()
+ sink = s
+}
+
+type S struct{ a, b uint64 }
+
+var sink any