Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use llvm_sys::core::{LLVMGetTypeAttributeValue, LLVMIsTypeAttribute};
use llvm_sys::prelude::LLVMAttributeRef;

use std::ffi::CStr;
use std::num::NonZeroU32;

#[llvm_versions(12..)]
use crate::types::AnyTypeEnum;
Expand Down Expand Up @@ -170,14 +171,16 @@ impl Attribute {
/// use inkwell::attributes::Attribute;
///
/// // This kind id doesn't exist:
/// assert_eq!(Attribute::get_named_enum_kind_id("foobar"), 0);
/// assert_eq!(Attribute::get_named_enum_kind_id("foobar"), None);
///
/// // These are real kind ids:
/// assert_eq!(Attribute::get_named_enum_kind_id("align"), 1);
/// assert_eq!(Attribute::get_named_enum_kind_id("builtin"), 5);
/// assert_eq!(Attribute::get_named_enum_kind_id("align").unwrap().get(), 1);
/// assert_eq!(Attribute::get_named_enum_kind_id("builtin").unwrap().get(), 5);
/// ```
pub fn get_named_enum_kind_id(name: &str) -> u32 {
unsafe { LLVMGetEnumAttributeKindForName(name.as_ptr() as *const ::libc::c_char, name.len()) }
pub fn get_named_enum_kind_id(name: &str) -> Option<NonZeroU32> {
let id = unsafe { LLVMGetEnumAttributeKindForName(name.as_ptr() as *const ::libc::c_char, name.len()) };

NonZeroU32::new(id)
}

/// Gets the kind id associated with an enum `Attribute`.
Expand Down
Loading