authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-07 23:03:45-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-08 14:58:53-07:00
logba566eed76bbfd57c6f4b410435067f3a6d7fd5d
treef7b335486685ca3a6b939404bf18e661aac03718
parent3654ec87707be408cc3bfa9ae7e59f95c4fdf7b3

LLVM: fix not handling dbg_stmt relative line

Also make `namespaceToDebugScope` behave correctly for file-level structs. Instead of being inside their own scope, they use the file scope.

1 files changed, 49 insertions(+), 1 deletions(-)

src/codegen/llvm.zig+49-1
......@@ -2313,7 +2313,29 @@ pub const DeclGen = struct {
23132313 return gop.value_ptr.*;
23142314 },
23152315 .Struct => {
2316 const owner_decl = ty.getOwnerDecl();
2317
2318 const name = try ty.nameAlloc(gpa); // TODO this is a leak
2319 const fwd_decl = dib.createReplaceableCompositeType(
2320 DW.TAG.structure_type,
2321 name.ptr,
2322 dg.object.di_compile_unit.?.toScope(),
2323 null, // file
2324 0, // line
2325 );
2326 gop.value_ptr.* = fwd_decl;
2327
2328 const TODO_implement_this = true; // TODO
2329 if (TODO_implement_this or !ty.hasRuntimeBits()) {
2330 const struct_di_ty = try dg.makeEmptyNamespaceDIType(owner_decl);
2331 dib.replaceTemporary(fwd_decl, struct_di_ty);
2332 // The recursive call to `lowerDebugType` via `makeEmptyNamespaceDIType`
2333 // means we can't use `gop` anymore.
2334 try dg.object.di_type_map.put(gpa, ty, struct_di_ty);
2335 return struct_di_ty;
2336 }
23162337 @panic("TODO debug info type for struct");
2338
23172339 //const gop = try dg.object.type_map.getOrPut(gpa, ty);
23182340 //if (gop.found_existing) return gop.value_ptr.*;
23192341
......@@ -2437,6 +2459,28 @@ pub const DeclGen = struct {
24372459 //return llvm_struct_ty;
24382460 },
24392461 .Union => {
2462 const owner_decl = ty.getOwnerDecl();
2463
2464 const name = try ty.nameAlloc(gpa); // TODO this is a leak
2465 const fwd_decl = dib.createReplaceableCompositeType(
2466 DW.TAG.structure_type,
2467 name.ptr,
2468 dg.object.di_compile_unit.?.toScope(),
2469 null, // file
2470 0, // line
2471 );
2472 gop.value_ptr.* = fwd_decl;
2473
2474 const TODO_implement_this = true; // TODO
2475 if (TODO_implement_this or !ty.hasRuntimeBits()) {
2476 const union_di_ty = try dg.makeEmptyNamespaceDIType(owner_decl);
2477 dib.replaceTemporary(fwd_decl, union_di_ty);
2478 // The recursive call to `lowerDebugType` via `makeEmptyNamespaceDIType`
2479 // means we can't use `gop` anymore.
2480 try dg.object.di_type_map.put(gpa, ty, union_di_ty);
2481 return union_di_ty;
2482 }
2483
24402484 @panic("TODO debug info type for union");
24412485 //const gop = try dg.object.type_map.getOrPut(gpa, ty);
24422486 //if (gop.found_existing) return gop.value_ptr.*;
......@@ -2561,6 +2605,10 @@ pub const DeclGen = struct {
25612605 }
25622606
25632607 fn namespaceToDebugScope(dg: *DeclGen, namespace: *const Module.Namespace) !*llvm.DIScope {
2608 if (namespace.parent == null) {
2609 const di_file = try dg.object.getDIFile(dg.gpa, namespace.file_scope);
2610 return di_file.toScope();
2611 }
25642612 const di_type = try dg.lowerDebugType(namespace.ty);
25652613 return di_type.toScope();
25662614 }
......@@ -3862,7 +3910,7 @@ pub const FuncGen = struct {
38623910 const di_scope = self.di_scope orelse return null;
38633911 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;
38643912 self.builder.setCurrentDebugLocation(
3865 @intCast(c_int, dbg_stmt.line + 1),
3913 @intCast(c_int, self.dg.decl.src_line + dbg_stmt.line + 1),
38663914 @intCast(c_int, dbg_stmt.column + 1),
38673915 di_scope,
38683916 );