-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: generate correct column info #26745
Comments
If I understand you correctly, in generation of the new files we add a comment of the original line so we can track where the error happened? Your last line was a bit unclear.. Anyway sounds like a pretty quick fix I can do if it's what I think it is. |
As of 1.11 cmd/compile supports using That said I recommend that you not work on cgo code today, because for 1.12 I may try to add https://golang.org/cl/120615, which will substantially change how cgo's code generation works. If you change the cmd/internal/edit package to support adding |
So I should try looking at passing the mechanism from cgo to cover? |
Both cmd/cgo and cmd/cover use cmd/internal/edit. If cmd/internal/edit can add |
@ianlancetaylor Just so I'll know I'm in the right direction |
Line 525 is |
@ianlancetaylor //line FILE:1
fmt.Println(C.C_func(5)) We want to do: fmt.Println(/*line FILE:1:13*/C.C_func(5)) That's what I understood from:
Right? And do you want me to add a function in edit.go that is specifically for that and then use it in cgo and cover? |
@ianlancetaylor After mangling the names we edit the current file so it has the new mangled name instead of the original. Edit: specifically, because we have the file object and the pos object we can just get the string by calling f.Position(pos).String() |
I was thinking we should change cmd/internal/edit because then we will fix both cmd/cover and cmd/cgo at the same time. But if it turns out to be simpler to do it in cgo directly, that is OK too. |
I think we should fix it in cgo and cover separately, because edit in supposed to be a generic byte buffer editor, but it's your call. |
I would have to see the change. |
I can't seem to reproduce this issue. package main
//int a = 234;
//int b = 0;
/*
int div(int x, int y){
return x / y;
}
*/
import (
"C"
)
import "fmt"
func main() {
fmt.Println(C.a / C.b)
} Output of
Output of On which errors does this issue occur? I need steps to reproduce so I'll know where to look, because so far the only place I saw that a fix should be inserted in is |
This change would only affect compilation errors, not run time errors. Here is an example: package p
// int a;
import "C"
func F(i int) int {
return C.a + i
} When I try build this today, I get foo.go:7:20: invalid operation: *_Cvar_a + i (mismatched types _Ctype_int and int) The column number 20 is incorrect. Line 7 has only 16 columns. The column number should be 13. |
@ianlancetaylor // Code generated by cmd/cgo; DO NOT EDIT.
//line C:/Users/oryan/go/src/github.com/oryanmoshe/cgotest/main.go:1:1
package main
// int a;
import _ "unsafe"
func main() {
F(5)
}
func F(i int) int {
return /*line :11:9*/(*_Cvar_a) + i
} But the error is still Do you have any idea what might have went wrong? Is it possible the new Edit: It's the same if I add the filename for the first argument in the line comment |
Pretty sure the Try fiddling with the number you emit to see whether the comments work properly. |
According to the docs:
Anyway, I tried putting it after the var and it worked (sort of?)! Now the error message is About the documentation, should I edit it? |
As far as I can see the docs are correct. The issue here is that the original code says The correct column number for the error in my example is the one that matches the |
But the error message contains the mangled name, not the original name. Should I fix it too? I think I understand the problem, we want the line comment to be after the cvar, but I need to add 3 to the col (because len(C.a) === 3) and then it'll be in the right position according to your count. Are you sure the docs are correct? It says the line directive specifies the position for the character immediately following the directive, not precsiding it.. But I might be understanding it upside down |
The fact that the error messages contains the mangled name is a separate bug that should be fixed separately. It's supposed to be handled by I expect that the docs are correct. Note that column numbers start at 1. |
Change https://golang.org/cl/128036 mentions this issue: |
Change https://golang.org/cl/151598 mentions this issue: |
The cgo tool reads input files written in Go referring to the magic import "C" and writes new files written in Go that use mangled names. cgo preserves line breaks, so errors reported in the new file have the correct line numbers, but they do not have correct column information. That is, column numbers in error reports about user written code will refer to the newly generated code, not the original user written code. We should the new
/*line*/
comments to get correct column information.The text was updated successfully, but these errors were encountered: