Describe the Bug
segfault when calling module.to_string
exception occured at the end of LLVMString::drop on my machine and this does not always happen.
To Reproduce
use inkwell::builder::Builder;
use inkwell::context::Context;
use inkwell::module::Module;
struct CodeGen<'ctx> {
context: &'ctx Context,
module: Module<'ctx>,
builder: Builder<'ctx>,
}
impl<'ctx> CodeGen<'ctx> {
fn build(&self) {
let i32_type = self.context.i32_type();
let fn_type = i32_type.fn_type(&[], false);
let function = self.module.add_function("main", fn_type, None);
let basic_block = self.context.append_basic_block(function, "entry");
self.builder.position_at_end(basic_block);
self.builder
.build_return(Some(&i32_type.const_int(0, false)))
.unwrap();
}
}
fn main() {
let context = Context::create();
let module = context.create_module("test");
let codegen = CodeGen {
context: &context,
module,
builder: context.create_builder(),
};
codegen.build();
println!("{}", codegen.module.to_string());
}
Expected Behavior
the program should not segfault after calling module.to_string function
LLVM Version (please complete the following information):
- LLVM Version: 21.1.8
- Inkwell Branch Used: llvm21-1
Desktop (please complete the following information):
Describe the Bug
segfault when calling
module.to_stringexception occured at the end of
LLVMString::dropon my machine and this does not always happen.To Reproduce
Expected Behavior
the program should not segfault after calling
module.to_stringfunctionLLVM Version (please complete the following information):
Desktop (please complete the following information):