Skip to content

Commit

Permalink
Merge pull request rust-lang#106 from wasmerio/debug
Browse files Browse the repository at this point in the history
A block without a parent doesn't have a next/previous. Return None in those cases.
  • Loading branch information
TheDan64 authored Aug 2, 2019
2 parents b06c41e + f8e9228 commit 75530c0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/basic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ impl BasicBlock {
/// assert_eq!(basic_block3.get_previous_basic_block().unwrap(), basic_block2);
/// ```
pub fn get_previous_basic_block(&self) -> Option<BasicBlock> {
if self.get_parent().is_none() {
return None;
}

let bb = unsafe {
LLVMGetPreviousBasicBlock(self.basic_block)
};
Expand Down Expand Up @@ -130,6 +134,10 @@ impl BasicBlock {
/// assert!(basic_block3.get_next_basic_block().is_none());
/// ```
pub fn get_next_basic_block(&self) -> Option<BasicBlock> {
if self.get_parent().is_none() {
return None;
}

let bb = unsafe {
LLVMGetNextBasicBlock(self.basic_block)
};
Expand Down

0 comments on commit 75530c0

Please sign in to comment.