From 0b2cde9394320ab6f097ef10408d663a28d44be3 Mon Sep 17 00:00:00 2001 From: tfzee Date: Sat, 23 Dec 2023 22:00:22 +0100 Subject: [PATCH] Corrected get_allocated_type return type to be more specific --- src/values/instruction_value.rs | 6 +++--- tests/all/test_instruction_values.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/values/instruction_value.rs b/src/values/instruction_value.rs index e08e3bb869a..5785c8492e5 100644 --- a/src/values/instruction_value.rs +++ b/src/values/instruction_value.rs @@ -18,9 +18,9 @@ use llvm_sys::LLVMOpcode; use std::{ffi::CStr, fmt, fmt::Display}; -use crate::values::traits::AsValueRef; use crate::values::{BasicValue, BasicValueEnum, BasicValueUse, MetadataValue, Value}; use crate::{basic_block::BasicBlock, types::AnyTypeEnum}; +use crate::{types::BasicTypeEnum, values::traits::AsValueRef}; use crate::{AtomicOrdering, FloatPredicate, IntPredicate}; use super::AnyValue; @@ -300,11 +300,11 @@ impl<'ctx> InstructionValue<'ctx> { // SubTypes: Only apply to alloca instruction /// Returns the type that is allocated by the alloca instruction. - pub fn get_allocated_type(self) -> Result, &'static str> { + pub fn get_allocated_type(self) -> Result, &'static str> { if !self.is_a_alloca_inst() { return Err("Value is not an alloca."); } - Ok(unsafe { AnyTypeEnum::new(LLVMGetAllocatedType(self.as_value_ref())) }) + Ok(unsafe { BasicTypeEnum::new(LLVMGetAllocatedType(self.as_value_ref())) }) } // SubTypes: Only apply to memory access and alloca instructions diff --git a/tests/all/test_instruction_values.rs b/tests/all/test_instruction_values.rs index 8471da70b8d..636be0084d1 100644 --- a/tests/all/test_instruction_values.rs +++ b/tests/all/test_instruction_values.rs @@ -1,5 +1,5 @@ use inkwell::context::Context; -use inkwell::types::{AnyType, AnyTypeEnum, AsTypeRef}; +use inkwell::types::{AnyTypeEnum, AsTypeRef, BasicType}; use inkwell::values::{BasicValue, InstructionOpcode::*}; use inkwell::{AddressSpace, AtomicOrdering, AtomicRMWBinOp, FloatPredicate, IntPredicate}; @@ -255,7 +255,7 @@ fn test_instructions() { assert_eq!( alloca_val.as_instruction().unwrap().get_allocated_type(), - Ok(i64_type.as_any_type_enum()) + Ok(i64_type.as_basic_type_enum()) ); assert!(store_instruction.get_allocated_type().is_err()); assert!(!store_instruction.is_terminator());