From 0bc96354909c0828b7fd36ce0be5705b7b21d63c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 12 Mar 2022 19:55:48 -0700 Subject: stage2: add debug info for locals in the LLVM backend Adds 2 new AIR instructions: * dbg_var_ptr * dbg_var_val Sema no longer emits dbg_stmt AIR instructions when strip=true. LLVM backend: fixed lowerPtrToVoid when calling ptrAlignment on the element type is problematic. LLVM backend: fixed alloca instructions improperly getting debug location annotated, causing chaotic debug info behavior. zig_llvm.cpp: fixed incorrect bindings for a function that should use unsigned integers for line and column. A bunch of C test cases regressed because the new dbg_var AIR instructions caused their operands to be alive, exposing latent bugs. Mostly it's just a problem that the C backend lowers mutable and const slices to the same C type, so we need to represent that in the C backend instead of printing two duplicate typedefs. --- src/codegen/c.zig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/codegen/c.zig') diff --git a/src/codegen/c.zig b/src/codegen/c.zig index f1da1fdc0c..5ab84520a4 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -1721,6 +1721,10 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO .union_init => try airUnionInit(f, inst), .prefetch => try airPrefetch(f, inst), + .dbg_var_ptr, + .dbg_var_val, + => try airDbgVar(f, inst), + .call => try airCall(f, inst, .auto), .call_always_tail => try airCall(f, inst, .always_tail), .call_never_tail => try airCall(f, inst, .never_tail), @@ -2651,6 +2655,16 @@ fn airDbgStmt(f: *Function, inst: Air.Inst.Index) !CValue { return CValue.none; } +fn airDbgVar(f: *Function, inst: Air.Inst.Index) !CValue { + const pl_op = f.air.instructions.items(.data)[inst].pl_op; + const name = f.air.nullTerminatedString(pl_op.payload); + const operand = try f.resolveInst(pl_op.operand); + _ = operand; + const writer = f.object.writer(); + try writer.print("/* var:{s} */\n", .{name}); + return CValue.none; +} + fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue { const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; const extra = f.air.extraData(Air.Block, ty_pl.payload); -- cgit v1.2.3