translate-c: deduplicate global declaration

Fix #15456

Signed-off-by: Tw <weii.tan>
This commit is contained in:
Tw 2023-04-26 17:21:56 +08:00 committed by Veikka Tuominen
parent 363269a2a9
commit 131b328c10

View File

@ -4195,8 +4195,11 @@ fn maybeSuppressResult(c: *Context, used: ResultUsed, result: Node) TransError!N
}
fn addTopLevelDecl(c: *Context, name: []const u8, decl_node: Node) !void {
try c.global_scope.sym_table.put(name, decl_node);
try c.global_scope.nodes.append(decl_node);
const gop = try c.global_scope.sym_table.getOrPut(name);
if (!gop.found_existing) {
gop.value_ptr.* = decl_node;
try c.global_scope.nodes.append(decl_node);
}
}
fn transQualTypeInitializedStringLiteral(c: *Context, elem_ty: Node, string_lit: *const clang.StringLiteral) TypeError!Node {