Skip to content

Commit

Permalink
change: as_mdnode prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
qjerome committed Feb 27, 2025
1 parent 84af052 commit 38c41e7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/llvm/di.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,10 @@ impl DISanitizer {
}

fn visit_mdnode_item(&mut self, item: Item) {
// guardrail preventing to visit non mdnode items
if !item.is_mdnode() {
let Some(mdnode) = item.as_mdnode() else {
return;
}
};

let mdnode = item.as_mdnode();
match mdnode.try_into().expect("MDNode is not Metadata") {
Metadata::DICompositeType(mut di_composite_type) => {
#[allow(clippy::single_match)]
Expand Down Expand Up @@ -479,8 +477,13 @@ impl Item {
unsafe { !LLVMIsAMDNode(self.value_ref()).is_null() }
}

fn as_mdnode(&self) -> MDNode<'_> {
unsafe { MDNode::from_value_ref(self.value_ref()) }
/// Returns the [Item] as [MDNode] only if [Item::is_mdnode] is `true` else `None`
fn as_mdnode(&self) -> Option<MDNode<'_>> {
if self.is_mdnode() {
Some(unsafe { MDNode::from_value_ref(self.value_ref()) })
} else {
None
}
}

fn value_ref(&self) -> LLVMValueRef {
Expand Down

0 comments on commit 38c41e7

Please sign in to comment.