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 {...@@ -2313,7 +2313,29 @@ pub const DeclGen = struct {
2313 return gop.value_ptr.*;2313 return gop.value_ptr.*;
2314 },2314 },
2315 .Struct => {2315 .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 }
2316 @panic("TODO debug info type for struct");2337 @panic("TODO debug info type for struct");
2338
2317 //const gop = try dg.object.type_map.getOrPut(gpa, ty);2339 //const gop = try dg.object.type_map.getOrPut(gpa, ty);
2318 //if (gop.found_existing) return gop.value_ptr.*;2340 //if (gop.found_existing) return gop.value_ptr.*;
23192341
...@@ -2437,6 +2459,28 @@ pub const DeclGen = struct {...@@ -2437,6 +2459,28 @@ pub const DeclGen = struct {
2437 //return llvm_struct_ty;2459 //return llvm_struct_ty;
2438 },2460 },
2439 .Union => {2461 .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
2440 @panic("TODO debug info type for union");2484 @panic("TODO debug info type for union");
2441 //const gop = try dg.object.type_map.getOrPut(gpa, ty);2485 //const gop = try dg.object.type_map.getOrPut(gpa, ty);
2442 //if (gop.found_existing) return gop.value_ptr.*;2486 //if (gop.found_existing) return gop.value_ptr.*;
...@@ -2561,6 +2605,10 @@ pub const DeclGen = struct {...@@ -2561,6 +2605,10 @@ pub const DeclGen = struct {
2561 }2605 }
25622606
2563 fn namespaceToDebugScope(dg: *DeclGen, namespace: *const Module.Namespace) !*llvm.DIScope {2607 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 }
2564 const di_type = try dg.lowerDebugType(namespace.ty);2612 const di_type = try dg.lowerDebugType(namespace.ty);
2565 return di_type.toScope();2613 return di_type.toScope();
2566 }2614 }
...@@ -3862,7 +3910,7 @@ pub const FuncGen = struct {...@@ -3862,7 +3910,7 @@ pub const FuncGen = struct {
3862 const di_scope = self.di_scope orelse return null;3910 const di_scope = self.di_scope orelse return null;
3863 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;3911 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;
3864 self.builder.setCurrentDebugLocation(3912 self.builder.setCurrentDebugLocation(
3865 @intCast(c_int, dbg_stmt.line + 1),3913 @intCast(c_int, self.dg.decl.src_line + dbg_stmt.line + 1),
3866 @intCast(c_int, dbg_stmt.column + 1),3914 @intCast(c_int, dbg_stmt.column + 1),
3867 di_scope,3915 di_scope,
3868 );3916 );