From bdd015f9e92f26a7f2ca8f5c23ea39276d7cb920 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Sat, 21 Jan 2023 21:01:01 -0500 Subject: [PATCH] Fixes #358 --- src/builder.rs | 157 ++++++++++----------------- src/values/traits.rs | 10 +- tests/all/test_instruction_values.rs | 2 +- 3 files changed, 64 insertions(+), 105 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 4bbbd99a494..4b352b61fda 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1490,56 +1490,50 @@ impl<'ctx> Builder<'ctx> { // if I::sign() == Unsigned { LLVMBuildUDiv() } else { LLVMBuildSDiv() } pub fn build_int_unsigned_div>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildUDiv(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // TODO: Possibly make this generic over sign via struct metadata or subtypes // SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue { pub fn build_int_signed_div>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildSDiv(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // TODO: Possibly make this generic over sign via struct metadata or subtypes // SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue { pub fn build_int_exact_signed_div>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildExactSDiv(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // TODO: Possibly make this generic over sign via struct metadata or subtypes // SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue { pub fn build_int_unsigned_rem>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildURem(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // TODO: Possibly make this generic over sign via struct metadata or subtypes // SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue { pub fn build_int_signed_rem>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildSRem(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } pub fn build_int_s_extend>(&self, int_value: T, int_type: T::BaseType, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildSExt( self.builder, @@ -1549,7 +1543,7 @@ impl<'ctx> Builder<'ctx> { ) }; - T::new(value) + unsafe { T::new(value) } } // REVIEW: Does this need vector support? @@ -1606,7 +1600,6 @@ impl<'ctx> Builder<'ctx> { V: BasicValue<'ctx>, { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildBitCast(self.builder, val.as_value_ref(), ty.as_type_ref(), c_string.as_ptr()) }; unsafe { BasicValueEnum::new(value) } @@ -1619,7 +1612,6 @@ impl<'ctx> Builder<'ctx> { name: &str, ) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildSExtOrBitCast( self.builder, @@ -1629,12 +1621,11 @@ impl<'ctx> Builder<'ctx> { ) }; - T::new(value) + unsafe { T::new(value) } } pub fn build_int_z_extend>(&self, int_value: T, int_type: T::BaseType, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildZExt( self.builder, @@ -1644,7 +1635,7 @@ impl<'ctx> Builder<'ctx> { ) }; - T::new(value) + unsafe { T::new(value) } } pub fn build_int_z_extend_or_bit_cast>( @@ -1654,7 +1645,6 @@ impl<'ctx> Builder<'ctx> { name: &str, ) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildZExtOrBitCast( self.builder, @@ -1664,7 +1654,7 @@ impl<'ctx> Builder<'ctx> { ) }; - T::new(value) + unsafe { T::new(value) } } pub fn build_int_truncate>(&self, int_value: T, int_type: T::BaseType, name: &str) -> T { @@ -1679,7 +1669,7 @@ impl<'ctx> Builder<'ctx> { ) }; - T::new(value) + unsafe { T::new(value) } } pub fn build_int_truncate_or_bit_cast>( @@ -1699,15 +1689,14 @@ impl<'ctx> Builder<'ctx> { ) }; - T::new(value) + unsafe { T::new(value) } } pub fn build_float_rem>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildFRem(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // REVIEW: Consolidate these two casts into one via subtypes @@ -1718,7 +1707,6 @@ impl<'ctx> Builder<'ctx> { name: &str, ) -> <>::MathConvType as IntMathType<'ctx>>::ValueType { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildFPToUI( self.builder, @@ -1728,7 +1716,7 @@ impl<'ctx> Builder<'ctx> { ) }; - <::MathConvType as IntMathType>::ValueType::new(value) + unsafe { <::MathConvType as IntMathType>::ValueType::new(value) } } pub fn build_float_to_signed_int>( @@ -1738,7 +1726,6 @@ impl<'ctx> Builder<'ctx> { name: &str, ) -> <>::MathConvType as IntMathType<'ctx>>::ValueType { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildFPToSI( self.builder, @@ -1748,7 +1735,7 @@ impl<'ctx> Builder<'ctx> { ) }; - <::MathConvType as IntMathType>::ValueType::new(value) + unsafe { <::MathConvType as IntMathType>::ValueType::new(value) } } // REVIEW: Consolidate these two casts into one via subtypes @@ -1759,7 +1746,6 @@ impl<'ctx> Builder<'ctx> { name: &str, ) -> <>::MathConvType as FloatMathType<'ctx>>::ValueType { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildUIToFP( self.builder, @@ -1769,7 +1755,7 @@ impl<'ctx> Builder<'ctx> { ) }; - <::MathConvType as FloatMathType>::ValueType::new(value) + unsafe { <::MathConvType as FloatMathType>::ValueType::new(value) } } pub fn build_signed_int_to_float>( @@ -1779,7 +1765,6 @@ impl<'ctx> Builder<'ctx> { name: &str, ) -> <>::MathConvType as FloatMathType<'ctx>>::ValueType { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildSIToFP( self.builder, @@ -1789,12 +1774,11 @@ impl<'ctx> Builder<'ctx> { ) }; - <::MathConvType as FloatMathType>::ValueType::new(value) + unsafe { <::MathConvType as FloatMathType>::ValueType::new(value) } } pub fn build_float_trunc>(&self, float: T, float_type: T::BaseType, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildFPTrunc( self.builder, @@ -1804,12 +1788,11 @@ impl<'ctx> Builder<'ctx> { ) }; - T::new(value) + unsafe { T::new(value) } } pub fn build_float_ext>(&self, float: T, float_type: T::BaseType, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildFPExt( self.builder, @@ -1819,12 +1802,11 @@ impl<'ctx> Builder<'ctx> { ) }; - T::new(value) + unsafe { T::new(value) } } pub fn build_float_cast>(&self, float: T, float_type: T::BaseType, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildFPCast( self.builder, @@ -1834,13 +1816,12 @@ impl<'ctx> Builder<'ctx> { ) }; - T::new(value) + unsafe { T::new(value) } } // SubType: (&self, lhs: &IntValue, rhs: &IntType, name: &str) -> IntValue { pub fn build_int_cast>(&self, int: T, int_type: T::BaseType, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildIntCast( self.builder, @@ -1850,7 +1831,7 @@ impl<'ctx> Builder<'ctx> { ) }; - T::new(value) + unsafe { T::new(value) } } /// Like `build_int_cast`, but respects the signedness of the type being cast to. @@ -1863,7 +1844,6 @@ impl<'ctx> Builder<'ctx> { name: &str, ) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildIntCast2( self.builder, @@ -1874,80 +1854,72 @@ impl<'ctx> Builder<'ctx> { ) }; - T::new(value) + unsafe { T::new(value) } } pub fn build_float_div>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildFDiv(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue { pub fn build_int_add>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildAdd(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // REVIEW: Possibly incorperate into build_int_add via flag param // SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue { pub fn build_int_nsw_add>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildNSWAdd(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // REVIEW: Possibly incorperate into build_int_add via flag param // SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue { pub fn build_int_nuw_add>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildNUWAdd(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // SubType: (&self, lhs: &FloatValue, rhs: &FloatValue, name: &str) -> FloatValue { pub fn build_float_add>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildFAdd(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue { pub fn build_xor>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildXor(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue { pub fn build_and>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildAnd(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue { pub fn build_or>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildOr(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } /// Builds an `IntValue` containing the result of a logical left shift instruction. @@ -1995,10 +1967,9 @@ impl<'ctx> Builder<'ctx> { /// ``` pub fn build_left_shift>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildShl(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } /// Builds an `IntValue` containing the result of a right shift instruction. @@ -2067,7 +2038,6 @@ impl<'ctx> Builder<'ctx> { /// ``` pub fn build_right_shift>(&self, lhs: T, rhs: T, sign_extend: bool, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { if sign_extend { LLVMBuildAShr(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) @@ -2076,82 +2046,74 @@ impl<'ctx> Builder<'ctx> { } }; - T::new(value) + unsafe { T::new(value) } } // SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue { pub fn build_int_sub>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildSub(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // REVIEW: Possibly incorperate into build_int_sub via flag param pub fn build_int_nsw_sub>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildNSWSub(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // REVIEW: Possibly incorperate into build_int_sub via flag param // SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue { pub fn build_int_nuw_sub>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildNUWSub(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // SubType: (&self, lhs: &FloatValue, rhs: &FloatValue, name: &str) -> FloatValue { pub fn build_float_sub>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildFSub(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue { pub fn build_int_mul>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildMul(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // REVIEW: Possibly incorperate into build_int_mul via flag param // SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue { pub fn build_int_nsw_mul>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildNSWMul(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // REVIEW: Possibly incorperate into build_int_mul via flag param // SubType: (&self, lhs: &IntValue, rhs: &IntValue, name: &str) -> IntValue { pub fn build_int_nuw_mul>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildNUWMul(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // SubType: (&self, lhs: &FloatValue, rhs: &FloatValue, name: &str) -> FloatValue { pub fn build_float_mul>(&self, lhs: T, rhs: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildFMul(self.builder, lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } pub fn build_cast, V: BasicValue<'ctx>>( @@ -2178,20 +2140,24 @@ impl<'ctx> Builder<'ctx> { // SubType: (&self, from: &PointerValue, to: &PointerType, name: &str) -> PointerValue { pub fn build_pointer_cast>(&self, from: T, to: T::BaseType, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildPointerCast(self.builder, from.as_value_ref(), to.as_type_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // SubType: (&self, op, lhs: &IntValue, rhs: &IntValue, name) -> IntValue { ? // Note: we need a way to get an appropriate return type, since this method's return value // is always a bool (or vector of bools), not necessarily the same as the input value // See https://github.com/TheDan64/inkwell/pull/47#discussion_r197599297 - pub fn build_int_compare>(&self, op: IntPredicate, lhs: T, rhs: T, name: &str) -> T { + pub fn build_int_compare>( + &self, + op: IntPredicate, + lhs: T, + rhs: T, + name: &str, + ) -> >::ValueType { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildICmp( self.builder, @@ -2202,7 +2168,7 @@ impl<'ctx> Builder<'ctx> { ) }; - T::new(value) + unsafe { >::ValueType::new(value) } } // SubType: (&self, op, lhs: &FloatValue, rhs: &FloatValue, name) -> IntValue { ? @@ -2226,7 +2192,7 @@ impl<'ctx> Builder<'ctx> { ) }; - <::MathConvType as IntMathType>::ValueType::new(value) + unsafe { <::MathConvType as IntMathType>::ValueType::new(value) } } pub fn build_unconditional_branch(&self, destination_block: BasicBlock<'ctx>) -> InstructionValue<'ctx> { @@ -2270,47 +2236,42 @@ impl<'ctx> Builder<'ctx> { // SubType: (&self, value: &IntValue, name) -> IntValue { pub fn build_int_neg>(&self, value: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildNeg(self.builder, value.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // REVIEW: Possibly incorperate into build_int_neg via flag and subtypes // SubType: (&self, value: &IntValue, name) -> IntValue { pub fn build_int_nsw_neg>(&self, value: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildNSWNeg(self.builder, value.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // SubType: (&self, value: &IntValue, name) -> IntValue { pub fn build_int_nuw_neg>(&self, value: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildNUWNeg(self.builder, value.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // SubType: (&self, value: &FloatValue, name) -> FloatValue { pub fn build_float_neg>(&self, value: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildFNeg(self.builder, value.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // SubType: (&self, value: &IntValue, name) -> IntValue { ? pub fn build_not>(&self, value: T, name: &str) -> T { let c_string = to_c_str(name); - let value = unsafe { LLVMBuildNot(self.builder, value.as_value_ref(), c_string.as_ptr()) }; - T::new(value) + unsafe { T::new(value) } } // REVIEW: What if instruction and basic_block are completely unrelated? @@ -2581,10 +2542,9 @@ impl<'ctx> Builder<'ctx> { name: &str, ) -> <>::PtrConvType as IntMathType<'ctx>>::ValueType { let c_string = to_c_str(name); - let val = unsafe { LLVMBuildIsNull(self.builder, ptr.as_value_ref(), c_string.as_ptr()) }; - <::PtrConvType as IntMathType>::ValueType::new(val) + unsafe { <::PtrConvType as IntMathType>::ValueType::new(val) } } // SubType:

(&self, ptr: &PointerValue

, name) -> IntValue { @@ -2594,10 +2554,9 @@ impl<'ctx> Builder<'ctx> { name: &str, ) -> <>::PtrConvType as IntMathType<'ctx>>::ValueType { let c_string = to_c_str(name); - let val = unsafe { LLVMBuildIsNotNull(self.builder, ptr.as_value_ref(), c_string.as_ptr()) }; - <::PtrConvType as IntMathType>::ValueType::new(val) + unsafe { <::PtrConvType as IntMathType>::ValueType::new(val) } } // SubType: (&self, int: &IntValue, ptr_type: &PointerType

, name) -> PointerValue

{ @@ -2618,7 +2577,7 @@ impl<'ctx> Builder<'ctx> { ) }; - <::PtrConvType as PointerMathType>::ValueType::new(value) + unsafe { <::PtrConvType as PointerMathType>::ValueType::new(value) } } // SubType: (&self, ptr: &PointerValue

, int_type: &IntType, name) -> IntValue { @@ -2639,7 +2598,7 @@ impl<'ctx> Builder<'ctx> { ) }; - <::PtrConvType as IntMathType>::ValueType::new(value) + unsafe { <::PtrConvType as IntMathType>::ValueType::new(value) } } pub fn clear_insertion_position(&self) { diff --git a/src/values/traits.rs b/src/values/traits.rs index 2a6e5e5637c..bafca6fd81c 100644 --- a/src/values/traits.rs +++ b/src/values/traits.rs @@ -34,7 +34,7 @@ macro_rules! math_trait_value_set { $( unsafe impl<'ctx> $trait_name<'ctx> for $value_type<'ctx> { type BaseType = $base_type<'ctx>; - fn new(value: LLVMValueRef) -> Self { + unsafe fn new(value: LLVMValueRef) -> $value_type<'ctx> { unsafe { $value_type::new(value) } @@ -118,18 +118,18 @@ pub unsafe trait BasicValue<'ctx>: AnyValue<'ctx> { /// Represents a value which is permitted in integer math operations pub unsafe trait IntMathValue<'ctx>: BasicValue<'ctx> { type BaseType: IntMathType<'ctx>; - fn new(value: LLVMValueRef) -> Self; + unsafe fn new(value: LLVMValueRef) -> Self; } /// Represents a value which is permitted in floating point math operations pub unsafe trait FloatMathValue<'ctx>: BasicValue<'ctx> { type BaseType: FloatMathType<'ctx>; - fn new(value: LLVMValueRef) -> Self; + unsafe fn new(value: LLVMValueRef) -> Self; } pub unsafe trait PointerMathValue<'ctx>: BasicValue<'ctx> { type BaseType: PointerMathType<'ctx>; - fn new(value: LLVMValueRef) -> Self; + unsafe fn new(value: LLVMValueRef) -> Self; } // REVIEW: print_to_string might be a good candidate to live here? @@ -149,6 +149,6 @@ pub unsafe trait AnyValue<'ctx>: AsValueRef + Debug { trait_value_set! {AggregateValue: ArrayValue, AggregateValueEnum, StructValue} trait_value_set! {AnyValue: AnyValueEnum, BasicValueEnum, BasicMetadataValueEnum, AggregateValueEnum, ArrayValue, IntValue, FloatValue, GlobalValue, PhiValue, PointerValue, FunctionValue, StructValue, VectorValue, InstructionValue, CallSiteValue, MetadataValue} trait_value_set! {BasicValue: ArrayValue, BasicValueEnum, AggregateValueEnum, IntValue, FloatValue, GlobalValue, StructValue, PointerValue, VectorValue} -math_trait_value_set! {IntMathValue: (IntValue => IntType), (VectorValue => VectorType)} +math_trait_value_set! {IntMathValue: (IntValue => IntType), (VectorValue => VectorType), (PointerValue => IntType)} math_trait_value_set! {FloatMathValue: (FloatValue => FloatType), (VectorValue => VectorType)} math_trait_value_set! {PointerMathValue: (PointerValue => PointerType), (VectorValue => VectorType)} diff --git a/tests/all/test_instruction_values.rs b/tests/all/test_instruction_values.rs index 539b685a866..5d71460021e 100644 --- a/tests/all/test_instruction_values.rs +++ b/tests/all/test_instruction_values.rs @@ -229,7 +229,7 @@ fn test_instructions() { let store_instruction = builder.build_store(arg1, f32_val); let ptr_val = builder.build_ptr_to_int(arg1, i64_type, "ptr_val"); let ptr = builder.build_int_to_ptr(ptr_val, f32_ptr_type, "ptr"); - let icmp = builder.build_int_compare(IntPredicate::EQ, ptr_val, ptr_val, "icmp"); + let icmp = builder.build_int_compare(IntPredicate::EQ, arg1, arg1, "icmp"); let f32_sum = builder.build_float_add(arg2, f32_val, "f32_sum"); let fcmp = builder.build_float_compare(FloatPredicate::OEQ, f32_sum, arg2, "fcmp"); let free_instruction = builder.build_free(arg1);