authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-13 18:18:25-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-14 00:11:46-07:00
logeeaaefb925a659f7bab1beea35b7c1b5f567d027
treed5514c85d14fa9cb261f29654385932dc4daa59f
parentcb3b1dd6ddee65d1811fb4058b5cc0f2c06d0139

LLVM: fix debug info for local vars

Previously we incorrectly used the pointer type as the debug info type.

2 files changed, 11 insertions(+), 2 deletions(-)

src/Sema.zig+9-1
...@@ -4195,7 +4195,15 @@ fn zirDbgVar(...@@ -4195,7 +4195,15 @@ fn zirDbgVar(
4195 const str_op = sema.code.instructions.items(.data)[inst].str_op;4195 const str_op = sema.code.instructions.items(.data)[inst].str_op;
4196 const operand = sema.resolveInst(str_op.operand);4196 const operand = sema.resolveInst(str_op.operand);
4197 const operand_ty = sema.typeOf(operand);4197 const operand_ty = sema.typeOf(operand);
4198 if (!(try sema.typeHasRuntimeBits(block, sema.src, operand_ty))) return;4198 switch (air_tag) {
4199 .dbg_var_ptr => {
4200 if (!(try sema.typeHasRuntimeBits(block, sema.src, operand_ty.childType()))) return;
4201 },
4202 .dbg_var_val => {
4203 if (!(try sema.typeHasRuntimeBits(block, sema.src, operand_ty))) return;
4204 },
4205 else => unreachable,
4206 }
4199 const name = str_op.getStr(sema.code);4207 const name = str_op.getStr(sema.code);
42004208
4201 // Add the name to the AIR.4209 // Add the name to the AIR.
src/codegen/llvm.zig+2-1
...@@ -3984,13 +3984,14 @@ pub const FuncGen = struct {...@@ -3984,13 +3984,14 @@ pub const FuncGen = struct {
3984 const pl_op = self.air.instructions.items(.data)[inst].pl_op;3984 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
3985 const operand = try self.resolveInst(pl_op.operand);3985 const operand = try self.resolveInst(pl_op.operand);
3986 const name = self.air.nullTerminatedString(pl_op.payload);3986 const name = self.air.nullTerminatedString(pl_op.payload);
3987 const ptr_ty = self.air.typeOf(pl_op.operand);
39873988
3988 const di_local_var = dib.createAutoVariable(3989 const di_local_var = dib.createAutoVariable(
3989 self.di_scope.?,3990 self.di_scope.?,
3990 name.ptr,3991 name.ptr,
3991 self.di_file.?,3992 self.di_file.?,
3992 self.prev_dbg_line,3993 self.prev_dbg_line,
3993 try self.dg.lowerDebugType(self.air.typeOf(pl_op.operand)),3994 try self.dg.lowerDebugType(ptr_ty.childType()),
3994 true, // always preserve3995 true, // always preserve
3995 0, // flags3996 0, // flags
3996 );3997 );