diff options
| author | Ian Lance Taylor <iant@golang.org> | 2016-01-07 15:22:39 -0800 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2016-01-08 03:56:30 +0000 |
| commit | d91ec5bb40bac5ce2c8136110c52723b35476985 (patch) | |
| tree | 18164c27c315f22ce0f3ce337249b2297dd2aa0d /misc/cgo/errors/ptr.go | |
| parent | e84dad3f6e394f15739db46d9f319f94a1537667 (diff) | |
| download | go-d91ec5bb40bac5ce2c8136110c52723b35476985.tar.xz | |
cmd/cgo, runtime: recognize unsafe.Pointer(&s[0]) in cgo pointer checks
It's fairly common to call cgo functions with conversions to
unsafe.Pointer or other C types. Apply the simpler checking of address
expressions when possible when the address expression occurs within a
type conversion.
Change-Id: I5187d4eb4d27a6542621c396cad9ee4b8647d1cd
Reviewed-on: https://go-review.googlesource.com/18391
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'misc/cgo/errors/ptr.go')
| -rw-r--r-- | misc/cgo/errors/ptr.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/misc/cgo/errors/ptr.go b/misc/cgo/errors/ptr.go index 1534601524..0dd291f5ed 100644 --- a/misc/cgo/errors/ptr.go +++ b/misc/cgo/errors/ptr.go @@ -107,6 +107,16 @@ var ptrTests = []ptrTest{ fail: false, }, { + // Passing the address of a slice of an array that is + // an element in a struct, with a type conversion. + name: "slice-ok-3", + c: `void f(void* p) {}`, + imports: []string{"unsafe"}, + support: `type S struct { p *int; a [4]byte }`, + body: `i := 0; p := &S{p:&i}; s := p.a[:]; C.f(unsafe.Pointer(&s[0]))`, + fail: false, + }, + { // Passing the address of a static variable with no // pointers doesn't matter. name: "varok", |
