Commit eeaaefb925

Andrew Kelley <andrew@ziglang.org>
2022-03-14 02:18:25
LLVM: fix debug info for local vars
Previously we incorrectly used the pointer type as the debug info type.
1 parent cb3b1dd
Changed files (2)
src
src/codegen/llvm.zig
@@ -3984,13 +3984,14 @@ pub const FuncGen = struct {
         const pl_op = self.air.instructions.items(.data)[inst].pl_op;
         const operand = try self.resolveInst(pl_op.operand);
         const name = self.air.nullTerminatedString(pl_op.payload);
+        const ptr_ty = self.air.typeOf(pl_op.operand);
 
         const di_local_var = dib.createAutoVariable(
             self.di_scope.?,
             name.ptr,
             self.di_file.?,
             self.prev_dbg_line,
-            try self.dg.lowerDebugType(self.air.typeOf(pl_op.operand)),
+            try self.dg.lowerDebugType(ptr_ty.childType()),
             true, // always preserve
             0, // flags
         );
src/Sema.zig
@@ -4195,7 +4195,15 @@ fn zirDbgVar(
     const str_op = sema.code.instructions.items(.data)[inst].str_op;
     const operand = sema.resolveInst(str_op.operand);
     const operand_ty = sema.typeOf(operand);
-    if (!(try sema.typeHasRuntimeBits(block, sema.src, operand_ty))) return;
+    switch (air_tag) {
+        .dbg_var_ptr => {
+            if (!(try sema.typeHasRuntimeBits(block, sema.src, operand_ty.childType()))) return;
+        },
+        .dbg_var_val => {
+            if (!(try sema.typeHasRuntimeBits(block, sema.src, operand_ty))) return;
+        },
+        else => unreachable,
+    }
     const name = str_op.getStr(sema.code);
 
     // Add the name to the AIR.