Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CallSiteValue::get_called_fn_value() fails it assert when the callee is a PointerValue #571

Open
winux138 opened this issue Feb 17, 2025 · 0 comments · May be fixed by #572
Open

CallSiteValue::get_called_fn_value() fails it assert when the callee is a PointerValue #571

winux138 opened this issue Feb 17, 2025 · 0 comments · May be fixed by #572

Comments

@winux138
Copy link

winux138 commented Feb 17, 2025

Describe the Bug

thread 'main' panicked at /home/ju/.cargo/registry/src/index.crates.io-6f17d22bba15001f/inkwell-0.5.0/src/values/fn_value.rs:48:9:
assertion failed: !LLVMIsAFunction(value).is_null()
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

CallSiteValue::get_called_fn_value() fails it assert when the callee is a PointerValue.

Is there a way to tell if the callee is a PointerValue or a FunctionValue ?

To Reproduce

const LLVM_IR: &str = r#"
; ModuleID = 'main.c'
source_filename = "main.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

; Function Attrs: noinline nounwind optnone uwtable
define dso_local void @dummy_fn() #0 {
  ret void
}

; Function Attrs: noinline nounwind optnone uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @dummy_fn()
  ; The following 3 lines cause a panic
  store ptr @dummy_fn, ptr %2, align 8
  %3 = load ptr, ptr %2, align 8
  call void %3()
  ret i32 0
}

attributes #0 = { noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3, !4}
!llvm.ident = !{!5}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{i32 7, !"frame-pointer", i32 2}
!5 = !{!"Ubuntu clang version 18.1.8 (++20240731024944+3b5b5c1ec4a3-1~exp1~20240731145000.144)"}
"#;

fn main() {
    let memory_buffer = inkwell::memory_buffer::MemoryBuffer::create_from_memory_range_copy(
        LLVM_IR.as_bytes(),
        "name",
    );

    let binding = inkwell::context::Context::create();
    let module = binding.create_module_from_ir(memory_buffer).unwrap();

    for f in module.get_functions() {
        for bb in f.get_basic_blocks() {
            for i in bb.get_instructions() {
                if let Ok(call_site_value) = inkwell::values::CallSiteValue::try_from(i) {
                    eprintln!(
                        "Found a call site: {:?}",
                        call_site_value.get_called_fn_value()
                    );
                }
            }
        }
    }
}

Expected Behavior
A primitive should be provided to distinguish calls to PointerValue from calls to FunctionValue.

LLVM Version (please complete the following information):

  • LLVM Version: 18.0
  • Inkwell Branch Used: llvm18-0

Desktop (please complete the following information):

  • OS: ubuntu 22.04 (popOS)

Additional Context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant