authorgravatar for jonathan.haehne@hotmail.comTau <jonathan.haehne@hotmail.com> 2024-06-23 17:56:36+02:00
committergravatar for jonathan.haehne@hotmail.comTau <jonathan.haehne@hotmail.com> 2024-07-19 17:51:38+02:00
log9c2d597e69d13326970daadbaf7fd14f7da64c45
tree7eec2caaae656e4e0885cc4e83ccc4a949be058c
parentb4eb81230500e0e35f2017113eb4ed03be6acfb8

llvm: Fix debug gen for 0-bit types

Add a regression test for that, since these weirdly never occur in any of the other tests on x86-64-linux.

2 files changed, 34 insertions(+), 6 deletions(-)

src/codegen/llvm.zig+11-6
......@@ -1950,7 +1950,6 @@ pub const Object = struct {
19501950 },
19511951 .Int => {
19521952 const info = ty.intInfo(zcu);
1953 assert(info.bits != 0);
19541953 const int_name = try o.allocTypeName(ty);
19551954 defer gpa.free(int_name);
19561955 const builder_name = try o.builder.metadataString(int_name);
......@@ -2132,7 +2131,6 @@ pub const Object = struct {
21322131 const debug_elem_type = switch (elem_ty.zigTypeTag(zcu)) {
21332132 .Int => blk: {
21342133 const info = elem_ty.intInfo(zcu);
2135 assert(info.bits != 0);
21362134 const vec_name = try o.allocTypeName(ty);
21372135 defer gpa.free(vec_name);
21382136 const builder_name = try o.builder.metadataString(vec_name);
......@@ -2446,8 +2444,6 @@ pub const Object = struct {
24462444 if (decl.kind != .named) continue;
24472445 if (decl.analysis != .complete) continue;
24482446
2449 const decl_line = decl.typeSrcLine(zcu) + 1;
2450
24512447 if (decl.val.typeOf(zcu).ip_index == .type_type) {
24522448 const nested_type = decl.val.toType();
24532449 // If this decl is the owner of the type, it will
......@@ -2457,11 +2453,20 @@ pub const Object = struct {
24572453 if (owner == decl_id) continue;
24582454 }
24592455
2456 switch (nested_type.zigTypeTag(zcu)) {
2457 // We still may want these for a Zig expression
2458 // evaluator in debuggers, but for now they are
2459 // completely useless.
2460 .ComptimeInt, .ComptimeFloat,
2461 .Type, .Undefined, .Null, .EnumLiteral => continue,
2462 else => {},
2463 }
2464
24602465 fields.appendAssumeCapacity(try o.builder.debugTypedef(
24612466 try o.builder.metadataString(decl_name),
24622467 try o.getDebugFile(namespace.fileScope(zcu)),
24632468 fwd_ref,
2464 decl_line,
2469 0,
24652470 try o.lowerDebugType(nested_type, false),
24662471 0, // Align
24672472 ));
......@@ -2470,7 +2475,7 @@ pub const Object = struct {
24702475 try o.builder.metadataString(decl_name),
24712476 try o.getDebugFile(namespace.fileScope(zcu)),
24722477 fwd_ref,
2473 decl_line,
2478 0,
24742479 try o.lowerDebugType(Type.fromInterned(v.ty), false),
24752480 ));
24762481 }
test/cases/llvm/debug_types.zig created+23
......@@ -0,0 +1,23 @@
1const Ty = struct {
2 pub const A = void;
3 pub const B = @Vector(2, u0);
4 pub const C = u0;
5 pub const D = enum (u0) {};
6 pub const E = type;
7 pub const F = 1;
8 pub const G = 1.0;
9 pub const H = undefined;
10 pub const I = null;
11 pub const J = .foo;
12};
13pub fn main() void {
14 inline for (@typeInfo(Ty).Struct.decls) |d|{
15 _ = @field(Ty, d.name);
16 }
17}
18
19// compile
20// output_mode=Exe
21// backend=llvm
22// target=x86_64-linux,x86_64-macos
23//
\ No newline at end of file