diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-03-12 19:55:48 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-03-13 03:41:31 -0400 |
| commit | 0bc96354909c0828b7fd36ce0be5705b7b21d63c (patch) | |
| tree | 2b544abbf34776414478cb5fe4b8baad661337b3 /src/AstGen.zig | |
| parent | 7ec2261dbf7a85f5c215f2dac22b80fca7de1e0f (diff) | |
| download | zig-0bc96354909c0828b7fd36ce0be5705b7b21d63c.tar.gz zig-0bc96354909c0828b7fd36ce0be5705b7b21d63c.zip | |
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.
Diffstat (limited to 'src/AstGen.zig')
| -rw-r--r-- | src/AstGen.zig | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index f54af8d3fb..646560fd5a 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -2389,6 +2389,8 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner .breakpoint, .fence, .dbg_stmt, + .dbg_var_ptr, + .dbg_var_val, .ensure_result_used, .ensure_result_non_error, .@"export", @@ -2666,6 +2668,15 @@ fn varDecl( } else .none; const init_inst = try reachableExpr(gz, scope, result_loc, var_decl.ast.init_node, node); + if (!gz.force_comptime) { + _ = try gz.add(.{ .tag = .dbg_var_val, .data = .{ + .str_op = .{ + .str = ident_name, + .operand = init_inst, + }, + } }); + } + const sub_scope = try block_arena.create(Scope.LocalVal); sub_scope.* = .{ .parent = scope, @@ -2751,6 +2762,15 @@ fn varDecl( } gz.instructions.items.len = dst; + if (!gz.force_comptime) { + _ = try gz.add(.{ .tag = .dbg_var_val, .data = .{ + .str_op = .{ + .str = ident_name, + .operand = init_inst, + }, + } }); + } + const sub_scope = try block_arena.create(Scope.LocalVal); sub_scope.* = .{ .parent = scope, @@ -2785,6 +2805,16 @@ fn varDecl( _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node); } const const_ptr = try gz.addUnNode(.make_ptr_const, init_scope.rl_ptr, node); + + if (!gz.force_comptime) { + _ = try gz.add(.{ .tag = .dbg_var_ptr, .data = .{ + .str_op = .{ + .str = ident_name, + .operand = const_ptr, + }, + } }); + } + const sub_scope = try block_arena.create(Scope.LocalPtr); sub_scope.* = .{ .parent = scope, @@ -2848,6 +2878,16 @@ fn varDecl( if (resolve_inferred_alloc != .none) { _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node); } + + if (!gz.force_comptime) { + _ = try gz.add(.{ .tag = .dbg_var_ptr, .data = .{ + .str_op = .{ + .str = ident_name, + .operand = var_data.alloc, + }, + } }); + } + const sub_scope = try block_arena.create(Scope.LocalPtr); sub_scope.* = .{ .parent = scope, |
