From 243c4898076d52cd052d91ded8a05233b9ff6006 Mon Sep 17 00:00:00 2001 From: Xavier Lambein Date: Thu, 1 Feb 2024 11:37:02 +0100 Subject: [PATCH] Add opaque pointers - Add a `ptr_type` method to `Context` for LLVM >= 15.0 to get an opaque pointer type. - Deprecate the use of `ptr_type` on `*Type`. - Add a `is_opaque` method to `PointerType` to check whether the pointer is opaque (which is always true unless opaque-by-default is disabled). - Change the tests to use the new `ptr_type` method on `Context`. --- src/basic_block.rs | 3 ++ src/builder.rs | 53 ++++++++++++++++++++-- src/context.rs | 49 +++++++++++++++++++- src/types/array_type.rs | 6 +++ src/types/float_type.rs | 6 +++ src/types/fn_type.rs | 6 +++ src/types/int_type.rs | 6 +++ src/types/ptr_type.rs | 56 +++++++++++++++++++++++ src/types/struct_type.rs | 6 +++ src/types/traits.rs | 6 +++ src/types/vec_type.rs | 6 +++ src/values/basic_value_use.rs | 9 ++++ src/values/instruction_value.rs | 15 ++++++ tests/all/test_builder.rs | 58 +++++++++++++++++++++++- tests/all/test_context.rs | 3 ++ tests/all/test_execution_engine.rs | 8 +++- tests/all/test_instruction_conversion.rs | 3 ++ tests/all/test_instruction_values.rs | 24 ++++++++++ tests/all/test_types.rs | 32 +++++++++++++ tests/all/test_values.rs | 37 ++++++++++++++- 20 files changed, 382 insertions(+), 10 deletions(-) diff --git a/src/basic_block.rs b/src/basic_block.rs index 7dbacb5f3b7..c22e71cc368 100644 --- a/src/basic_block.rs +++ b/src/basic_block.rs @@ -288,7 +288,10 @@ impl<'ctx> BasicBlock<'ctx> { /// /// let void_type = context.void_type(); /// let i32_type = context.i32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let i32_ptr_type = context.ptr_type(AddressSpace::default()); /// /// let fn_type = void_type.fn_type(&[i32_ptr_type.into()], false); /// let fn_value = module.add_function("ret", fn_type, None); diff --git a/src/builder.rs b/src/builder.rs index ed3f8b514a2..90877dbe261 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -456,7 +456,10 @@ impl<'ctx> Builder<'ctx> { /// }; /// /// // type of an exception in C++ + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let i8_ptr_type = context.i32_type().ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let i32_ptr_ty = context.ptr_type(AddressSpace::default()); /// let i32_type = context.i32_type(); /// let exception_type = context.struct_type(&[i8_ptr_type.into(), i32_type.into()], false); /// @@ -574,11 +577,11 @@ impl<'ctx> Builder<'ctx> { /// }; /// /// // type of an exception in C++ - /// let i8_ptr_type = context.i32_type().ptr_type(AddressSpace::default()); + /// let ptr_type = context.ptr_type(AddressSpace::default()); /// let i32_type = context.i32_type(); - /// let exception_type = context.struct_type(&[i8_ptr_type.into(), i32_type.into()], false); + /// let exception_type = context.struct_type(&[ptr_type.into(), i32_type.into()], false); /// - /// let null = i8_ptr_type.const_zero(); + /// let null = ptr_type.const_zero(); /// let res = builder.build_landing_pad(exception_type, personality_function, &[null.into()], false, "res").unwrap(); /// /// // we handle the exception by returning a default value @@ -705,7 +708,10 @@ impl<'ctx> Builder<'ctx> { /// let builder = context.create_builder(); /// /// // type of an exception in C++ + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let i8_ptr_type = context.i8_type().ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let i8_ptr_type = context.ptr_type(AddressSpace::default()); /// let i32_type = context.i32_type(); /// let exception_type = context.struct_type(&[i8_ptr_type.into(), i32_type.into()], false); /// @@ -734,7 +740,10 @@ impl<'ctx> Builder<'ctx> { /// let builder = context.create_builder(); /// /// // type of an exception in C++ + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let i8_ptr_type = context.i8_type().ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let i8_ptr_type = context.ptr_type(AddressSpace::default()); /// let i32_type = context.i32_type(); /// let exception_type = context.struct_type(&[i8_ptr_type.into(), i32_type.into()], false); /// @@ -766,7 +775,10 @@ impl<'ctx> Builder<'ctx> { /// let builder = context.create_builder(); /// /// // type of an exception in C++ + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let i8_ptr_type = context.i8_type().ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let i8_ptr_type = context.ptr_type(AddressSpace::default()); /// let i32_type = context.i32_type(); /// let exception_type = context.struct_type(&[i8_ptr_type.into(), i32_type.into()], false); /// @@ -801,7 +813,10 @@ impl<'ctx> Builder<'ctx> { /// let builder = context.create_builder(); /// /// // type of an exception in C++ + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let i8_ptr_type = context.i8_type().ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let i8_ptr_type = context.ptr_type(AddressSpace::default()); /// let i32_type = context.i32_type(); /// let exception_type = context.struct_type(&[i8_ptr_type.into(), i32_type.into()], false); /// @@ -920,7 +935,10 @@ impl<'ctx> Builder<'ctx> { /// }; /// /// // type of an exception in C++ - /// let i8_ptr_type = context.i32_type().ptr_type(AddressSpace::default()); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] + /// let i8_ptr_type = context.i8_type().ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let i8_ptr_type = context.ptr_type(AddressSpace::default()); /// let i32_type = context.i32_type(); /// let exception_type = context.struct_type(&[i8_ptr_type.into(), i32_type.into()], false); /// @@ -1069,7 +1087,10 @@ impl<'ctx> Builder<'ctx> { /// let module = context.create_module("struct_gep"); /// let void_type = context.void_type(); /// let i32_ty = context.i32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let i32_ptr_ty = i32_ty.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let i32_ptr_ty = context.ptr_type(AddressSpace::default()); /// let field_types = &[i32_ty.into(), i32_ty.into()]; /// let struct_ty = context.struct_type(field_types, false); /// let struct_ptr_ty = struct_ty.ptr_type(AddressSpace::default()); @@ -1132,7 +1153,10 @@ impl<'ctx> Builder<'ctx> { /// let module = context.create_module("struct_gep"); /// let void_type = context.void_type(); /// let i32_ty = context.i32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let i32_ptr_ty = i32_ty.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let i32_ptr_ty = context.ptr_type(AddressSpace::default()); /// let field_types = &[i32_ty.into(), i32_ty.into()]; /// let struct_ty = context.struct_type(field_types, false); /// let struct_ptr_ty = struct_ty.ptr_type(AddressSpace::default()); @@ -1203,7 +1227,10 @@ impl<'ctx> Builder<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let i32_type = context.i32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let i32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[i32_ptr_type.into(), i32_ptr_type.into()], false); /// let fn_value = module.add_function("ret", fn_type, None); /// let entry = context.append_basic_block(fn_value, "entry"); @@ -1251,7 +1278,10 @@ impl<'ctx> Builder<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let i32_type = context.i32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let i32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[i32_ptr_type.into(), i32_ptr_type.into()], false); /// let fn_value = module.add_function("ret", fn_type, None); /// let entry = context.append_basic_block(fn_value, "entry"); @@ -1317,7 +1347,10 @@ impl<'ctx> Builder<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let i32_type = context.i32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let i32_ptr_type = context.ptr_type(AddressSpace::default()); /// let i32_seven = i32_type.const_int(7, false); /// let fn_type = void_type.fn_type(&[i32_ptr_type.into()], false); /// let fn_value = module.add_function("ret", fn_type, None); @@ -1354,7 +1387,10 @@ impl<'ctx> Builder<'ctx> { /// let module = context.create_module("ret"); /// let builder = context.create_builder(); /// let i32_type = context.i32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let i32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = i32_type.fn_type(&[i32_ptr_type.into()], false); /// let fn_value = module.add_function("ret", fn_type, None); /// let entry = context.append_basic_block(fn_value, "entry"); @@ -1391,7 +1427,10 @@ impl<'ctx> Builder<'ctx> { /// let module = context.create_module("ret"); /// let builder = context.create_builder(); /// let i32_type = context.i32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let i32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = i32_type.fn_type(&[i32_ptr_type.into()], false); /// let fn_value = module.add_function("ret", fn_type, None); /// let entry = context.append_basic_block(fn_value, "entry"); @@ -3226,7 +3265,10 @@ impl<'ctx> Builder<'ctx> { /// let void_type = context.void_type(); /// let i32_type = context.i32_type(); /// let i32_seven = i32_type.const_int(7, false); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let i32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[i32_ptr_type.into()], false); /// let fn_value = module.add_function("rmw", fn_type, None); /// let entry = context.append_basic_block(fn_value, "entry"); @@ -3297,7 +3339,10 @@ impl<'ctx> Builder<'ctx> { /// let module = context.create_module("cmpxchg"); /// let void_type = context.void_type(); /// let i32_type = context.i32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let i32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[i32_ptr_type.into()], false); /// let fn_value = module.add_function("", fn_type, None); /// let i32_ptr_param = fn_value.get_first_param().unwrap().into_pointer_value(); diff --git a/src/context.rs b/src/context.rs index 5fbfcc66cb4..5974f39c1d7 100644 --- a/src/context.rs +++ b/src/context.rs @@ -13,6 +13,8 @@ use llvm_sys::core::LLVMGetInlineAsm; use llvm_sys::core::LLVMGetTypeByName2; #[llvm_versions(6.0..=latest)] use llvm_sys::core::LLVMMetadataTypeInContext; +#[llvm_versions(15.0..=latest)] +use llvm_sys::core::LLVMPointerTypeInContext; use llvm_sys::core::{ LLVMAppendBasicBlockInContext, LLVMConstStringInContext, LLVMConstStructInContext, LLVMContextCreate, LLVMContextDispose, LLVMContextSetDiagnosticHandler, LLVMCreateBuilderInContext, LLVMCreateEnumAttribute, @@ -40,7 +42,7 @@ use crate::targets::TargetData; use crate::types::AnyTypeEnum; #[llvm_versions(6.0..=latest)] use crate::types::MetadataType; -use crate::types::{AsTypeRef, BasicTypeEnum, FloatType, FunctionType, IntType, StructType, VoidType}; +use crate::types::{AsTypeRef, BasicTypeEnum, FloatType, FunctionType, IntType, PointerType, StructType, VoidType}; use crate::values::{ ArrayValue, AsValueRef, BasicMetadataValueEnum, BasicValueEnum, FunctionValue, MetadataValue, PointerValue, StructValue, @@ -242,6 +244,11 @@ impl ContextImpl { unsafe { FloatType::new(LLVMPPCFP128TypeInContext(self.0)) } } + #[llvm_versions(15.0..=latest)] + fn ptr_type<'ctx>(&self, address_space: AddressSpace) -> PointerType<'ctx> { + unsafe { PointerType::new(LLVMPointerTypeInContext(self.0, address_space.0)) } + } + fn struct_type<'ctx>(&self, field_types: &[BasicTypeEnum], packed: bool) -> StructType<'ctx> { let mut field_types: Vec = field_types.iter().map(|val| val.as_type_ref()).collect(); unsafe { @@ -917,6 +924,26 @@ impl Context { self.context.ppc_f128_type() } + /// Gets the `IntType` representing 8 bit width. It will be assigned the current context. + /// + /// # Example + /// + /// ```no_run + /// use inkwell::context::Context; + /// use inkwell::AddressSpace; + /// + /// let context = Context::create(); + /// let ptr_type = context.ptr_type(AddressSpace::default()); + /// + /// assert_eq!(ptr_type.get_address_space(), AddressSpace::default()); + /// assert_eq!(ptr_type.get_context(), context); + /// ``` + #[llvm_versions(15.0..=latest)] + #[inline] + pub fn ptr_type(&self, address_space: AddressSpace) -> PointerType { + self.context.ptr_type(address_space) + } + /// Creates a `StructType` definition from heterogeneous types in the current `Context`. /// /// # Example @@ -1765,6 +1792,26 @@ impl<'ctx> ContextRef<'ctx> { self.context.ppc_f128_type() } + /// Gets the `IntType` representing 8 bit width. It will be assigned the current context. + /// + /// # Example + /// + /// ```no_run + /// use inkwell::context::Context; + /// use inkwell::AddressSpace; + /// + /// let context = Context::create(); + /// let ptr_type = context.ptr_type(AddressSpace::default()); + /// + /// assert_eq!(ptr_type.get_address_space(), AddressSpace::default()); + /// assert_eq!(ptr_type.get_context(), context); + /// ``` + #[llvm_versions(15.0..=latest)] + #[inline] + pub fn ptr_type(&self, address_space: AddressSpace) -> PointerType<'ctx> { + self.context.ptr_type(address_space) + } + /// Creates a `StructType` definition from heterogeneous types in the current `Context`. /// /// # Example diff --git a/src/types/array_type.rs b/src/types/array_type.rs index 10694d50180..4e5afb114f1 100644 --- a/src/types/array_type.rs +++ b/src/types/array_type.rs @@ -91,6 +91,12 @@ impl<'ctx> ArrayType<'ctx> { /// ))] /// assert_eq!(i8_array_ptr_type.get_element_type().into_array_type(), i8_array_type); /// ``` + #[cfg_attr( + any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0",), + deprecated( + note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." + ) + )] pub fn ptr_type(self, address_space: AddressSpace) -> PointerType<'ctx> { self.array_type.ptr_type(address_space) } diff --git a/src/types/float_type.rs b/src/types/float_type.rs index cd254cdf50e..2011622e964 100644 --- a/src/types/float_type.rs +++ b/src/types/float_type.rs @@ -230,6 +230,12 @@ impl<'ctx> FloatType<'ctx> { /// ))] /// assert_eq!(f32_ptr_type.get_element_type().into_float_type(), f32_type); /// ``` + #[cfg_attr( + any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0",), + deprecated( + note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." + ) + )] pub fn ptr_type(self, address_space: AddressSpace) -> PointerType<'ctx> { self.float_type.ptr_type(address_space) } diff --git a/src/types/fn_type.rs b/src/types/fn_type.rs index e28c58406c0..9b7117d6aa6 100644 --- a/src/types/fn_type.rs +++ b/src/types/fn_type.rs @@ -60,6 +60,12 @@ impl<'ctx> FunctionType<'ctx> { /// ))] /// assert_eq!(fn_ptr_type.get_element_type().into_function_type(), fn_type); /// ``` + #[cfg_attr( + any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0",), + deprecated( + note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." + ) + )] pub fn ptr_type(self, address_space: AddressSpace) -> PointerType<'ctx> { self.fn_type.ptr_type(address_space) } diff --git a/src/types/int_type.rs b/src/types/int_type.rs index 1053f3762b5..b4368087851 100644 --- a/src/types/int_type.rs +++ b/src/types/int_type.rs @@ -325,6 +325,12 @@ impl<'ctx> IntType<'ctx> { /// ))] /// assert_eq!(i8_ptr_type.get_element_type().into_int_type(), i8_type); /// ``` + #[cfg_attr( + any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0",), + deprecated( + note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." + ) + )] pub fn ptr_type(self, address_space: AddressSpace) -> PointerType<'ctx> { self.int_type.ptr_type(address_space) } diff --git a/src/types/ptr_type.rs b/src/types/ptr_type.rs index dc895981537..87aebad9c9e 100644 --- a/src/types/ptr_type.rs +++ b/src/types/ptr_type.rs @@ -1,3 +1,5 @@ +#[llvm_versions(15.0..=latest)] +use llvm_sys::core::LLVMPointerTypeIsOpaque; use llvm_sys::core::{LLVMConstArray, LLVMGetPointerAddressSpace}; use llvm_sys::prelude::{LLVMTypeRef, LLVMValueRef}; @@ -42,7 +44,10 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_type_size = f32_ptr_type.size_of(); /// ``` pub fn size_of(self) -> IntValue<'ctx> { @@ -59,7 +64,10 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_type_alignment = f32_ptr_type.get_alignment(); /// ``` pub fn get_alignment(self) -> IntValue<'ctx> { @@ -76,7 +84,10 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_ptr_type = f32_ptr_type.ptr_type(AddressSpace::default()); /// /// #[cfg(any( @@ -94,6 +105,12 @@ impl<'ctx> PointerType<'ctx> { /// ))] /// assert_eq!(f32_ptr_ptr_type.get_element_type().into_pointer_type(), f32_ptr_type); /// ``` + #[cfg_attr( + any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0",), + deprecated( + note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." + ) + )] pub fn ptr_type(self, address_space: AddressSpace) -> PointerType<'ctx> { self.ptr_type.ptr_type(address_space) } @@ -108,7 +125,10 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// /// assert_eq!(f32_ptr_type.get_context(), context); /// ``` @@ -127,7 +147,10 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = f32_ptr_type.fn_type(&[], false); /// ``` pub fn fn_type(self, param_types: &[BasicMetadataTypeEnum<'ctx>], is_var_args: bool) -> FunctionType<'ctx> { @@ -144,7 +167,10 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_array_type = f32_ptr_type.array_type(3); /// /// assert_eq!(f32_ptr_array_type.len(), 3); @@ -164,7 +190,10 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// /// assert_eq!(f32_ptr_type.get_address_space(), AddressSpace::default()); /// ``` @@ -190,7 +219,10 @@ impl<'ctx> PointerType<'ctx> { /// // Local Context /// let context = Context::create(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_null = f32_ptr_type.const_null(); /// /// assert!(f32_ptr_null.is_null()); @@ -212,7 +244,10 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_zero = f32_ptr_type.const_zero(); /// ``` pub fn const_zero(self) -> PointerValue<'ctx> { @@ -228,7 +263,10 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_undef = f32_ptr_type.get_undef(); /// /// assert!(f32_ptr_undef.is_undef()); @@ -247,7 +285,10 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_undef = f32_ptr_type.get_poison(); /// /// assert!(f32_ptr_undef.is_poison()); @@ -267,7 +308,10 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_vec_type = f32_ptr_type.vec_type(3); /// /// assert_eq!(f32_ptr_vec_type.get_size(), 3); @@ -288,7 +332,10 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// /// assert_eq!(f32_ptr_type.get_element_type().into_float_type(), f32_type); /// ``` @@ -306,7 +353,10 @@ impl<'ctx> PointerType<'ctx> { /// /// let context = Context::create(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let f32_ptr_val = f32_ptr_type.const_null(); /// let f32_ptr_array = f32_ptr_type.const_array(&[f32_ptr_val, f32_ptr_val]); /// @@ -322,6 +372,12 @@ impl<'ctx> PointerType<'ctx> { )) } } + + /// Determine whether this pointer is opaque. + #[llvm_versions(15.0..=latest)] + pub fn is_opaque(self) -> bool { + unsafe { LLVMPointerTypeIsOpaque(self.ptr_type.ty) != 0 } + } } unsafe impl AsTypeRef for PointerType<'_> { diff --git a/src/types/struct_type.rs b/src/types/struct_type.rs index baebef6551d..3ca5548f756 100644 --- a/src/types/struct_type.rs +++ b/src/types/struct_type.rs @@ -216,6 +216,12 @@ impl<'ctx> StructType<'ctx> { /// ))] /// assert_eq!(struct_ptr_type.get_element_type().into_struct_type(), struct_type); /// ``` + #[cfg_attr( + any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0",), + deprecated( + note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." + ) + )] pub fn ptr_type(self, address_space: AddressSpace) -> PointerType<'ctx> { self.struct_type.ptr_type(address_space) } diff --git a/src/types/traits.rs b/src/types/traits.rs index 086eb202aa0..7b4746e8e09 100644 --- a/src/types/traits.rs +++ b/src/types/traits.rs @@ -126,6 +126,12 @@ pub unsafe trait BasicType<'ctx>: AnyType<'ctx> { /// let addr_space = AddressSpace::default(); /// assert_eq!(int_basic_type.ptr_type(addr_space), int.ptr_type(addr_space)); /// ``` + #[cfg_attr( + any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0",), + deprecated( + note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." + ) + )] fn ptr_type(&self, address_space: AddressSpace) -> PointerType<'ctx> { unsafe { Type::new(self.as_type_ref()).ptr_type(address_space) } } diff --git a/src/types/vec_type.rs b/src/types/vec_type.rs index 0724d0e8795..d903e7ad8f6 100644 --- a/src/types/vec_type.rs +++ b/src/types/vec_type.rs @@ -215,6 +215,12 @@ impl<'ctx> VectorType<'ctx> { /// ))] /// assert_eq!(f32_vec_ptr_type.get_element_type().into_vector_type(), f32_vec_type); /// ``` + #[cfg_attr( + any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0",), + deprecated( + note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead." + ) + )] pub fn ptr_type(self, address_space: AddressSpace) -> PointerType<'ctx> { self.vec_type.ptr_type(address_space) } diff --git a/src/values/basic_value_use.rs b/src/values/basic_value_use.rs index fa971c03b1a..1d53f5859d6 100644 --- a/src/values/basic_value_use.rs +++ b/src/values/basic_value_use.rs @@ -40,7 +40,10 @@ impl<'ctx> BasicValueUse<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); /// /// let function = module.add_function("take_f32_ptr", fn_type, None); @@ -101,7 +104,10 @@ impl<'ctx> BasicValueUse<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); /// /// let function = module.add_function("take_f32_ptr", fn_type, None); @@ -137,7 +143,10 @@ impl<'ctx> BasicValueUse<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); /// /// let function = module.add_function("take_f32_ptr", fn_type, None); diff --git a/src/values/instruction_value.rs b/src/values/instruction_value.rs index 61b484003b8..1beccf7179f 100644 --- a/src/values/instruction_value.rs +++ b/src/values/instruction_value.rs @@ -389,7 +389,10 @@ impl<'ctx> InstructionValue<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); /// /// let function = module.add_function("take_f32_ptr", fn_type, None); @@ -449,7 +452,10 @@ impl<'ctx> InstructionValue<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); /// /// let function = module.add_function("take_f32_ptr", fn_type, None); @@ -550,7 +556,10 @@ impl<'ctx> InstructionValue<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); /// /// let function = module.add_function("take_f32_ptr", fn_type, None); @@ -593,7 +602,10 @@ impl<'ctx> InstructionValue<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); /// /// let function = module.add_function("take_f32_ptr", fn_type, None); @@ -657,7 +669,10 @@ impl<'ctx> InstructionValue<'ctx> { /// let builder = context.create_builder(); /// let void_type = context.void_type(); /// let f32_type = context.f32_type(); + /// #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] /// let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + /// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + /// let f32_ptr_type = context.ptr_type(AddressSpace::default()); /// let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); /// /// let function = module.add_function("take_f32_ptr", fn_type, None); diff --git a/tests/all/test_builder.rs b/tests/all/test_builder.rs index 3688ad7d1c8..cf3bb283061 100644 --- a/tests/all/test_builder.rs +++ b/tests/all/test_builder.rs @@ -48,7 +48,10 @@ fn test_build_call() { let function3 = module.add_function("call_fn", fn_type2, None); let basic_block3 = context.append_basic_block(function3, "entry"); let fn_ptr = function3.as_global_value().as_pointer_value(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let fn_ptr_type = fn_ptr.get_type(); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let fn_ptr_type = context.ptr_type(AddressSpace::default()); builder.position_at_end(basic_block3); @@ -157,7 +160,10 @@ fn test_build_invoke_cleanup_resume() { }; // type of an exception in C++ + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let i8_ptr_type = context.i32_type().ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let i8_ptr_type = context.ptr_type(AddressSpace::default()); let i32_type = context.i32_type(); let exception_type = context.struct_type(&[i8_ptr_type.into(), i32_type.into()], false); @@ -228,7 +234,10 @@ fn test_build_invoke_catch_all() { }; // type of an exception in C++ + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let i8_ptr_type = context.i32_type().ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let i8_ptr_type = context.ptr_type(AddressSpace::default()); let i32_type = context.i32_type(); let exception_type = context.struct_type(&[i8_ptr_type.into(), i32_type.into()], false); @@ -303,7 +312,10 @@ fn landing_pad_filter() { }; // type of an exception in C++ + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let i8_ptr_type = context.i32_type().ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let i8_ptr_type = context.ptr_type(AddressSpace::default()); let i32_type = context.i32_type(); let exception_type = context.struct_type(&[i8_ptr_type.into(), i32_type.into()], false); @@ -348,7 +360,10 @@ fn test_null_checked_ptr_ops() { // } let i8_type = context.i8_type(); - let i8_ptr_type = i8_type.ptr_type(AddressSpace::default()); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] + let i8_ptr_type = context.i32_type().ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let i8_ptr_type = context.ptr_type(AddressSpace::default()); let i64_type = context.i64_type(); let fn_type = i8_type.fn_type(&[i8_ptr_type.into()], false); let neg_one = i8_type.const_all_ones(); @@ -932,7 +947,10 @@ fn test_vector_pointer_ops() { let context = Context::create(); let module = context.create_module("test"); let int32_vec_type = context.i32_type().vec_type(4); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let i8_ptr_vec_type = context.i8_type().ptr_type(AddressSpace::default()).vec_type(4); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let i8_ptr_vec_type = context.ptr_type(AddressSpace::default()).vec_type(4); let bool_vec_type = context.bool_type().vec_type(4); // Here we're building a function that takes a <4 x i32>, converts it to a <4 x i8*> and returns a @@ -1178,7 +1196,10 @@ fn run_memcpy_on<'ctx>( let i32_type = context.i32_type(); let i64_type = context.i64_type(); let array_len = 4; + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let fn_type = i32_type.ptr_type(AddressSpace::default()).fn_type(&[], false); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let fn_type = context.ptr_type(AddressSpace::default()).fn_type(&[], false); let fn_value = module.add_function("test_fn", fn_type, None); let builder = context.create_builder(); let entry = context.append_basic_block(fn_value, "entry"); @@ -1288,7 +1309,10 @@ fn run_memmove_on<'ctx>( let i32_type = context.i32_type(); let i64_type = context.i64_type(); let array_len = 4; + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let fn_type = i32_type.ptr_type(AddressSpace::default()).fn_type(&[], false); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let fn_type = context.ptr_type(AddressSpace::default()).fn_type(&[], false); let fn_value = module.add_function("test_fn", fn_type, None); let builder = context.create_builder(); let entry = context.append_basic_block(fn_value, "entry"); @@ -1399,7 +1423,10 @@ fn run_memset_on<'ctx>( let i32_type = context.i32_type(); let i64_type = context.i64_type(); let array_len = 4; + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let fn_type = i32_type.ptr_type(AddressSpace::default()).fn_type(&[], false); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let fn_type = context.ptr_type(AddressSpace::default()).fn_type(&[], false); let fn_value = module.add_function("test_fn", fn_type, None); let builder = context.create_builder(); let entry = context.append_basic_block(fn_value, "entry"); @@ -1485,8 +1512,14 @@ fn test_bitcast() { let i32_type = context.i32_type(); let f64_type = context.f64_type(); let i64_type = context.i64_type(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let i32_ptr_type = context.ptr_type(AddressSpace::default()); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let i64_ptr_type = i64_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let i64_ptr_type = context.ptr_type(AddressSpace::default()); let i32_vec_type = i32_type.vec_type(2); let arg_types = [ i32_type.into(), @@ -1538,11 +1571,13 @@ fn test_atomicrmw() { builder.position_at_end(entry); let i32_type = context.i32_type(); - let i64_type = context.i64_type(); let i31_type = context.custom_width_int_type(31); let i4_type = context.custom_width_int_type(4); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let ptr_value = i32_type.ptr_type(AddressSpace::default()).get_undef(); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr_value = context.ptr_type(AddressSpace::default()).get_undef(); let zero_value = i32_type.const_zero(); let result = builder.build_atomicrmw(AtomicRMWBinOp::Add, ptr_value, zero_value, AtomicOrdering::Unordered); assert!(result.is_ok()); @@ -1561,18 +1596,25 @@ fn test_atomicrmw() { feature = "llvm14-0" ))] { + let i64_type = context.i64_type(); let ptr_value = i64_type.ptr_type(AddressSpace::default()).get_undef(); let zero_value = i32_type.const_zero(); let result = builder.build_atomicrmw(AtomicRMWBinOp::Add, ptr_value, zero_value, AtomicOrdering::Unordered); assert!(result.is_err()); } + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let ptr_value = i31_type.ptr_type(AddressSpace::default()).get_undef(); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr_value = context.ptr_type(AddressSpace::default()).get_undef(); let zero_value = i31_type.const_zero(); let result = builder.build_atomicrmw(AtomicRMWBinOp::Add, ptr_value, zero_value, AtomicOrdering::Unordered); assert!(result.is_err()); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let ptr_value = i4_type.ptr_type(AddressSpace::default()).get_undef(); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr_value = context.ptr_type(AddressSpace::default()).get_undef(); let zero_value = i4_type.const_zero(); let result = builder.build_atomicrmw(AtomicRMWBinOp::Add, ptr_value, zero_value, AtomicOrdering::Unordered); assert!(result.is_err()); @@ -1592,8 +1634,14 @@ fn test_cmpxchg() { let i32_type = context.i32_type(); let i64_type = context.i64_type(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let i32_ptr_type = context.ptr_type(AddressSpace::default()); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let i32_ptr_ptr_type = i32_ptr_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let i32_ptr_ptr_type = context.ptr_type(AddressSpace::default()); let ptr_value = i32_ptr_type.get_undef(); let zero_value = i32_type.const_zero(); @@ -1765,10 +1813,16 @@ fn test_safe_struct_gep() { let module = context.create_module("struct_gep"); let void_type = context.void_type(); let i32_ty = context.i32_type(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let i32_ptr_ty = i32_ty.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let i32_ptr_ty = context.ptr_type(AddressSpace::default()); let field_types = &[i32_ty.into(), i32_ty.into()]; let struct_ty = context.struct_type(field_types, false); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let struct_ptr_ty = struct_ty.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let struct_ptr_ty = context.ptr_type(AddressSpace::default()); let fn_type = void_type.fn_type(&[i32_ptr_ty.into(), struct_ptr_ty.into()], false); let fn_value = module.add_function("", fn_type, None); let entry = context.append_basic_block(fn_value, "entry"); diff --git a/tests/all/test_context.rs b/tests/all/test_context.rs index 8e725dc1cff..91fc5502c97 100644 --- a/tests/all/test_context.rs +++ b/tests/all/test_context.rs @@ -53,7 +53,10 @@ fn test_values_get_context() { let i8_type = context.i8_type(); let f32_type = context.f32_type(); let f32_vec_type = f32_type.vec_type(3); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let f32_ptr_type = context.ptr_type(AddressSpace::default()); let f32_array_type = f32_type.array_type(2); let fn_type = f32_type.fn_type(&[], false); let struct_type = context.struct_type(&[i8_type.into(), f32_type.into()], false); diff --git a/tests/all/test_execution_engine.rs b/tests/all/test_execution_engine.rs index 8b15c20f4de..477623d3c5e 100644 --- a/tests/all/test_execution_engine.rs +++ b/tests/all/test_execution_engine.rs @@ -55,8 +55,12 @@ fn test_jit_execution_engine() { let builder = context.create_builder(); let i8_type = context.i8_type(); let i32_type = context.i32_type(); - let i8_ptr_type = i8_type.ptr_type(AddressSpace::default()); - let i8_ptr_ptr_type = i8_ptr_type.ptr_type(AddressSpace::default()); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] + let i8_ptr_ptr_type = i8_type + .ptr_type(AddressSpace::default()) + .ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let i8_ptr_ptr_type = context.ptr_type(AddressSpace::default()); let one_i32 = i32_type.const_int(1, false); let three_i32 = i32_type.const_int(3, false); let fourtytwo_i32 = i32_type.const_int(42, false); diff --git a/tests/all/test_instruction_conversion.rs b/tests/all/test_instruction_conversion.rs index 76bd421cae0..d6c58aae4bf 100644 --- a/tests/all/test_instruction_conversion.rs +++ b/tests/all/test_instruction_conversion.rs @@ -111,7 +111,10 @@ fn test_conversion_to_pointer_value() { // Create a PointerType instruction let i64_type = context.i64_type(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let i64_ptr_type = i64_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let i64_ptr_type = context.ptr_type(AddressSpace::default()); let alloca_instr = builder .build_alloca(i64_ptr_type, "alloca") .unwrap() diff --git a/tests/all/test_instruction_values.rs b/tests/all/test_instruction_values.rs index ded3378459f..5dddaca8d03 100644 --- a/tests/all/test_instruction_values.rs +++ b/tests/all/test_instruction_values.rs @@ -11,7 +11,10 @@ fn test_operands() { let builder = context.create_builder(); let void_type = context.void_type(); let f32_type = context.f32_type(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let f32_ptr_type = context.ptr_type(AddressSpace::default()); let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false); let function = module.add_function("take_f32_ptr", fn_type, None); @@ -254,7 +257,10 @@ fn test_instructions() { let void_type = context.void_type(); let i64_type = context.i64_type(); let f32_type = context.f32_type(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let f32_ptr_type = context.ptr_type(AddressSpace::default()); let fn_type = void_type.fn_type(&[f32_ptr_type.into(), f32_type.into()], false); let function = module.add_function("free_f32", fn_type, None); @@ -345,7 +351,10 @@ fn test_volatile_atomicrmw_cmpxchg() { let void_type = context.void_type(); let i32_type = context.i32_type(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let i32_ptr_type = context.ptr_type(AddressSpace::default()); let fn_type = void_type.fn_type(&[i32_ptr_type.into(), i32_type.into()], false); let function = module.add_function("mem_inst", fn_type, None); @@ -399,7 +408,10 @@ fn test_mem_instructions() { let void_type = context.void_type(); let f32_type = context.f32_type(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let f32_ptr_type = context.ptr_type(AddressSpace::default()); let fn_type = void_type.fn_type(&[f32_ptr_type.into(), f32_type.into()], false); let function = module.add_function("mem_inst", fn_type, None); @@ -464,7 +476,10 @@ fn test_mem_instructions() { let void_type = context.void_type(); let f32_type = context.f32_type(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let f32_ptr_type = context.ptr_type(AddressSpace::default()); let fn_type = void_type.fn_type(&[f32_ptr_type.into(), f32_type.into()], false); let function = module.add_function("mem_inst", fn_type, None); @@ -543,7 +558,10 @@ fn test_atomic_ordering_mem_instructions() { let void_type = context.void_type(); let f32_type = context.f32_type(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let f32_ptr_type = f32_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let f32_ptr_type = context.ptr_type(AddressSpace::default()); let fn_type = void_type.fn_type(&[f32_ptr_type.into(), f32_type.into()], false); let function = module.add_function("mem_inst", fn_type, None); @@ -618,7 +636,10 @@ fn test_metadata_kinds() { let i8_type = context.i8_type(); let f32_type = context.f32_type(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let ptr_type = i8_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr_type = context.ptr_type(AddressSpace::default()); let struct_type = context.struct_type(&[i8_type.into(), f32_type.into()], false); let vector_type = i8_type.vec_type(2); @@ -652,7 +673,10 @@ fn test_find_instruction_with_name() { let void_type = context.void_type(); let i32_type = context.i32_type(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let i32_ptr_type = context.ptr_type(AddressSpace::default()); let fn_type = void_type.fn_type(&[i32_ptr_type.into()], false); let fn_value = module.add_function("ret", fn_type, None); diff --git a/tests/all/test_types.rs b/tests/all/test_types.rs index 9c47068f95d..ee3b768e9b5 100644 --- a/tests/all/test_types.rs +++ b/tests/all/test_types.rs @@ -160,6 +160,8 @@ fn sized_types(global_ctx: &Context) { let f80_type = global_ctx.x86_f80_type(); let f128_type = global_ctx.f128_type(); let ppc_f128_type = global_ctx.ppc_f128_type(); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr_type = global_ctx.ptr_type(AddressSpace::default()); let struct_type = global_ctx.struct_type(&[i8_type.into(), f128_type.into()], false); let struct_type2 = global_ctx.struct_type(&[], false); let struct_type3 = global_ctx.struct_type(&[i8_type.into(), f128_type.into()], true); @@ -184,6 +186,8 @@ fn sized_types(global_ctx: &Context) { assert!(f80_type.is_sized()); assert!(f128_type.is_sized()); assert!(ppc_f128_type.is_sized()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + assert!(ptr_type.is_sized()); assert!(struct_type.is_sized()); assert!(struct_type2.is_sized()); assert!(struct_type3.is_sized()); @@ -222,6 +226,8 @@ fn sized_types(global_ctx: &Context) { assert!(f80_type.array_type(42).is_sized()); assert!(f128_type.array_type(42).is_sized()); assert!(ppc_f128_type.array_type(42).is_sized()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + assert!(ptr_type.array_type(42).is_sized()); assert!(struct_type.array_type(0).is_sized()); assert!(struct_type2.array_type(0).is_sized()); assert!(struct_type3.array_type(0).is_sized()); @@ -239,6 +245,8 @@ fn sized_types(global_ctx: &Context) { assert!(f80_type.vec_type(42).is_sized()); assert!(f128_type.vec_type(42).is_sized()); assert!(ppc_f128_type.vec_type(42).is_sized()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + assert!(ptr_type.vec_type(42).is_sized()); let opaque_struct_type = global_ctx.opaque_struct_type("opaque"); @@ -263,7 +271,10 @@ fn test_const_zero() { let f128_type = context.f128_type(); let ppc_f128_type = context.ppc_f128_type(); let struct_type = context.struct_type(&[i8_type.into(), f128_type.into()], false); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let ptr_type = f64_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr_type = context.ptr_type(AddressSpace::default()); let vec_type = f64_type.vec_type(42); let array_type = f64_type.array_type(42); @@ -379,7 +390,10 @@ fn test_type_copies() { fn test_ptr_type() { let context = Context::create(); let i8_type = context.i8_type(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let ptr_type = i8_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr_type = context.ptr_type(AddressSpace::default()); assert_eq!(ptr_type.get_address_space(), AddressSpace::default()); @@ -434,7 +448,10 @@ fn test_basic_type_enum() { &context.f64_type(), // derived types &int.array_type(0), + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] &int.ptr_type(addr), + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + &context.ptr_type(addr), &context.struct_type(&[int.as_basic_type_enum()], false), &int.vec_type(1), ]; @@ -465,9 +482,24 @@ fn test_ptr_address_space() { for index in spaces { let address_space = AddressSpace::try_from(index).unwrap(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let ptr = context.i32_type().ptr_type(address_space); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr = context.ptr_type(address_space); assert_eq!(ptr.get_address_space(), address_space); } assert!(AddressSpace::try_from(1u32 << 24).is_err()); } + +#[llvm_versions(15.0..=latest)] +#[test] +fn test_ptr_is_opaque() { + let context = Context::create(); + + let i32_ptr_type = context.i32_type().ptr_type(AddressSpace::default()); + let ptr_type = context.ptr_type(AddressSpace::default()); + + assert!(i32_ptr_type.is_opaque()); + assert!(ptr_type.is_opaque()); +} diff --git a/tests/all/test_values.rs b/tests/all/test_values.rs index 0f45785ac3c..ec971735783 100644 --- a/tests/all/test_values.rs +++ b/tests/all/test_values.rs @@ -77,6 +77,8 @@ fn test_set_get_name() { let f32_type = context.f32_type(); let f64_type = context.f64_type(); let f128_type = context.f128_type(); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr_type = context.ptr_type(AddressSpace::default()); let array_type = f64_type.array_type(42); let ppc_f128_type = context.ppc_f128_type(); @@ -90,7 +92,10 @@ fn test_set_get_name() { let f32_val = f32_type.const_float(0.0); let f64_val = f64_type.const_float(0.0); let f128_val = f128_type.const_float(0.0); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let ptr_val = bool_type.ptr_type(AddressSpace::default()).const_null(); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr_val = ptr_type.const_null(); let array_val = f64_type.const_array(&[f64_val]); let struct_val = context.const_struct(&[i8_val.into(), f128_val.into()], false); let vec_val = VectorType::const_vector(&[i8_val]); @@ -146,7 +151,10 @@ fn test_set_get_name() { assert_eq!(ppc_f128_val.get_name().to_str(), Ok("")); let void_type = context.void_type(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let ptr_type = bool_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr_type = context.ptr_type(AddressSpace::default()); let struct_type = context.struct_type(&[bool_type.into()], false); let vec_type = bool_type.vec_type(1); @@ -217,6 +225,8 @@ fn test_undef() { let f32_type = context.f32_type(); let f64_type = context.f64_type(); let f128_type = context.f128_type(); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr_type = context.ptr_type(AddressSpace::default()); let array_type = f64_type.array_type(42); let ppc_f128_type = context.ppc_f128_type(); @@ -232,7 +242,10 @@ fn test_undef() { let f32_val = f32_type.const_float(0.0); let f64_val = f64_type.const_float(0.0); let f128_val = f128_type.const_float(0.0); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let ptr_val = bool_type.ptr_type(AddressSpace::default()).const_null(); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr_val = ptr_type.const_null(); let array_val = f64_type.const_array(&[f64_val]); let struct_val = context.const_struct(&[i8_val.into(), f128_val.into()], false); let vec_val = VectorType::const_vector(&[i8_val]); @@ -264,7 +277,10 @@ fn test_undef() { let f32_undef = f32_type.get_undef(); let f64_undef = f64_type.get_undef(); let f128_undef = f128_type.get_undef(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let ptr_undef = bool_type.ptr_type(AddressSpace::default()).get_undef(); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr_undef = ptr_type.get_undef(); let array_undef = array_type.get_undef(); let struct_undef = context.struct_type(&[bool_type.into()], false).get_undef(); let vec_undef = bool_type.vec_type(1).get_undef(); @@ -301,6 +317,8 @@ fn test_poison() { let f32_type = context.f32_type(); let f64_type = context.f64_type(); let f128_type = context.f128_type(); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr_type = context.ptr_type(AddressSpace::default()); let array_type = f64_type.array_type(42); let ppc_f128_type = context.ppc_f128_type(); @@ -316,7 +334,10 @@ fn test_poison() { let f32_val = f32_type.const_float(0.0); let f64_val = f64_type.const_float(0.0); let f128_val = f128_type.const_float(0.0); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let ptr_val = bool_type.ptr_type(AddressSpace::default()).const_null(); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr_val = ptr_type.const_null(); let array_val = f64_type.const_array(&[f64_val]); let struct_val = context.const_struct(&[i8_val.into(), f128_val.into()], false); let vec_val = VectorType::const_vector(&[i8_val]); @@ -348,7 +369,10 @@ fn test_poison() { let f32_poison = f32_type.get_poison(); let f64_poison = f64_type.get_poison(); let f128_poison = f128_type.get_poison(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let ptr_poison = bool_type.ptr_type(AddressSpace::default()).get_poison(); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let ptr_poison = ptr_type.get_poison(); let array_poison = array_type.get_poison(); let struct_poison = context.struct_type(&[bool_type.into()], false).get_poison(); let vec_poison = bool_type.vec_type(1).get_poison(); @@ -491,6 +515,8 @@ fn test_metadata() { let f32_type = context.f32_type(); // let f64_type = context.f64_type(); // let f128_type = context.f128_type(); + // #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + // let ptr_type = context.ptr_type(AddressSpace::default()); // let array_type = f64_type.array_type(42); // let ppc_f128_type = context.ppc_f128_type(); // let fn_type = bool_type.fn_type(&[i64_type.into(), array_type.into()], false); @@ -506,7 +532,10 @@ fn test_metadata() { // let f64_val = f64_type.const_float(0.0); // let f128_val = f128_type.const_float(0.0); // let ppc_f128_val = ppc_f128_type.const_float(0.0); + // #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] // let ptr_val = bool_type.ptr_type(AddressSpace::default()).const_null(); + // #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + // let ptr_val = ptr_type.const_null(); // let array_val = f64_type.const_array(&[f64_val]); // let struct_val = context.const_struct(&[i8_val.into(), f128_val.into()], false); // let vec_val = VectorType::const_vector(&[i8_val]); @@ -1289,7 +1318,10 @@ fn test_non_fn_ptr_called() { let builder = context.create_builder(); let module = context.create_module("my_mod"); let i8_type = context.i8_type(); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] let i8_ptr_type = i8_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let i8_ptr_type = context.ptr_type(AddressSpace::default()); let fn_type = i8_type.fn_type(&[i8_ptr_type.into()], false); let fn_value = module.add_function("my_func", fn_type, None); let bb = context.append_basic_block(fn_value, "entry"); @@ -1355,7 +1387,10 @@ fn test_aggregate_returns() { let builder = context.create_builder(); let module = context.create_module("my_mod"); let i32_type = context.i32_type(); - let i32_ptr_type = i32_type.ptr_type(AddressSpace::from(5u16)); + #[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))] + let i32_ptr_type = i32_type.ptr_type(AddressSpace::default()); + #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))] + let i32_ptr_type = context.ptr_type(AddressSpace::default()); let i32_three = i32_type.const_int(3, false); let i32_seven = i32_type.const_int(7, false); let struct_type = context.struct_type(&[i32_type.into(), i32_type.into()], false);