Index: llvm/bindings/ocaml/llvm/llvm_ocaml.c =================================================================== --- llvm/bindings/ocaml/llvm/llvm_ocaml.c +++ llvm/bindings/ocaml/llvm/llvm_ocaml.c @@ -587,45 +587,45 @@ /* lltype -> int */ value llvm_array_length(LLVMTypeRef ArrayTy) { - return Val_int(LLVMGetArrayLength(ArrayTy)); + return Val_int(LLVMGetArrayLength2(ArrayTy)); } /* lltype -> int */ value llvm_address_space(LLVMTypeRef PtrTy) { return Val_int(LLVMGetPointerAddressSpace(PtrTy)); } /* lltype -> int */ value llvm_vector_size(LLVMTypeRef VectorTy) { return Val_int(LLVMGetVectorSize(VectorTy)); } /*--... Operations on other types ..........................................--*/ /* llcontext -> lltype */ LLVMTypeRef llvm_void_type(LLVMContextRef Context) { return LLVMVoidTypeInContext(Context); } /* llcontext -> lltype */ LLVMTypeRef llvm_label_type(LLVMContextRef Context) { return LLVMLabelTypeInContext(Context); } /* llcontext -> lltype */ LLVMTypeRef llvm_x86_mmx_type(LLVMContextRef Context) { return LLVMX86MMXTypeInContext(Context); } value llvm_type_by_name(LLVMModuleRef M, value Name) { return ptr_to_option(LLVMGetTypeByName(M, String_val(Name))); } /*===-- VALUES ------------------------------------------------------------===*/ /* llvalue -> lltype */ LLVMTypeRef llvm_type_of(LLVMValueRef Val) { return LLVMTypeOf(Val); } /* keep in sync with ValueKind.t */ enum ValueKind { NullValue = 0, Index: llvm/include/llvm-c/Core.h =================================================================== --- llvm/include/llvm-c/Core.h +++ llvm/include/llvm-c/Core.h @@ -1437,19 +1437,40 @@ * The created type will exist in the context that its element type * exists in. * + * @deprecated LLVMArrayType is deprecated in favor of the API accurate LLVMArrayType2 * @see llvm::ArrayType::get() */ LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount); +/** + * Create a fixed size array type that refers to a specific type. + * + * The created type will exist in the context that its element type + * exists in. + * + * @see llvm::ArrayType::get() + */ +LLVMTypeRef LLVMArrayType2(LLVMTypeRef ElementType, uint64_t ElementCount); + /** * Obtain the length of an array type. * * This only works on types that represent arrays. * + * @deprecated LLVMGetArrayLength is deprecated in favor of the API accurate LLVMGetArrayLength2 * @see llvm::ArrayType::getNumElements() */ unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy); +/** + * Obtain the length of an array type. + * + * This only works on types that represent arrays. + * + * @see llvm::ArrayType::getNumElements() + */ +uint64_t LLVMGetArrayLength2(LLVMTypeRef ArrayTy); + /** * Create a pointer type that points to a defined type. * @@ -2118,11 +2139,19 @@ /** * Create a ConstantArray from values. * + * @deprecated LLVMConstArray is deprecated in favor of the API accurate LLVMConstArray2 * @see llvm::ConstantArray::get() */ LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy, LLVMValueRef *ConstantVals, unsigned Length); +/** + * Create a ConstantArray from values. + * + * @see llvm::ConstantArray::get() + */ +LLVMValueRef LLVMConstArray2(LLVMTypeRef ElementTy, LLVMValueRef *ConstantVals, uint64_t Length); + /** * Create a non-anonymous ConstantStruct from values. * Index: llvm/lib/IR/Core.cpp =================================================================== --- llvm/lib/IR/Core.cpp +++ llvm/lib/IR/Core.cpp @@ -788,23 +788,27 @@ return wrap(ArrayType::get(unwrap(ElementType), ElementCount)); } +LLVMTypeRef LLVMArrayType2(LLVMTypeRef ElementType, uint64_t ElementCount) { + return wrap(ArrayType::get(unwrap(ElementType), ElementCount)); +} + LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace) { return wrap(PointerType::get(unwrap(ElementType), AddressSpace)); } LLVMBool LLVMPointerTypeIsOpaque(LLVMTypeRef Ty) { return unwrap(Ty)->isOpaquePointerTy(); } LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) { return wrap(FixedVectorType::get(unwrap(ElementType), ElementCount)); } LLVMTypeRef LLVMScalableVectorType(LLVMTypeRef ElementType, unsigned ElementCount) { return wrap(ScalableVectorType::get(unwrap(ElementType), ElementCount)); } LLVMTypeRef LLVMGetElementType(LLVMTypeRef WrappedTy) { auto *Ty = unwrap(WrappedTy); if (auto *PTy = dyn_cast(Ty)) @@ -822,20 +826,25 @@ return unwrap(ArrayTy)->getNumElements(); } +uint64_t LLVMGetArrayLength2(LLVMTypeRef ArrayTy) { + return unwrap(ArrayTy)->getNumElements(); +} + + unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy) { return unwrap(PointerTy)->getAddressSpace(); } unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) { return unwrap(VectorTy)->getElementCount().getKnownMinValue(); } /*--.. Operations on other types ...........................................--*/ LLVMTypeRef LLVMPointerTypeInContext(LLVMContextRef C, unsigned AddressSpace) { return wrap(PointerType::get(*unwrap(C), AddressSpace)); } LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C) { return wrap(Type::getVoidTy(*unwrap(C))); } @@ -1493,6 +1502,11 @@ return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), V)); } +LLVMValueRef LLVMConstArray2(LLVMTypeRef ElementTy, LLVMValueRef *ConstantVals, uint64_t Length) { + ArrayRef V(unwrap(ConstantVals, Length), Length); + return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), V)); +} + LLVMValueRef LLVMConstStructInContext(LLVMContextRef C, LLVMValueRef *ConstantVals, unsigned Count, LLVMBool Packed) { Index: llvm/tools/llvm-c-test/echo.cpp =================================================================== --- llvm/tools/llvm-c-test/echo.cpp +++ llvm/tools/llvm-c-test/echo.cpp @@ -133,9 +133,9 @@ return S; } case LLVMArrayTypeKind: - return LLVMArrayType( + return LLVMArrayType2( Clone(LLVMGetElementType(Src)), - LLVMGetArrayLength(Src) + LLVMGetArrayLength2(Src) ); case LLVMPointerTypeKind: if (LLVMPointerTypeIsOpaque(Src)) @@ -309,13 +309,13 @@ ? LLVMConstantArrayValueKind : LLVMConstantDataArrayValueKind); LLVMTypeRef Ty = TypeCloner(M).Clone(Cst); - unsigned EltCount = LLVMGetArrayLength(Ty); + uint64_t EltCount = LLVMGetArrayLength2(Ty); SmallVector Elts; for (unsigned i = 0; i < EltCount; i++) Elts.push_back(clone_constant(LLVMGetAggregateElement(Cst, i), M)); return LLVMConstArray(LLVMGetElementType(Ty), Elts.data(), EltCount); } // Try constant struct if (LLVMIsAConstantStruct(Cst)) { check_value_kind(Cst, LLVMConstantStructValueKind);