Skip to content

Commit

Permalink
llvm: Fix debug gen for 0-bit types
Browse files Browse the repository at this point in the history
Add a regression test for that, since these weirdly never occur in any
of the other tests on x86-64-linux.
  • Loading branch information
tau-dev committed Jun 23, 2024
1 parent 254b531 commit babd747
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/codegen/llvm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2024,7 +2024,6 @@ pub const Object = struct {
},
.Int => {
const info = ty.intInfo(mod);
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);
Expand Down Expand Up @@ -2206,7 +2205,6 @@ pub const Object = struct {
const debug_elem_type = switch (elem_ty.zigTypeTag(mod)) {
.Int => blk: {
const info = elem_ty.intInfo(mod);
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);
Expand Down Expand Up @@ -2530,6 +2528,15 @@ pub const Object = struct {
if (owner == decl_id) continue;
}

switch (nested_type.zigTypeTag(mod)) {
// 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.file_scope),
Expand Down
23 changes: 23 additions & 0 deletions test/cases/llvm/debug_types.zig
Original file line number Diff line number Diff line change
@@ -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
//

0 comments on commit babd747

Please sign in to comment.