cdisselkoen/llvm-ir-analysis

idom_of_return panics on function with infinity loop.

Closed this issue · 1 comments

Test program test.c:

void foo() {
  while(1) {};
}

int main()
{
  foo();
  return 0;
}

Build instruction: clang -c test.c -emit-llvm -o test.bc

Rust program:

use llvm_ir::Module;
use llvm_ir_analysis::ModuleAnalysis;
use std::path::Path;

fn main() {
    let module = Module::from_bc_path(Path::new("./test.bc")).expect("failed to open the test file");
    let _ = ModuleAnalysis::new(&module).fn_analysis("foo").dominator_tree().idom_of_return();
}

Cargo.toml:

[package]
name = "test-panic"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
llvm-ir = { version = "0.8.2", features = ["llvm-14"] }
llvm-ir-analysis = { version = "0.3.1" }

Run command: cargo run

idom_of_return panics with:
thread 'main' panicked at 'Return node should have an idom', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/llvm-ir-analysis-0.3.1/src/dominator_tree.rs:197:35

Good catch. In this case, there is no dominator of the return node. idom_of_return() should return an Option to account for this.