core: Restore debug location when generating allocas
Debug location is lost when moving the builder cursor.
This commit is contained in:
parent
c5629d4eb5
commit
1a54aaa1c0
|
@ -129,6 +129,8 @@ impl CodeGenTargetMachineOptions {
|
|||
pub struct CodeGenContext<'ctx, 'a> {
|
||||
pub ctx: &'ctx Context,
|
||||
pub builder: Builder<'ctx>,
|
||||
/// The [DebugInfoBuilder], [compilation unit information][DICompileUnit], and
|
||||
/// [scope information][DIScope] of this context.
|
||||
pub debug_info: (DebugInfoBuilder<'ctx>, DICompileUnit<'ctx>, DIScope<'ctx>),
|
||||
pub module: Module<'ctx>,
|
||||
pub top_level: &'a TopLevelContext,
|
||||
|
|
|
@ -27,12 +27,27 @@ pub fn gen_var<'ctx, 'a>(
|
|||
ty: BasicTypeEnum<'ctx>,
|
||||
name: Option<&str>,
|
||||
) -> Result<PointerValue<'ctx>, String> {
|
||||
// Restore debug location
|
||||
let di_loc = ctx.debug_info.0.create_debug_location(
|
||||
ctx.ctx,
|
||||
ctx.current_loc.row as u32,
|
||||
ctx.current_loc.column as u32,
|
||||
ctx.debug_info.2,
|
||||
None,
|
||||
);
|
||||
|
||||
// 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());
|
||||
ctx.builder.set_current_debug_location(di_loc);
|
||||
|
||||
let ptr = ctx.builder.build_alloca(ty, name.unwrap_or(""));
|
||||
|
||||
ctx.builder.position_at_end(current);
|
||||
ctx.builder.set_current_debug_location(di_loc);
|
||||
|
||||
Ok(ptr)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue