| author | |
| committer | |
| log | 8f8efcdd6e333e5ee3cf406fd095d0c8d47ab89c |
| tree | 7a07814a436f444fb6e60fd6a7cf09d3dce7d581 |
| parent | 9c03b39d1ebb52a94f1e6ee6f92a19f54a0ee528 |
2 files changed, 21 insertions(+), 1 deletions(-)
src/translate_c.zig+7-1| ... | ... | @@ -447,7 +447,13 @@ fn declVisitorNamesOnly(c: *Context, decl: *const clang.Decl) Error!void { |
| 447 | 447 | // TODO https://github.com/ziglang/zig/issues/3756 |
| 448 | 448 | // TODO https://github.com/ziglang/zig/issues/1802 |
| 449 | 449 | const name = if (isZigPrimitiveType(decl_name)) try std.fmt.allocPrint(c.arena, "{s}_{d}", .{ decl_name, c.getMangle() }) else decl_name; |
| 450 | try c.unnamed_typedefs.putNoClobber(c.gpa, addr, name); | |
| 450 | const result = try c.unnamed_typedefs.getOrPut(c.gpa, addr); | |
| 451 | if (result.found_existing) { | |
| 452 | // One typedef can declare multiple names. | |
| 453 | // Don't put this one in `decl_table` so it's processed later. | |
| 454 | return; | |
| 455 | } | |
| 456 | result.entry.value = name; | |
| 451 | 457 | // Put this typedef in the decl_table to avoid redefinitions. |
| 452 | 458 | try c.decl_table.putNoClobber(c.gpa, @ptrToInt(typedef_decl.getCanonicalDecl()), name); |
| 453 | 459 | } |
test/run_translated_c.zig+14| ... | ... | @@ -1476,4 +1476,18 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void { |
| 1476 | 1476 | \\ return 0; |
| 1477 | 1477 | \\} |
| 1478 | 1478 | , ""); |
| 1479 | ||
| 1480 | cases.add("typedef with multiple names", | |
| 1481 | \\#include <stdlib.h> | |
| 1482 | \\typedef struct { | |
| 1483 | \\ char field; | |
| 1484 | \\} a_t, b_t; | |
| 1485 | \\ | |
| 1486 | \\int main(void) { | |
| 1487 | \\ a_t a = { .field = 42 }; | |
| 1488 | \\ b_t b = a; | |
| 1489 | \\ if (b.field != 42) abort(); | |
| 1490 | \\ return 0; | |
| 1491 | \\} | |
| 1492 | , ""); | |
| 1479 | 1493 | } |