From 0ad74fd1dcb278b7d9348e9c8a46152bdab4c376 Mon Sep 17 00:00:00 2001 From: Patrick Pokatilo Date: Mon, 29 Nov 2021 07:22:15 +0000 Subject: [PATCH] cmd/cgo: add line info for return statements When calling a C function, line information will be incorrect if the function call's closing parenthesis is not on the same line as the last argument. We add a comment with the line info for the return statement to guide debuggers to the correct line. Fixes #49839. Change-Id: I8bc2ce35fec9cbcafbbe8536d5a79dc487eb24bb GitHub-Last-Rev: 8b28646d2e25b19272ded7a3d54b9374108a54e2 GitHub-Pull-Request: golang/go#49840 Reviewed-on: https://go-review.googlesource.com/c/go/+/367454 Reviewed-by: David Chase Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor --- src/cmd/cgo/gcc.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index a469afa8dd..855309edfa 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -811,6 +811,7 @@ func (p *Package) rewriteCall(f *File, call *Call) (string, bool) { params := name.FuncType.Params args := call.Call.Args + end := call.Call.End() // Avoid a crash if the number of arguments doesn't match // the number of parameters. @@ -958,7 +959,7 @@ func (p *Package) rewriteCall(f *File, call *Call) (string, bool) { if nu { needsUnsafe = true } - sb.WriteString(gofmtLine(m)) + sb.WriteString(gofmtPos(m, end)) sb.WriteString("(") for i := range params { -- 2.50.0