Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/Translator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,9 @@ fn maybeSuppressResult(t: *Translator, used: ResultUsed, result: ZigNode) TransE

pub fn addTopLevelDecl(t: *Translator, name: []const u8, decl_node: ZigNode) !void {
const gop = try t.global_scope.sym_table.getOrPut(t.gpa, name);
if (!gop.found_existing) {
gop.value_ptr.* = decl_node;
try t.global_scope.nodes.append(t.gpa, decl_node);
}
if (gop.found_existing) return; // Any duplicate decls are equivalent
gop.value_ptr.* = decl_node;
try t.global_scope.nodes.append(t.gpa, decl_node);
}

fn fail(
Expand Down Expand Up @@ -317,10 +316,12 @@ fn prepopulateGlobalNameTable(t: *Translator) !void {
const gop = try t.unnamed_typedefs.getOrPut(t.gpa, base.qt);
if (gop.found_existing) {
// One typedef can declare multiple names.
// TODO Don't put this one in `decl_table` so it's processed later.
// Don't put this one in `decl_table` so it's processed later.
continue;
}
gop.value_ptr.* = decl_name;
try t.type_decls.put(t.gpa, decl, decl_name);
try t.typedefs.put(t.gpa, decl_name, {});
},

.struct_decl,
Expand Down
16 changes: 16 additions & 0 deletions test/cases/translate/unnamed_typedef_referencing_itself.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
typedef struct {
struct TypeB* b_member;
} TypeA;

struct TypeB {
TypeA* a_member;
};

// translate
//
// pub const struct_TypeB = extern struct {
// a_member: [*c]TypeA = null,
// };
// pub const TypeA = extern struct {
// b_member: [*c]struct_TypeB = null,
// };