diff --git a/src/attributes.rs b/src/attributes.rs index aba09b6f4191b..bad6867908bb4 100644 --- a/src/attributes.rs +++ b/src/attributes.rs @@ -189,3 +189,28 @@ impl Attribute { } } } + +/// An `AttributeLoc` determines where on a function an attribute is assigned to. +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +pub enum AttributeLoc { + /// Assign to the `FunctionValue`'s return type. + Return, + /// Assign to one of the `FunctionValue`'s params (0-indexed). + Param(u32), + /// Assign to the `FunctionValue` itself. + Function, +} + +impl AttributeLoc { + pub(crate) fn get_index(&self) -> u32 { + match self { + AttributeLoc::Return => 0, + AttributeLoc::Param(index) => { + assert!(*index <= u32::max_value() - 2, "Param index must be <= u32::max_value() - 2"); + + index + 1 + }, + AttributeLoc::Function => u32::max_value(), + } + } +} diff --git a/src/values/call_site_value.rs b/src/values/call_site_value.rs index ad18695adaaca..c433a2f5ea015 100644 --- a/src/values/call_site_value.rs +++ b/src/values/call_site_value.rs @@ -4,7 +4,7 @@ use llvm_sys::core::{LLVMIsTailCall, LLVMSetTailCall, LLVMGetTypeKind, LLVMTypeO use llvm_sys::prelude::LLVMValueRef; #[llvm_versions(3.9..=latest)] -use crate::attributes::Attribute; +use crate::attributes::{Attribute, AttributeLoc}; use crate::support::LLVMString; use crate::values::{AsValueRef, BasicValueEnum, InstructionValue, Value}; #[llvm_versions(3.9..=latest)] @@ -112,6 +112,7 @@ impl CallSiteValue { /// # Example /// /// ```no_run + /// use inkwell::attributes::AttributeLoc; /// use inkwell::context::Context; /// /// let context = Context::create(); @@ -128,15 +129,15 @@ impl CallSiteValue { /// /// let call_site_value = builder.build_call(fn_value, &[], "my_fn"); /// - /// call_site_value.add_attribute(0, string_attribute); - /// call_site_value.add_attribute(0, enum_attribute); + /// call_site_value.add_attribute(AttributeLoc::Return, string_attribute); + /// call_site_value.add_attribute(AttributeLoc::Return, enum_attribute); /// ``` #[llvm_versions(3.9..=latest)] - pub fn add_attribute(&self, index: u32, attribute: Attribute) { + pub fn add_attribute(&self, loc: AttributeLoc, attribute: Attribute) { use llvm_sys::core::LLVMAddCallSiteAttribute; unsafe { - LLVMAddCallSiteAttribute(self.as_value_ref(), index, attribute.attribute) + LLVMAddCallSiteAttribute(self.as_value_ref(), loc.get_index(), attribute.attribute) } } @@ -179,6 +180,7 @@ impl CallSiteValue { /// # Example /// /// ```no_run + /// use inkwell::attributes::AttributeLoc; /// use inkwell::context::Context; /// /// let context = Context::create(); @@ -195,17 +197,17 @@ impl CallSiteValue { /// /// let call_site_value = builder.build_call(fn_value, &[], "my_fn"); /// - /// call_site_value.add_attribute(0, string_attribute); - /// call_site_value.add_attribute(0, enum_attribute); + /// call_site_value.add_attribute(AttributeLoc::Return, string_attribute); + /// call_site_value.add_attribute(AttributeLoc::Return, enum_attribute); /// - /// assert_eq!(call_site_value.count_attributes(0), 2); + /// assert_eq!(call_site_value.count_attributes(AttributeLoc::Return), 2); /// ``` #[llvm_versions(3.9..=latest)] - pub fn count_attributes(&self, index: u32) -> u32 { + pub fn count_attributes(&self, loc: AttributeLoc) -> u32 { use llvm_sys::core::LLVMGetCallSiteAttributeCount; unsafe { - LLVMGetCallSiteAttributeCount(self.as_value_ref(), index) + LLVMGetCallSiteAttributeCount(self.as_value_ref(), loc.get_index()) } } @@ -214,6 +216,7 @@ impl CallSiteValue { /// # Example /// /// ```no_run + /// use inkwell::attributes::AttributeLoc; /// use inkwell::context::Context; /// /// let context = Context::create(); @@ -230,18 +233,18 @@ impl CallSiteValue { /// /// let call_site_value = builder.build_call(fn_value, &[], "my_fn"); /// - /// call_site_value.add_attribute(0, string_attribute); - /// call_site_value.add_attribute(0, enum_attribute); + /// call_site_value.add_attribute(AttributeLoc::Return, string_attribute); + /// call_site_value.add_attribute(AttributeLoc::Return, enum_attribute); /// - /// assert_eq!(call_site_value.get_enum_attribute(0, 1).unwrap(), enum_attribute); + /// assert_eq!(call_site_value.get_enum_attribute(AttributeLoc::Return, 1).unwrap(), enum_attribute); /// ``` // SubTypes: -> Attribute #[llvm_versions(3.9..=latest)] - pub fn get_enum_attribute(&self, index: u32, kind_id: u32) -> Option { + pub fn get_enum_attribute(&self, loc: AttributeLoc, kind_id: u32) -> Option { use llvm_sys::core::LLVMGetCallSiteEnumAttribute; let ptr = unsafe { - LLVMGetCallSiteEnumAttribute(self.as_value_ref(), index, kind_id) + LLVMGetCallSiteEnumAttribute(self.as_value_ref(), loc.get_index(), kind_id) }; if ptr.is_null() { @@ -256,6 +259,7 @@ impl CallSiteValue { /// # Example /// /// ```no_run + /// use inkwell::attributes::AttributeLoc; /// use inkwell::context::Context; /// /// let context = Context::create(); @@ -272,18 +276,18 @@ impl CallSiteValue { /// /// let call_site_value = builder.build_call(fn_value, &[], "my_fn"); /// - /// call_site_value.add_attribute(0, string_attribute); - /// call_site_value.add_attribute(0, enum_attribute); + /// call_site_value.add_attribute(AttributeLoc::Return, string_attribute); + /// call_site_value.add_attribute(AttributeLoc::Return, enum_attribute); /// - /// assert_eq!(call_site_value.get_string_attribute(0, "my_key").unwrap(), string_attribute); + /// assert_eq!(call_site_value.get_string_attribute(AttributeLoc::Return, "my_key").unwrap(), string_attribute); /// ``` // SubTypes: -> Attribute #[llvm_versions(3.9..=latest)] - pub fn get_string_attribute(&self, index: u32, key: &str) -> Option { + pub fn get_string_attribute(&self, loc: AttributeLoc, key: &str) -> Option { use llvm_sys::core::LLVMGetCallSiteStringAttribute; let ptr = unsafe { - LLVMGetCallSiteStringAttribute(self.as_value_ref(), index, key.as_ptr() as *const i8, key.len() as u32) + LLVMGetCallSiteStringAttribute(self.as_value_ref(), loc.get_index(), key.as_ptr() as *const i8, key.len() as u32) }; if ptr.is_null() { @@ -298,6 +302,7 @@ impl CallSiteValue { /// # Example /// /// ```no_run + /// use inkwell::attributes::AttributeLoc; /// use inkwell::context::Context; /// /// let context = Context::create(); @@ -314,18 +319,18 @@ impl CallSiteValue { /// /// let call_site_value = builder.build_call(fn_value, &[], "my_fn"); /// - /// call_site_value.add_attribute(0, string_attribute); - /// call_site_value.add_attribute(0, enum_attribute); - /// call_site_value.remove_enum_attribute(0, 1); + /// call_site_value.add_attribute(AttributeLoc::Return, string_attribute); + /// call_site_value.add_attribute(AttributeLoc::Return, enum_attribute); + /// call_site_value.remove_enum_attribute(AttributeLoc::Return, 1); /// - /// assert_eq!(call_site_value.get_enum_attribute(0, 1), None); + /// assert_eq!(call_site_value.get_enum_attribute(AttributeLoc::Return, 1), None); /// ``` #[llvm_versions(3.9..=latest)] - pub fn remove_enum_attribute(&self, index: u32, kind_id: u32) { + pub fn remove_enum_attribute(&self, loc: AttributeLoc, kind_id: u32) { use llvm_sys::core::LLVMRemoveCallSiteEnumAttribute; unsafe { - LLVMRemoveCallSiteEnumAttribute(self.as_value_ref(), index, kind_id) + LLVMRemoveCallSiteEnumAttribute(self.as_value_ref(), loc.get_index(), kind_id) } } @@ -334,6 +339,7 @@ impl CallSiteValue { /// # Example /// /// ```no_run + /// use inkwell::attributes::AttributeLoc; /// use inkwell::context::Context; /// /// let context = Context::create(); @@ -350,18 +356,18 @@ impl CallSiteValue { /// /// let call_site_value = builder.build_call(fn_value, &[], "my_fn"); /// - /// call_site_value.add_attribute(0, string_attribute); - /// call_site_value.add_attribute(0, enum_attribute); - /// call_site_value.remove_string_attribute(0, "my_key"); + /// call_site_value.add_attribute(AttributeLoc::Return, string_attribute); + /// call_site_value.add_attribute(AttributeLoc::Return, enum_attribute); + /// call_site_value.remove_string_attribute(AttributeLoc::Return, "my_key"); /// - /// assert_eq!(call_site_value.get_string_attribute(0, "my_key"), None); + /// assert_eq!(call_site_value.get_string_attribute(AttributeLoc::Return, "my_key"), None); /// ``` #[llvm_versions(3.9..=latest)] - pub fn remove_string_attribute(&self, index: u32, key: &str) { + pub fn remove_string_attribute(&self, loc: AttributeLoc, key: &str) { use llvm_sys::core::LLVMRemoveCallSiteStringAttribute; unsafe { - LLVMRemoveCallSiteStringAttribute(self.as_value_ref(), index, key.as_ptr() as *const i8, key.len() as u32) + LLVMRemoveCallSiteStringAttribute(self.as_value_ref(), loc.get_index(), key.as_ptr() as *const i8, key.len() as u32) } } @@ -370,6 +376,7 @@ impl CallSiteValue { /// # Example /// /// ```no_run + /// use inkwell::attributes::AttributeLoc; /// use inkwell::context::Context; /// /// let context = Context::create(); @@ -462,6 +469,7 @@ impl CallSiteValue { /// # Example /// /// ```no_run + /// use inkwell::attributes::AttributeLoc; /// use inkwell::context::Context; /// /// let context = Context::create(); @@ -476,13 +484,13 @@ impl CallSiteValue { /// /// let call_site_value = builder.build_call(fn_value, &[], "my_fn"); /// - /// call_site_value.set_param_alignment_attribute(0, 2); + /// call_site_value.set_alignment_attribute(AttributeLoc::Param(0), 2); /// ``` - pub fn set_param_alignment_attribute(&self, index: u32, alignment: u32) { + pub fn set_alignment_attribute(&self, loc: AttributeLoc, alignment: u32) { assert_eq!(alignment.count_ones(), 1, "Alignment must be a power of two."); unsafe { - LLVMSetInstrParamAlignment(self.as_value_ref(), index, alignment) + LLVMSetInstrParamAlignment(self.as_value_ref(), loc.get_index(), alignment) } } diff --git a/src/values/fn_value.rs b/src/values/fn_value.rs index 03a0215d3f1ef..277bd8aa747d3 100644 --- a/src/values/fn_value.rs +++ b/src/values/fn_value.rs @@ -11,7 +11,7 @@ use std::mem::forget; use std::fmt; #[llvm_versions(3.9..=latest)] -use crate::attributes::Attribute; +use crate::attributes::{Attribute, AttributeLoc}; use crate::basic_block::BasicBlock; use crate::module::Linkage; use crate::support::LLVMString; @@ -356,12 +356,12 @@ impl FunctionValue { self.fn_value.replace_all_uses_with(other.as_value_ref()) } - /// Adds an `Attribute` to this `FunctionValue` if index is 0, otherwise to its parameter - /// in the 1 - Nth position. + /// Adds an `Attribute` to a particular location in this `FunctionValue`. /// /// # Example /// /// ```no_run + /// use inkwell::attributes::AttributeLoc; /// use inkwell::context::Context; /// /// let context = Context::create(); @@ -372,22 +372,22 @@ impl FunctionValue { /// let string_attribute = context.create_string_attribute("my_key", "my_val"); /// let enum_attribute = context.create_enum_attribute(1, 1); /// - /// fn_value.add_attribute(0, string_attribute); - /// fn_value.add_attribute(0, enum_attribute); + /// fn_value.add_attribute(AttributeLoc::Return, string_attribute); + /// fn_value.add_attribute(AttributeLoc::Return, enum_attribute); /// ``` #[llvm_versions(3.9..=latest)] - pub fn add_attribute(&self, index: u32, attribute: Attribute) { + pub fn add_attribute(&self, loc: AttributeLoc, attribute: Attribute) { unsafe { - LLVMAddAttributeAtIndex(self.as_value_ref(), index, attribute.attribute) + LLVMAddAttributeAtIndex(self.as_value_ref(), loc.get_index(), attribute.attribute) } } - /// Counts the number of `Attribute`s belonging to this `FunctionValue` if index is 0, - /// otherwise to its parameter in the 1 - Nth position. + /// Counts the number of `Attribute`s belonging to the specified location in this `FunctionValue`. /// /// # Example /// /// ```no_run + /// use inkwell::attributes::AttributeLoc; /// use inkwell::context::Context; /// /// let context = Context::create(); @@ -398,24 +398,24 @@ impl FunctionValue { /// let string_attribute = context.create_string_attribute("my_key", "my_val"); /// let enum_attribute = context.create_enum_attribute(1, 1); /// - /// fn_value.add_attribute(0, string_attribute); - /// fn_value.add_attribute(0, enum_attribute); + /// fn_value.add_attribute(AttributeLoc::Return, string_attribute); + /// fn_value.add_attribute(AttributeLoc::Return, enum_attribute); /// - /// assert_eq!(fn_value.count_attributes(0), 2); + /// assert_eq!(fn_value.count_attributes(AttributeLoc::Return), 2); /// ``` #[llvm_versions(3.9..=latest)] - pub fn count_attributes(&self, index: u32) -> u32 { + pub fn count_attributes(&self, loc: AttributeLoc) -> u32 { unsafe { - LLVMGetAttributeCountAtIndex(self.as_value_ref(), index) + LLVMGetAttributeCountAtIndex(self.as_value_ref(), loc.get_index()) } } - /// Removes a string `Attribute` belonging this `FunctionValue` if index is 0, - /// otherwise to its parameter in the 1 - Nth position. + /// Removes a string `Attribute` belonging to the specified location in this `FunctionValue`. /// /// # Example /// /// ```no_run + /// use inkwell::attributes::AttributeLoc; /// use inkwell::context::Context; /// /// let context = Context::create(); @@ -425,22 +425,22 @@ impl FunctionValue { /// let fn_value = module.add_function("my_fn", fn_type, None); /// let string_attribute = context.create_string_attribute("my_key", "my_val"); /// - /// fn_value.add_attribute(0, string_attribute); - /// fn_value.remove_string_attribute(0, "my_key"); + /// fn_value.add_attribute(AttributeLoc::Return, string_attribute); + /// fn_value.remove_string_attribute(AttributeLoc::Return, "my_key"); /// ``` #[llvm_versions(3.9..=latest)] - pub fn remove_string_attribute(&self, index: u32, key: &str) { + pub fn remove_string_attribute(&self, loc: AttributeLoc, key: &str) { unsafe { - LLVMRemoveStringAttributeAtIndex(self.as_value_ref(), index, key.as_ptr() as *const i8, key.len() as u32) + LLVMRemoveStringAttributeAtIndex(self.as_value_ref(), loc.get_index(), key.as_ptr() as *const i8, key.len() as u32) } } - /// Removes an enum `Attribute` belonging to this `FunctionValue` if index is 0, - /// otherwise to its parameter in the 1 - Nth position. + /// Removes an enum `Attribute` belonging to the specified location in this `FunctionValue`. /// /// # Example /// /// ```no_run + /// use inkwell::attributes::AttributeLoc; /// use inkwell::context::Context; /// /// let context = Context::create(); @@ -450,22 +450,22 @@ impl FunctionValue { /// let fn_value = module.add_function("my_fn", fn_type, None); /// let enum_attribute = context.create_enum_attribute(1, 1); /// - /// fn_value.add_attribute(0, enum_attribute); - /// fn_value.remove_enum_attribute(0, 1); + /// fn_value.add_attribute(AttributeLoc::Return, enum_attribute); + /// fn_value.remove_enum_attribute(AttributeLoc::Return, 1); /// ``` #[llvm_versions(3.9..=latest)] - pub fn remove_enum_attribute(&self, index: u32, kind_id: u32) { + pub fn remove_enum_attribute(&self, loc: AttributeLoc, kind_id: u32) { unsafe { - LLVMRemoveEnumAttributeAtIndex(self.as_value_ref(), index, kind_id) + LLVMRemoveEnumAttributeAtIndex(self.as_value_ref(), loc.get_index(), kind_id) } } - /// Gets an enum `Attribute` belonging to this `FunctionValue` if index is 0, - /// otherwise to its parameter in the 1 - Nth position. + /// Gets an enum `Attribute` belonging to the specified location in this `FunctionValue`. /// /// # Example /// /// ```no_run + /// use inkwell::attributes::AttributeLoc; /// use inkwell::context::Context; /// /// let context = Context::create(); @@ -475,15 +475,15 @@ impl FunctionValue { /// let fn_value = module.add_function("my_fn", fn_type, None); /// let enum_attribute = context.create_enum_attribute(1, 1); /// - /// fn_value.add_attribute(0, enum_attribute); + /// fn_value.add_attribute(AttributeLoc::Return, enum_attribute); /// - /// assert_eq!(fn_value.get_enum_attribute(0, 1), Some(enum_attribute)); + /// assert_eq!(fn_value.get_enum_attribute(AttributeLoc::Return, 1), Some(enum_attribute)); /// ``` // SubTypes: -> Option> #[llvm_versions(3.9..=latest)] - pub fn get_enum_attribute(&self, index: u32, kind_id: u32) -> Option { + pub fn get_enum_attribute(&self, loc: AttributeLoc, kind_id: u32) -> Option { let ptr = unsafe { - LLVMGetEnumAttributeAtIndex(self.as_value_ref(), index, kind_id) + LLVMGetEnumAttributeAtIndex(self.as_value_ref(), loc.get_index(), kind_id) }; if ptr.is_null() { @@ -493,12 +493,12 @@ impl FunctionValue { Some(Attribute::new(ptr)) } - /// Gets a string `Attribute` belonging this `FunctionValue` if index is 0, - /// otherwise to its parameter in the 1 - Nth position. + /// Gets a string `Attribute` belonging to the specified location in this `FunctionValue`. /// /// # Example /// /// ```no_run + /// use inkwell::attributes::AttributeLoc; /// use inkwell::context::Context; /// /// let context = Context::create(); @@ -508,15 +508,15 @@ impl FunctionValue { /// let fn_value = module.add_function("my_fn", fn_type, None); /// let string_attribute = context.create_string_attribute("my_key", "my_val"); /// - /// fn_value.add_attribute(0, string_attribute); + /// fn_value.add_attribute(AttributeLoc::Return, string_attribute); /// - /// assert_eq!(fn_value.get_string_attribute(0, "my_key"), Some(string_attribute)); + /// assert_eq!(fn_value.get_string_attribute(AttributeLoc::Return, "my_key"), Some(string_attribute)); /// ``` // SubTypes: -> Option> #[llvm_versions(3.9..=latest)] - pub fn get_string_attribute(&self, index: u32, key: &str) -> Option { + pub fn get_string_attribute(&self, loc: AttributeLoc, key: &str) -> Option { let ptr = unsafe { - LLVMGetStringAttributeAtIndex(self.as_value_ref(), index, key.as_ptr() as *const i8, key.len() as u32) + LLVMGetStringAttributeAtIndex(self.as_value_ref(), loc.get_index(), key.as_ptr() as *const i8, key.len() as u32) }; if ptr.is_null() { diff --git a/tests/all/test_attributes.rs b/tests/all/test_attributes.rs index 53904a1cd0a0e..b4ac29d9cd001 100644 --- a/tests/all/test_attributes.rs +++ b/tests/all/test_attributes.rs @@ -1,6 +1,6 @@ extern crate inkwell; -use self::inkwell::attributes::Attribute; +use self::inkwell::attributes::{Attribute, AttributeLoc}; use self::inkwell::context::Context; use std::ffi::CString; @@ -85,30 +85,31 @@ fn test_attributes_on_function_values() { builder.position_at_end(&entry_bb); builder.build_return(None); - assert_eq!(fn_value.count_attributes(0), 0); - assert_eq!(fn_value.count_attributes(1), 0); + assert_eq!(fn_value.count_attributes(AttributeLoc::Return), 0); + assert_eq!(fn_value.count_attributes(AttributeLoc::Param(0)), 0); - fn_value.remove_string_attribute(0, "my_key"); // Noop - fn_value.remove_enum_attribute(0, alignstack_attribute); // Noop + fn_value.remove_string_attribute(AttributeLoc::Return, "my_key"); // Noop + fn_value.remove_enum_attribute(AttributeLoc::Return, alignstack_attribute); // Noop // define align 1 "my_key"="my_val" void @my_fn() - fn_value.add_attribute(0, string_attribute); - fn_value.add_attribute(1, string_attribute); // Applied to 1st param - fn_value.add_attribute(0, enum_attribute); + fn_value.add_attribute(AttributeLoc::Return, string_attribute); + fn_value.add_attribute(AttributeLoc::Param(0), string_attribute); // Applied to 1st param + fn_value.add_attribute(AttributeLoc::Return, enum_attribute); - assert_eq!(fn_value.count_attributes(0), 2); - assert_eq!(fn_value.get_enum_attribute(0, alignstack_attribute), Some(enum_attribute)); - assert_eq!(fn_value.get_string_attribute(0, "my_key"), Some(string_attribute)); + assert_eq!(fn_value.count_attributes(AttributeLoc::Return), 2); + assert_eq!(fn_value.get_enum_attribute(AttributeLoc::Return, alignstack_attribute), Some(enum_attribute)); + assert_eq!(fn_value.get_string_attribute(AttributeLoc::Return, "my_key"), Some(string_attribute)); - fn_value.remove_string_attribute(0, "my_key"); + fn_value.remove_string_attribute(AttributeLoc::Return, "my_key"); - assert_eq!(fn_value.count_attributes(0), 1); + assert_eq!(fn_value.count_attributes(AttributeLoc::Return), 1); - fn_value.remove_enum_attribute(0, alignstack_attribute); + fn_value.remove_enum_attribute(AttributeLoc::Return, alignstack_attribute); - assert_eq!(fn_value.count_attributes(0), 0); - assert!(fn_value.get_enum_attribute(0, alignstack_attribute).is_none()); - assert!(fn_value.get_string_attribute(0, "my_key").is_none()); + assert_eq!(fn_value.count_attributes(AttributeLoc::Function), 0); + assert_eq!(fn_value.count_attributes(AttributeLoc::Return), 0); + assert!(fn_value.get_enum_attribute(AttributeLoc::Return, alignstack_attribute).is_none()); + assert!(fn_value.get_string_attribute(AttributeLoc::Return, "my_key").is_none()); } #[test] @@ -123,6 +124,7 @@ fn test_attributes_on_call_site_values() { let entry_bb = fn_value.append_basic_block("entry"); let string_attribute = context.create_string_attribute("my_key", "my_val"); let alignstack_attribute = Attribute::get_named_enum_kind_id("alignstack"); + let align_attribute = Attribute::get_named_enum_kind_id("align"); let enum_attribute = context.create_enum_attribute(alignstack_attribute, 1); builder.position_at_end(&entry_bb); @@ -132,34 +134,34 @@ fn test_attributes_on_call_site_values() { builder.build_return(None); assert_eq!(call_site_value.count_arguments(), 1); - assert_eq!(call_site_value.count_attributes(0), 0); - assert_eq!(call_site_value.count_attributes(1), 0); + assert_eq!(call_site_value.count_attributes(AttributeLoc::Return), 0); + assert_eq!(call_site_value.count_attributes(AttributeLoc::Param(0)), 0); - call_site_value.remove_string_attribute(0, "my_key"); // Noop - call_site_value.remove_enum_attribute(0, alignstack_attribute); // Noop + call_site_value.remove_string_attribute(AttributeLoc::Return, "my_key"); // Noop + call_site_value.remove_enum_attribute(AttributeLoc::Return, alignstack_attribute); // Noop // define align 1 "my_key"="my_val" void @my_fn() - call_site_value.add_attribute(0, string_attribute); - call_site_value.add_attribute(1, string_attribute); // Applied to 1st param - call_site_value.add_attribute(0, enum_attribute); + call_site_value.add_attribute(AttributeLoc::Return, string_attribute); + call_site_value.add_attribute(AttributeLoc::Param(0), string_attribute); // Applied to 1st param + call_site_value.add_attribute(AttributeLoc::Return, enum_attribute); - assert_eq!(call_site_value.count_attributes(0), 2); - assert_eq!(call_site_value.get_enum_attribute(0, alignstack_attribute), Some(enum_attribute)); - assert_eq!(call_site_value.get_string_attribute(0, "my_key"), Some(string_attribute)); + assert_eq!(call_site_value.count_attributes(AttributeLoc::Return), 2); + assert_eq!(call_site_value.get_enum_attribute(AttributeLoc::Return, alignstack_attribute), Some(enum_attribute)); + assert_eq!(call_site_value.get_string_attribute(AttributeLoc::Return, "my_key"), Some(string_attribute)); - call_site_value.remove_string_attribute(0, "my_key"); + call_site_value.remove_string_attribute(AttributeLoc::Return, "my_key"); - assert_eq!(call_site_value.count_attributes(0), 1); + assert_eq!(call_site_value.count_attributes(AttributeLoc::Return), 1); - call_site_value.remove_enum_attribute(0, alignstack_attribute); + call_site_value.remove_enum_attribute(AttributeLoc::Return, alignstack_attribute); - assert_eq!(call_site_value.count_attributes(0), 0); - assert!(call_site_value.get_enum_attribute(0, alignstack_attribute).is_none()); - assert!(call_site_value.get_string_attribute(0, "my_key").is_none()); + assert_eq!(call_site_value.count_attributes(AttributeLoc::Return), 0); + assert!(call_site_value.get_enum_attribute(AttributeLoc::Return, alignstack_attribute).is_none()); + assert!(call_site_value.get_string_attribute(AttributeLoc::Return, "my_key").is_none()); assert_eq!(call_site_value.get_called_fn_value(), fn_value); - call_site_value.set_param_alignment_attribute(0, 16); + call_site_value.set_alignment_attribute(AttributeLoc::Return, 16); - assert_eq!(call_site_value.count_attributes(0), 1); - assert!(call_site_value.get_enum_attribute(0, 1).is_some()); + assert_eq!(call_site_value.count_attributes(AttributeLoc::Return), 1); + assert!(call_site_value.get_enum_attribute(AttributeLoc::Return, align_attribute).is_some()); } diff --git a/tests/all/test_values.rs b/tests/all/test_values.rs index 02aacf80f19be..e7ce0a0456d51 100644 --- a/tests/all/test_values.rs +++ b/tests/all/test_values.rs @@ -1,6 +1,7 @@ extern crate inkwell; use self::inkwell::{DLLStorageClass, FloatPredicate, GlobalVisibility, ThreadLocalMode, AddressSpace}; +use self::inkwell::attributes::AttributeLoc; use self::inkwell::context::Context; use self::inkwell::module::Linkage::*; use self::inkwell::types::{StringRadix, StructType, VectorType}; @@ -61,7 +62,7 @@ fn test_call_site() { assert_eq!(call_site.get_call_convention(), 2); - call_site.set_param_alignment_attribute(0, 16); + call_site.set_alignment_attribute(AttributeLoc::Return, 16); } #[test]