body: `s := struct { a [4]byte; p *int }{p: new(int)}; C.f43(unsafe.Pointer(unsafe.SliceData(s.a[:])))`,
fail: false,
},
+ {
+ // Passing the address of an element of a pointer-to-array.
+ name: "arraypointer",
+ c: `void f44(void* p) {}`,
+ imports: []string{"unsafe"},
+ body: `a := new([10]byte); C.f44(unsafe.Pointer(&a[0]))`,
+ fail: false,
+ },
+ {
+ // Passing the address of an element of a pointer-to-array
+ // that contains a Go pointer.
+ name: "arraypointer2",
+ c: `void f45(void** p) {}`,
+ imports: []string{"unsafe"},
+ body: `i := 0; a := &[2]unsafe.Pointer{nil, unsafe.Pointer(&i)}; C.f45(&a[0])`,
+ fail: true,
+ },
}
func TestPointerChecks(t *testing.T) {
ep = aep
t = ep._type
top = false
+ case abi.Pointer:
+ // The Go code is indexing into a pointer to an array,
+ // and we have been passed the pointer-to-array.
+ // Check the array rather than the pointer.
+ pt := (*abi.PtrType)(unsafe.Pointer(aep._type))
+ t = pt.Elem
+ if t.Kind_&abi.KindMask != abi.Array {
+ throw("can't happen")
+ }
+ ep = aep
+ top = false
default:
throw("can't happen")
}