Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: panic: overlapping edits #33061

Closed
zeldovich opened this issue Jul 11, 2019 · 8 comments

Comments

@zeldovich
Copy link

commented Jul 11, 2019

What version of Go are you using (go version)?

$ go version
go version devel +80cca23b59 Wed Jul 10 21:26:21 2019 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/nickolai/.cache/go-build"
GOENV="/home/nickolai/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/nickolai/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/nickolai/tmp/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/nickolai/tmp/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build157323227=/tmp/go-build -gno-record-gcc-switches"

What did you do?

% cat cgo-panic.go
package p

// #include 
import "C"

func f() {
	C.free(0, C.size_t(0))
}
% go build cgo-panic.go
# command-line-arguments
panic: overlapping edits: [58,80)->"func() { _cgo0 := /*line :7:9*/0; _cgoCheckPointer(_cgo0); _Cfunc_free(_cgo0); }()", [68,76)->" /*line :7:12*/_Ctype_size_t /*line :7:20*/"

goroutine 1 [running]:
cmd/internal/edit.(*Buffer).Bytes(0xc000086960, 0xc00000e148, 0x602de7, 0xe)
	/home/nickolai/tmp/go/src/cmd/internal/edit/edit.go:79 +0x598
main.(*Package).writeOutput(0xc0000c8000, 0xc0000ba140, 0x7fff391c7ff5, 0x11)
	/home/nickolai/tmp/go/src/cmd/cgo/out.go:597 +0x38d
main.main()
	/home/nickolai/tmp/go/src/cmd/cgo/main.go:356 +0xce3
% 

What did you expect to see?

No panic messages.

What did you see instead?

A panic message.

@zeldovich

This comment has been minimized.

Copy link
Author

commented Jul 11, 2019

It looks like I failed to properly quote certain characters in my initial bug report, so here it is formatted with Markdown, which should do the right thing with < and > symbols:

% cat cgo-panic.go
package p

// #include <stdlib.h>
import "C"

func f() {
    C.free(0, C.size_t(0))
}
% go build cgo-panic.go
# command-line-arguments
panic: overlapping edits: [58,80)->"func() { _cgo0 := /*line :7:9*/0; _cgoCheckPointer(_cgo0); _Cfunc_free(_cgo0); }()", [68,76)->" /*line :7:12*/_Ctype_size_t /*line :7:20*/"

goroutine 1 [running]:
cmd/internal/edit.(*Buffer).Bytes(0xc000086960, 0xc00000e148, 0x602de7, 0xe)
    /home/nickolai/tmp/go/src/cmd/internal/edit/edit.go:79 +0x598
main.(*Package).writeOutput(0xc0000c8000, 0xc0000ba140, 0x7fff391c7ff5, 0x11)
    /home/nickolai/tmp/go/src/cmd/cgo/out.go:597 +0x38d
main.main()
    /home/nickolai/tmp/go/src/cmd/cgo/main.go:356 +0xce3
%
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 11, 2019

It's kind of a terrible error message, but note that your program is invalid. C.free takes only a single argument.

@ianlancetaylor ianlancetaylor changed the title cgo: panic: overlapping edits cmd/cgo: panic: overlapping edits Jul 11, 2019

@zeldovich

This comment has been minimized.

Copy link
Author

commented Jul 11, 2019

Indeed, I just minimized this to a simple reproducing case. The original program was much larger, and the bad error message made it difficult to track down what was wrong (it was also some C function being called with the wrong number of arguments).

@gopherbot

This comment has been minimized.

Copy link

commented Jul 11, 2019

Change https://golang.org/cl/185797 mentions this issue: cmd/cgo: do not rewrite call if there are more args than parameters

@gopherbot gopherbot closed this in e831719 Jul 12, 2019

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 12, 2019

@gopherbot Please open a backport issue for 1.12.

@gopherbot

This comment has been minimized.

Copy link

commented Jul 12, 2019

Backport issue(s) opened: #33081 (for 1.12).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

@gopherbot

This comment has been minimized.

Copy link

commented Jul 12, 2019

Backport issue(s) opened: #33082 (for 1.12).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

@gopherbot

This comment has been minimized.

Copy link

commented Jul 12, 2019

Change https://golang.org/cl/185997 mentions this issue: [release-branch.go1.12] cmd/cgo: do not rewrite call if there are more args than parameters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.