diff --git a/loader/libclang.go b/loader/libclang.go index 6166e156..0017489e 100644 --- a/loader/libclang.go +++ b/loader/libclang.go @@ -307,9 +307,23 @@ func (info *fileInfo) makeASTType(typ C.CXType) ast.Expr { typeName = "complex128" } case C.CXType_Pointer: + pointeeType := C.clang_getPointeeType(typ) + if pointeeType.kind == C.CXType_Void { + // void* type is translated to Go as unsafe.Pointer + return &ast.SelectorExpr{ + X: &ast.Ident{ + NamePos: info.importCPos, + Name: "unsafe", + }, + Sel: &ast.Ident{ + NamePos: info.importCPos, + Name: "Pointer", + }, + } + } return &ast.StarExpr{ Star: info.importCPos, - X: info.makeASTType(C.clang_getPointeeType(typ)), + X: info.makeASTType(pointeeType), } case C.CXType_ConstantArray: return &ast.ArrayType{ diff --git a/testdata/cgo/main.c b/testdata/cgo/main.c index 1d144a02..6f52749f 100644 --- a/testdata/cgo/main.c +++ b/testdata/cgo/main.c @@ -9,6 +9,8 @@ _Complex float globalComplexFloat = 4.1+3.3i; _Complex double globalComplexDouble = 4.2+3.4i; _Complex double globalComplexLongDouble = 4.3+3.5i; char globalChar = 100; +void *globalVoidPtrSet = &global; +void *globalVoidPtrNull; collection_t globalStruct = {256, -123456, 3.14, 88}; int globalStructSize = sizeof(globalStruct); short globalArray[3] = {5, 6, 7}; diff --git a/testdata/cgo/main.go b/testdata/cgo/main.go index ae95943a..0e85fc09 100644 --- a/testdata/cgo/main.go +++ b/testdata/cgo/main.go @@ -41,6 +41,8 @@ func main() { println("complex double:", C.globalComplexDouble) println("complex long double:", C.globalComplexLongDouble) println("char match:", C.globalChar == 100) + var voidPtr unsafe.Pointer = C.globalVoidPtrNull + println("void* match:", voidPtr == nil, C.globalVoidPtrNull == nil, (*C.int)(C.globalVoidPtrSet) == &C.global) // complex types println("struct:", C.int(unsafe.Sizeof(C.globalStruct)) == C.globalStructSize, C.globalStruct.s, C.globalStruct.l, C.globalStruct.f) diff --git a/testdata/cgo/main.h b/testdata/cgo/main.h index 8c09fe9b..a7b3b75a 100644 --- a/testdata/cgo/main.h +++ b/testdata/cgo/main.h @@ -37,6 +37,8 @@ extern _Complex float globalComplexFloat; extern _Complex double globalComplexDouble; extern _Complex double globalComplexLongDouble; extern char globalChar; +extern void *globalVoidPtrSet; +extern void *globalVoidPtrNull; extern collection_t globalStruct; extern int globalStructSize; extern short globalArray[3]; diff --git a/testdata/cgo/out.txt b/testdata/cgo/out.txt index df481edf..2e799e60 100644 --- a/testdata/cgo/out.txt +++ b/testdata/cgo/out.txt @@ -15,6 +15,7 @@ complex float: (+4.100000e+000+3.300000e+000i) complex double: (+4.200000e+000+3.400000e+000i) complex long double: (+4.300000e+000+3.500000e+000i) char match: true +void* match: true true true struct: true 256 -123456 +3.140000e+000 array: 5 6 7 union: true