Skip to content

Commit

Permalink
Corrected get_allocated_type return type to be more specific
Browse files Browse the repository at this point in the history
  • Loading branch information
tfzee authored and TheDan64 committed Dec 26, 2023
1 parent 998f46b commit 0b2cde9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/values/instruction_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<AnyTypeEnum<'ctx>, &'static str> {
pub fn get_allocated_type(self) -> Result<BasicTypeEnum<'ctx>, &'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
Expand Down
4 changes: 2 additions & 2 deletions tests/all/test_instruction_values.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 0b2cde9

Please sign in to comment.