Commit 9c2d597e69

Tau <jonathan.haehne@hotmail.com>
2024-06-23 17:56:36
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.
1 parent b4eb812
Changed files (2)
src
codegen
test
cases
src/codegen/llvm.zig
@@ -1950,7 +1950,6 @@ pub const Object = struct {
             },
             .Int => {
                 const info = ty.intInfo(zcu);
-                assert(info.bits != 0);
                 const int_name = try o.allocTypeName(ty);
                 defer gpa.free(int_name);
                 const builder_name = try o.builder.metadataString(int_name);
@@ -2132,7 +2131,6 @@ pub const Object = struct {
                 const debug_elem_type = switch (elem_ty.zigTypeTag(zcu)) {
                     .Int => blk: {
                         const info = elem_ty.intInfo(zcu);
-                        assert(info.bits != 0);
                         const vec_name = try o.allocTypeName(ty);
                         defer gpa.free(vec_name);
                         const builder_name = try o.builder.metadataString(vec_name);
@@ -2446,8 +2444,6 @@ pub const Object = struct {
                     if (decl.kind != .named) continue;
                     if (decl.analysis != .complete) continue;
 
-                    const decl_line = decl.typeSrcLine(zcu) + 1;
-
                     if (decl.val.typeOf(zcu).ip_index == .type_type) {
                         const nested_type = decl.val.toType();
                         // If this decl is the owner of the type, it will
@@ -2457,11 +2453,20 @@ pub const Object = struct {
                             if (owner == decl_id) continue;
                         }
 
+                        switch (nested_type.zigTypeTag(zcu)) {
+                            // We still may want these for a Zig expression
+                            // evaluator in debuggers, but for now they are
+                            // completely useless.
+                            .ComptimeInt, .ComptimeFloat,
+                            .Type, .Undefined, .Null, .EnumLiteral => continue,
+                            else => {},
+                        }
+
                         fields.appendAssumeCapacity(try o.builder.debugTypedef(
                             try o.builder.metadataString(decl_name),
                             try o.getDebugFile(namespace.fileScope(zcu)),
                             fwd_ref,
-                            decl_line,
+                            0,
                             try o.lowerDebugType(nested_type, false),
                             0, // Align
                         ));
@@ -2470,7 +2475,7 @@ pub const Object = struct {
                             try o.builder.metadataString(decl_name),
                             try o.getDebugFile(namespace.fileScope(zcu)),
                             fwd_ref,
-                            decl_line,
+                            0,
                             try o.lowerDebugType(Type.fromInterned(v.ty), false),
                         ));
                     }
test/cases/llvm/debug_types.zig
@@ -0,0 +1,23 @@
+const Ty = struct {
+	pub const A = void;
+	pub const B = @Vector(2, u0);
+	pub const C = u0;
+	pub const D = enum (u0) {};
+	pub const E = type;
+	pub const F = 1;
+	pub const G = 1.0;
+	pub const H = undefined;
+	pub const I = null;
+	pub const J = .foo;
+};
+pub fn main() void {
+	inline for (@typeInfo(Ty).Struct.decls) |d|{
+		_ = @field(Ty, d.name);
+	}
+}
+
+// compile
+// output_mode=Exe
+// backend=llvm
+// target=x86_64-linux,x86_64-macos
+//
\ No newline at end of file