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

Malloc get seg fault #540

Open
noahfraiture opened this issue Oct 3, 2024 · 0 comments
Open

Malloc get seg fault #540

noahfraiture opened this issue Oct 3, 2024 · 0 comments

Comments

@noahfraiture
Copy link

Describe the Bug
Hello,
I'm trying to emit a simple malloc call but I get a segfault when the call is made, before even returning from the malloc. It compile correctly, but crash on run in a JIT

With a code as simple as that

        let malloc = self
            .builder_main
            .build_malloc(self.context.custom_width_int_type(8), "malloc")
            .expect("call malloc");

with nothing else being compiled, I get the following opcode

call:                                             ; No predecessors!
  %malloc = tail call ptr @malloc(i32 ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to i32))
  ret void
}

As we can see there's a getelementptr (i8, ptr null, i32 1) which I think might cause the issue.

I tried i8_type or different name but the result is always the same. I tried to add a free instruction after that but it doesn't reach the free on run.

LLVM Version:
inkwell = { version = "0.5.0", features = ["llvm18-0"] }
llvm-sys-180 = { package = "llvm-sys", version = "180.0.0", features = [
"prefer-static",
] }

Desktop (please complete the following information):

  • OS: Arch linux, linux 6.10.10.arch1-1
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

No branches or pull requests

1 participant