@@ -665,6 +665,7 @@ func (t Type) StructSetBody(elementTypes []Type, packed bool) {
665
665
}
666
666
667
667
func (t Type ) IsStructPacked () bool { return C .LLVMIsPackedStruct (t .C ) != 0 }
668
+ func (t Type ) IsStructOpaque () bool { return C .LLVMIsOpaqueStruct (t .C ) != 0 }
668
669
func (t Type ) StructElementTypesCount () int { return int (C .LLVMCountStructElementTypes (t .C )) }
669
670
func (t Type ) StructElementTypes () []Type {
670
671
out := make ([]Type , t .StructElementTypesCount ())
@@ -676,7 +677,12 @@ func (t Type) StructElementTypes() []Type {
676
677
677
678
// Operations on array, pointer, and vector types (sequence types)
678
679
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 )
680
686
C .LLVMGetSubtypes (t .C , llvmTypeRefPtr (& ret [0 ]))
681
687
return
682
688
}
@@ -694,6 +700,7 @@ func VectorType(elementType Type, elementCount int) (t Type) {
694
700
return
695
701
}
696
702
703
+ func (t Type ) IsPointerOpaque () bool { return C .LLVMPointerTypeIsOpaque (t .C ) != 0 }
697
704
func (t Type ) ElementType () (rt Type ) { rt .C = C .LLVMGetElementType (t .C ); return }
698
705
func (t Type ) ArrayLength () int { return int (C .LLVMGetArrayLength (t .C )) }
699
706
func (t Type ) PointerAddressSpace () int { return int (C .LLVMGetPointerAddressSpace (t .C )) }
0 commit comments