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/compile: off-by-many in line number reported for compile error #8836

Closed
dominikh opened this issue Sep 29, 2014 · 5 comments
Closed

cmd/compile: off-by-many in line number reported for compile error #8836

dominikh opened this issue Sep 29, 2014 · 5 comments
Milestone

Comments

@dominikh
Copy link
Member

What does 'go version' print?
go version go1.3.2 linux/amd64

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

1. Compile http://play.golang.org/p/V41ws9TExS
2.
3.

What happened?
# _/tmp/foo
./foobar.go:12: cannot use 42 (type int) as type *C.int in argument to _Cfunc_foobar


What should have happened instead?
# _/tmp/foo
./foobar.go:15: cannot use 42 (type int) as type *C.int in argument to _Cfunc_foobar

Please provide any additional information below.
The error is always reported for line 12, even if more arguments are added to the
function. If the first argument of foobar is changed from int* to int, (and the call
adjusted appropriately), the error is instead reported for line 16, which is another
off-by-one error.
@ianlancetaylor
Copy link
Contributor

Comment 1:

Labels changed: added repo-main, release-go1.5.

Status changed to Accepted.

@ianlancetaylor
Copy link
Contributor

Comment 2:

Actually this has nothing to do with cgo, the Go compiler has the same problem.
http://play.golang.org/p/XgU4-2ryvT

@bradfitz bradfitz modified the milestone: Go1.5 Dec 16, 2014
@rsc rsc removed accepted labels Apr 14, 2015
@rsc
Copy link
Contributor

rsc commented May 19, 2015

@dr2chase another

@dr2chase
Copy link
Contributor

This looks intractable and annoying -- I think the root cause is our tendency to sometimes construct ASTs that aren't trees, so that when an argument to a function call is a shared node in the AST its line number is not trustworthy. It is possible to get it right for numbers, but not for boolean constants true and false.

You can see the hackiness in setlineno around line 230 of subr.go; that uses the line number of a node to set the global lineno (a hack in itself if you ask me) but only when the node is not a ONAME, OTYPE, OPACK, or OLITERAL.

@rsc rsc changed the title cmd/gc: off-by-many in line number reported for compile error cmd/compile: off-by-many in line number reported for compile error Jun 8, 2015
@gopherbot
Copy link

CL https://golang.org/cl/11672 mentions this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants