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

Can't create declaration for intrinsic with a pointer parameter #496

Open
kotakotik22 opened this issue May 14, 2024 · 0 comments
Open

Can't create declaration for intrinsic with a pointer parameter #496

kotakotik22 opened this issue May 14, 2024 · 0 comments
Labels

Comments

@kotakotik22
Copy link

Describe the Bug
Intrinsic::get_declaration (or some other part of inkwell) seems to convert PointerType to a i64 when creating the intrinsic declaration, which doesn't pass llvm's verify, at least when there's a nocapture attribute.

To Reproduce
This example tries to get a declaration of the llvm.lifetime.start intrinsic (but doesn't even call it):

let ctx = Context::create();
let module = ctx.create_module("module");
let intrinsic = Intrinsic::find("llvm.lifetime.start").unwrap()
    // create the declaration
    .get_declaration(&module, &[
        ctx.i64_type().as_basic_type_enum(),
        ctx.ptr_type(AddressSpace::default()).as_basic_type_enum()
    ]);

// print the LLVM IR to stderr
module.print_to_stderr();
// attempt to verify (will panic)
module.verify().unwrap()

This generates the following LLVM IR:

; ModuleID = 'module'
source_filename = "module"

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.i64.p0(i64 immarg %0, i64 nocapture %1) #0

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }

Which then throws the following error when verifying: Attribute 'nocapture' applied to incompatible type! ptr @llvm.lifetime.start.i64.p0

Expected Behavior
I expected that code to generate a declaration which accepts a i64 and a ptr, and of course that it wouldn't throw a verification error.

LLVM Version:

  • LLVM Version: 17.0.6
  • Inkwell Branch Used: the crate feature is llvm17-0-prefer-static. I assume that's what I'm supposed to put here 😅

Desktop:

  • OS: Windows 10
@TheDan64 TheDan64 added the bug label Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants