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 {...@@ -1950,7 +1950,6 @@ pub const Object = struct {
1950 },1950 },
1951 .Int => {1951 .Int => {
1952 const info = ty.intInfo(zcu);1952 const info = ty.intInfo(zcu);
1953 assert(info.bits != 0);
1954 const int_name = try o.allocTypeName(ty);1953 const int_name = try o.allocTypeName(ty);
1955 defer gpa.free(int_name);1954 defer gpa.free(int_name);
1956 const builder_name = try o.builder.metadataString(int_name);1955 const builder_name = try o.builder.metadataString(int_name);
...@@ -2132,7 +2131,6 @@ pub const Object = struct {...@@ -2132,7 +2131,6 @@ pub const Object = struct {
2132 const debug_elem_type = switch (elem_ty.zigTypeTag(zcu)) {2131 const debug_elem_type = switch (elem_ty.zigTypeTag(zcu)) {
2133 .Int => blk: {2132 .Int => blk: {
2134 const info = elem_ty.intInfo(zcu);2133 const info = elem_ty.intInfo(zcu);
2135 assert(info.bits != 0);
2136 const vec_name = try o.allocTypeName(ty);2134 const vec_name = try o.allocTypeName(ty);
2137 defer gpa.free(vec_name);2135 defer gpa.free(vec_name);
2138 const builder_name = try o.builder.metadataString(vec_name);2136 const builder_name = try o.builder.metadataString(vec_name);
...@@ -2446,8 +2444,6 @@ pub const Object = struct {...@@ -2446,8 +2444,6 @@ pub const Object = struct {
2446 if (decl.kind != .named) continue;2444 if (decl.kind != .named) continue;
2447 if (decl.analysis != .complete) continue;2445 if (decl.analysis != .complete) continue;
24482446
2449 const decl_line = decl.typeSrcLine(zcu) + 1;
2450
2451 if (decl.val.typeOf(zcu).ip_index == .type_type) {2447 if (decl.val.typeOf(zcu).ip_index == .type_type) {
2452 const nested_type = decl.val.toType();2448 const nested_type = decl.val.toType();
2453 // If this decl is the owner of the type, it will2449 // If this decl is the owner of the type, it will
...@@ -2457,11 +2453,20 @@ pub const Object = struct {...@@ -2457,11 +2453,20 @@ pub const Object = struct {
2457 if (owner == decl_id) continue;2453 if (owner == decl_id) continue;
2458 }2454 }
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
2460 fields.appendAssumeCapacity(try o.builder.debugTypedef(2465 fields.appendAssumeCapacity(try o.builder.debugTypedef(
2461 try o.builder.metadataString(decl_name),2466 try o.builder.metadataString(decl_name),
2462 try o.getDebugFile(namespace.fileScope(zcu)),2467 try o.getDebugFile(namespace.fileScope(zcu)),
2463 fwd_ref,2468 fwd_ref,
2464 decl_line,2469 0,
2465 try o.lowerDebugType(nested_type, false),2470 try o.lowerDebugType(nested_type, false),
2466 0, // Align2471 0, // Align
2467 ));2472 ));
...@@ -2470,7 +2475,7 @@ pub const Object = struct {...@@ -2470,7 +2475,7 @@ pub const Object = struct {
2470 try o.builder.metadataString(decl_name),2475 try o.builder.metadataString(decl_name),
2471 try o.getDebugFile(namespace.fileScope(zcu)),2476 try o.getDebugFile(namespace.fileScope(zcu)),
2472 fwd_ref,2477 fwd_ref,
2473 decl_line,2478 0,
2474 try o.lowerDebugType(Type.fromInterned(v.ty), false),2479 try o.lowerDebugType(Type.fromInterned(v.ty), false),
2475 ));2480 ));
2476 }2481 }
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