Skip to content

Commit 4c8589c

Browse files
committed
cmd/compile: attach correct line number for fallthru-return
Fixes #14646. Change-Id: I0bb82ed6d3533633cd8369ba37aa467948bbe155 Reviewed-on: https://go-review.googlesource.com/20381 Run-TryBot: David Chase <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent 1264f6e commit 4c8589c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func buildssa(fn *Node) *ssa.Func {
180180
s.stmts(s.exitCode)
181181
m := s.mem()
182182
b := s.endBlock()
183+
b.Line = fn.Func.Endlineno
183184
b.Kind = ssa.BlockRet
184185
b.Control = m
185186
}

test/fixedbugs/issue14646.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// run
2+
3+
// Copyright 2016 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
import "runtime"
10+
11+
func main() {
12+
var file string
13+
var line int
14+
func() {
15+
defer func() {
16+
_, file, line, _ = runtime.Caller(1)
17+
}()
18+
}() // this is the expected line
19+
const EXPECTED = 18
20+
if line != EXPECTED {
21+
println("Expected line =", EXPECTED, "but got line =", line, "and file =", file)
22+
}
23+
}

0 commit comments

Comments
 (0)