Skip to content

Commit 1d17b26

Browse files
committed
Add support for opaque pointers and structs
1 parent 8e7ec80 commit 1d17b26

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ir.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ func (t Type) StructSetBody(elementTypes []Type, packed bool) {
665665
}
666666

667667
func (t Type) IsStructPacked() bool { return C.LLVMIsPackedStruct(t.C) != 0 }
668+
func (t Type) IsStructOpaque() bool { return C.LLVMIsOpaqueStruct(t.C) != 0 }
668669
func (t Type) StructElementTypesCount() int { return int(C.LLVMCountStructElementTypes(t.C)) }
669670
func (t Type) StructElementTypes() []Type {
670671
out := make([]Type, t.StructElementTypesCount())
@@ -676,7 +677,12 @@ func (t Type) StructElementTypes() []Type {
676677

677678
// Operations on array, pointer, and vector types (sequence types)
678679
func (t Type) Subtypes() (ret []Type) {
679-
ret = make([]Type, C.LLVMGetNumContainedTypes(t.C))
680+
num := C.LLVMGetNumContainedTypes(t.C)
681+
if num == 0 {
682+
// prevent a crash at &ret[0] if there are no subtypes
683+
return nil
684+
}
685+
ret = make([]Type, num)
680686
C.LLVMGetSubtypes(t.C, llvmTypeRefPtr(&ret[0]))
681687
return
682688
}
@@ -694,6 +700,7 @@ func VectorType(elementType Type, elementCount int) (t Type) {
694700
return
695701
}
696702

703+
func (t Type) IsPointerOpaque() bool { return C.LLVMPointerTypeIsOpaque(t.C) != 0 }
697704
func (t Type) ElementType() (rt Type) { rt.C = C.LLVMGetElementType(t.C); return }
698705
func (t Type) ArrayLength() int { return int(C.LLVMGetArrayLength(t.C)) }
699706
func (t Type) PointerAddressSpace() int { return int(C.LLVMGetPointerAddressSpace(t.C)) }

0 commit comments

Comments
 (0)