-
Notifications
You must be signed in to change notification settings - Fork 227
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
Segmentation Fault when printing FunctionValue
which lives longer than Module
#343
Comments
I met this bug when following fn compile<'ctx>(
ctx: &'ctx Context,
mod_name: &str,
function: &Function,
) -> compiler::Result<FunctionValue<'ctx>> {
let builder = ctx.create_builder();
let module = ctx.create_module(mod_name);
let fpm = PassManager::create(&module);
fpm.add_instruction_combining_pass();
fpm.add_reassociate_pass();
fpm.add_gvn_pass();
fpm.add_cfg_simplification_pass();
fpm.initialize();
Compiler::default()
.builder(&builder)
.context(ctx)
.module(&module)
.function_pass_manager(&fpm)
.compile(function)
} and the With I feel like it would be better to force |
Good catch, the fn value lifetime should probably be tied to the module not the context |
I can't seem to reproduce the segfault in LLVM10, I wonder if something changed in LLVM14? 🤔 |
Prints out:
|
I see. |
I suspect that GlobalValues might have this same issue. Would you be able to confirm for me? |
Yes, exactly. let ctx = Context::create();
// gvalue lives longer than module.
let gvalue =
{
let module = ctx.create_module("test");
let gvalue = module.add_global(ctx.i32_type(), Some(AddressSpace::Const), "global");
// This is OK, it prints ""@global = external addrspace(4) global i32"
println!("{gvalue}");
gvalue
};
// Segmentation fault
println!("{gvalue}"); |
Okay, even though I wasn't able to reproduce the issue in gdb, I think it was maybe just luck? Like maybe the memory was never overridden on my system. I think I might have repro'd in valgrind:
|
See comment here as well: #347 (comment) will probably hold off until 0.2.0 |
Describe the Bug
When trying to print the content of
FuncitonValue
that originates in already droppedModule
, it leads to segmentation fault.To Reproduce
Expected Behavior
Expected to print
"define double @test_fn()\n"
again.(or print nothing because the module already dropped? Actually I'm not confident because I'm LLVM newbie...)
LLVM Version (please complete the following information):
Desktop (please complete the following information):
Additional Context
Nothing special.
The text was updated successfully, but these errors were encountered: