fix debug info

This commit is contained in:
ychenfo 2022-04-16 00:05:28 +08:00
parent 9bfcf36016
commit 3a58708add

View File

@ -26,12 +26,16 @@ pub fn gen_var<'ctx, 'a>(
ctx: &mut CodeGenContext<'ctx, 'a>,
ty: BasicTypeEnum<'ctx>,
) -> Result<PointerValue<'ctx>, String> {
let loc = ctx.builder.get_current_debug_location();
// put the alloca in init block
let current = ctx.builder.get_insert_block().unwrap();
// position before the last branching instruction...
ctx.builder.position_before(&ctx.init_bb.get_last_instruction().unwrap());
let ptr = ctx.builder.build_alloca(ty, "tmp");
ctx.builder.position_at_end(current);
if let Some(l) = loc {
ctx.builder.set_current_debug_location(ctx.ctx, l);
}
Ok(ptr)
}