Commit 07a22dbd authored by Alan Donovan's avatar Alan Donovan

cmd/vet: cgo: emit no error for calls to C.CBytes

Fixes issue golang/go#17563

Change-Id: Ibb41ea9419907193526cc601f6afd07d8689b1fe
Reviewed-on: https://go-review.googlesource.com/31810Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 2a3db5c0
......@@ -38,6 +38,11 @@ func checkCgoCall(f *File, node ast.Node) {
return
}
// A call to C.CBytes passes a pointer but is always safe.
if sel.Sel.Name == "CBytes" {
return
}
for _, arg := range x.Args {
if !typeOKForCgoCall(cgoBaseType(f, arg)) {
f.Badf(arg.Pos(), "possibly passing Go type with embedded pointer to C")
......
......@@ -51,4 +51,6 @@ func CgoTests() {
var st2 struct{ i int }
C.f(*(*unsafe.Pointer)(unsafe.Pointer(&st2)))
C.f(unsafe.Pointer(&st2))
C.CBytes([]byte("hello"))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment