Segfault in LLVM API

Hi there!
I am relatively new to OCaml (and hence its LLVM API) and am running into some nasty segfaults. For background i am building a compiler which translates my AST to LLVM IR. Everything up until my code generation phase has been working smoothly, but my first LLVM API reference is causing a segfault, specifically using the build_alloca function. I am wondering what are some general practices in debugging these types of errors in OCaml. Any/all input is appreciated greatly.

If you want to look at my code for more context of the problem, here is the link: https://github.com/os12345678/Poppy/blob/codegen/lib/llvm-codegen/codegen_expr.ml

Does the more or less official demo works (doen’t crash) for you?

Yes the demo works fine for me

Don’t you need to position the builder at a valid point (eg at the end of a basic block) before you start emitting instructions?

Cheers,
Nicolas