-
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: cgo parameter type mismatch between generated go wrapper and call to wrapper #40494
Comments
Thanks, I can reproduce this. Looking. |
Here's a minimal, standalone reproducer for the issue:
Still looking into this. I'm thinking the fix may be to change |
Change https://golang.org/cl/246057 mentions this issue: |
@somersf CL 246057 fixes your test case for me. Do you mind verifying that it fixes your original issue? @aclements I think @ianlancetaylor is out this week. I don't know if this can wait until Monday, or if I should find someone else to review/approve it before then? |
@mdempsky Thanks for the prompt investigation
That CL passes for the original package where I hit the issue. I've kicked off a test across the full codebase, but it'll need overnight to complete. |
@somersf Great, thank you for the confirmation. I've submitted the fix. If your overnight testing reveals any further issues, please let us know. |
An example cgo program which passes an
enum
and aunion
to an external C function previously compiled successfully, but fails to compile with go1.15rc1.Example code is provided below with concrete types/signatures, but in summary:
enum
parameter was simplified to auint32
in the generated go wrapper for the C function, and also in the generated go code which calls the wrapper. Similarly, aunion
was simplified to a*[num]byte
.enum
andunion
are simplified in the generated go wrapper for the C function, but are not simplified in the generated go code which calls the wrapper, leading to type mismatch errors.What version of Go are you using (
go version
)?( also with GOARCH=amd64 )
Does this issue reproduce with the latest release?
The example fails with compilation errors with go1.15rc1 but compiles successfully with multiple versions <= go1.14.6.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Here is a fairly minimal example for an
apply
package, consisting ofapply.go
,apply.h
andapply.cpp
. It was built usinggo build .
within theapply
package directory.apply.go
apply.h
apply.cpp
What did you expect to see?
Compiling with go1.14.6 is successful, so I'd expected it would also succeed with go1.15rc1.
What did you see instead?
Inspecting the go build cache, I found the generated C function wrapper:
and the generated call from apply.go to it (line-wrapped):
This fails to compile because the call parameter types (which do match the C declaration) don't match the generated go wrapper definition.
For comparison, the go1.14.6 generated C function wrapper is essentially the same (the
_Cfunc_Apply
signature matches exactly, but there are other differences in the same file), but the call from apply.go differs (line-wrapped):In go1.14, the compiler has emitted call parameter types which match the generated wrapper.
Presumably the correct thing to do would be for compiler to use the correct rather than simplified type names for both the generated C function wrapper and the calls to that wrapper (or at least be consistent).
The text was updated successfully, but these errors were encountered: