File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,16 @@ var ptrTests = []ptrTest{
122
122
body : `i := 0; p := &S{p:&i}; s := p.a[:]; C.f(unsafe.Pointer(&s[0]))` ,
123
123
fail : false ,
124
124
},
125
+ {
126
+ // Passing the address of a slice of an array that is
127
+ // an element in a struct, with a type conversion.
128
+ name : "slice-ok-4" ,
129
+ c : `typedef void* PV; void f(PV p) {}` ,
130
+ imports : []string {"unsafe" },
131
+ support : `type S struct { p *int; a [4]byte }` ,
132
+ body : `i := 0; p := &S{p:&i}; C.f(C.PV(unsafe.Pointer(&p.a[0])))` ,
133
+ fail : false ,
134
+ },
125
135
{
126
136
// Passing the address of a static variable with no
127
137
// pointers doesn't matter.
Original file line number Diff line number Diff line change @@ -819,14 +819,17 @@ func (p *Package) hasSideEffects(f *File, x ast.Expr) bool {
819
819
func (p * Package ) isType (t ast.Expr ) bool {
820
820
switch t := t .(type ) {
821
821
case * ast.SelectorExpr :
822
- if t .Sel .Name != "Pointer" {
823
- return false
824
- }
825
822
id , ok := t .X .(* ast.Ident )
826
823
if ! ok {
827
824
return false
828
825
}
829
- return id .Name == "unsafe"
826
+ if id .Name == "unsafe" && t .Sel .Name == "Pointer" {
827
+ return true
828
+ }
829
+ if id .Name == "C" && typedef ["_Ctype_" + t .Sel .Name ] != nil {
830
+ return true
831
+ }
832
+ return false
830
833
case * ast.Ident :
831
834
// TODO: This ignores shadowing.
832
835
switch t .Name {
You can’t perform that action at this time.
0 commit comments