diff options
| author | Tw <weii.tan> | 2023-04-26 17:21:56 +0800 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2023-04-27 11:13:16 +0300 |
| commit | 131b328c10abde0193c13073b5ab82f0031fb121 (patch) | |
| tree | 7d346d88973d8112e07c76e55a9d2bd0daa04e02 /src | |
| parent | 363269a2a9aa71d909aa28f2f9c68c4220ae3d0b (diff) | |
| download | zig-131b328c10abde0193c13073b5ab82f0031fb121.tar.gz zig-131b328c10abde0193c13073b5ab82f0031fb121.zip | |
translate-c: deduplicate global declaration
Fix #15456
Signed-off-by: Tw <weii.tan>
Diffstat (limited to 'src')
| -rw-r--r-- | src/translate_c.zig | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/translate_c.zig b/src/translate_c.zig index 920da77cfd..7ad58329df 100644 --- a/src/translate_c.zig +++ b/src/translate_c.zig @@ -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 { |
