authorgravatar for jay@jayschwa.netJay Petacat <jay@jayschwa.net> 2023-09-18 14:05:44-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-18 23:09:47-07:00
logf91ff9a746ff97945dacc8114c073bd279f68f17
tree0f33d39d2a96f0d5bbd80114b16e6e17360710ce
parent5af5d87ad2227b6a7b5347c7217312ef8a83de12

translate-c: Struct fields default to zero value

C99 introduced designated initializers for structs. Omitted fields are implicitly initialized to zero. Some C APIs are designed with this in mind. Defaulting to zero values for translated struct fields permits Zig code to comfortably use such an API. Closes #8165

3 files changed, 121 insertions(+), 98 deletions(-)

src/translate_c.zig+9
......@@ -1229,6 +1229,14 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD
12291229 else
12301230 ClangAlignment.forField(c, field_decl, record_def).zigAlignment();
12311231
1232 // C99 introduced designated initializers for structs. Omitted fields are implicitly
1233 // initialized to zero. Some C APIs are designed with this in mind. Defaulting to zero
1234 // values for translated struct fields permits Zig code to comfortably use such an API.
1235 const default_value = if (record_decl.isStruct())
1236 try Tag.std_mem_zeroes.create(c.arena, field_type)
1237 else
1238 null;
1239
12321240 if (is_anon) {
12331241 try c.decl_table.putNoClobber(c.gpa, @intFromPtr(field_decl.getCanonicalDecl()), field_name);
12341242 }
......@@ -1237,6 +1245,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD
12371245 .name = field_name,
12381246 .type = field_type,
12391247 .alignment = alignment,
1248 .default_value = default_value,
12401249 });
12411250 }
12421251
src/translate_c/ast.zig+34-20
......@@ -576,6 +576,7 @@ pub const Payload = struct {
576576 name: []const u8,
577577 type: Node,
578578 alignment: ?c_uint,
579 default_value: ?Node,
579580 };
580581 };
581582
......@@ -2095,34 +2096,47 @@ fn renderRecord(c: *Context, node: Node) !NodeIndex {
20952096 _ = try c.addToken(.colon, ":");
20962097 const type_expr = try renderNode(c, field.type);
20972098
2098 const alignment = field.alignment orelse {
2099 members[i] = try c.addNode(.{
2100 .tag = .container_field_init,
2101 .main_token = name_tok,
2102 .data = .{
2103 .lhs = type_expr,
2104 .rhs = 0,
2105 },
2099 const align_expr = if (field.alignment) |alignment| blk: {
2100 _ = try c.addToken(.keyword_align, "align");
2101 _ = try c.addToken(.l_paren, "(");
2102 const align_expr = try c.addNode(.{
2103 .tag = .number_literal,
2104 .main_token = try c.addTokenFmt(.number_literal, "{d}", .{alignment}),
2105 .data = undefined,
21062106 });
2107 _ = try c.addToken(.comma, ",");
2108 continue;
2109 };
2110 _ = try c.addToken(.keyword_align, "align");
2111 _ = try c.addToken(.l_paren, "(");
2112 const align_expr = try c.addNode(.{
2113 .tag = .number_literal,
2114 .main_token = try c.addTokenFmt(.number_literal, "{d}", .{alignment}),
2115 .data = undefined,
2116 });
2117 _ = try c.addToken(.r_paren, ")");
2107 _ = try c.addToken(.r_paren, ")");
2108 break :blk align_expr;
2109 } else 0;
21182110
2119 members[i] = try c.addNode(.{
2111 const value_expr = if (field.default_value) |value| blk: {
2112 _ = try c.addToken(.equal, "=");
2113 break :blk try renderNode(c, value);
2114 } else 0;
2115
2116 members[i] = try c.addNode(if (align_expr == 0) .{
2117 .tag = .container_field_init,
2118 .main_token = name_tok,
2119 .data = .{
2120 .lhs = type_expr,
2121 .rhs = value_expr,
2122 },
2123 } else if (value_expr == 0) .{
21202124 .tag = .container_field_align,
21212125 .main_token = name_tok,
21222126 .data = .{
21232127 .lhs = type_expr,
21242128 .rhs = align_expr,
21252129 },
2130 } else .{
2131 .tag = .container_field,
2132 .main_token = name_tok,
2133 .data = .{
2134 .lhs = type_expr,
2135 .rhs = try c.addExtra(std.zig.Ast.Node.ContainerField{
2136 .align_expr = align_expr,
2137 .value_expr = value_expr,
2138 }),
2139 },
21262140 });
21272141 _ = try c.addToken(.comma, ",");
21282142 }
test/translate_c.zig+78-78
......@@ -98,8 +98,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
9898 ++ " " ++ default_enum_type ++
9999 \\;
100100 \\pub const Bar = extern struct {
101 \\ a: c_int,
102 \\ b: c_int,
101 \\ a: c_int = @import("std").mem.zeroes(c_int),
102 \\ b: c_int = @import("std").mem.zeroes(c_int),
103103 \\};
104104 });
105105
......@@ -149,11 +149,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
149149 \\#define PTR void *
150150 , &[_][]const u8{
151151 \\pub const struct_Bar_1 = extern struct {
152 \\ a: c_int,
152 \\ a: c_int = @import("std").mem.zeroes(c_int),
153153 \\};
154154 \\pub const struct_Foo = extern struct {
155 \\ a: c_int,
156 \\ b: struct_Bar_1,
155 \\ a: c_int = @import("std").mem.zeroes(c_int),
156 \\ b: struct_Bar_1 = @import("std").mem.zeroes(struct_Bar_1),
157157 \\};
158158 \\pub export var a: struct_Foo = struct_Foo{
159159 \\ .a = 0,
......@@ -183,9 +183,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
183183 , &[_][]const u8{
184184 \\pub export fn foo() void {
185185 \\ const struct_Foo = extern struct {
186 \\ A: c_int,
187 \\ B: c_int,
188 \\ C: c_int,
186 \\ A: c_int = @import("std").mem.zeroes(c_int),
187 \\ B: c_int = @import("std").mem.zeroes(c_int),
188 \\ C: c_int = @import("std").mem.zeroes(c_int),
189189 \\ };
190190 \\ var a: struct_Foo = struct_Foo{
191191 \\ .A = @as(c_int, 0),
......@@ -195,9 +195,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
195195 \\ _ = @TypeOf(a);
196196 \\ {
197197 \\ const struct_Foo_1 = extern struct {
198 \\ A: c_int,
199 \\ B: c_int,
200 \\ C: c_int,
198 \\ A: c_int = @import("std").mem.zeroes(c_int),
199 \\ B: c_int = @import("std").mem.zeroes(c_int),
200 \\ C: c_int = @import("std").mem.zeroes(c_int),
201201 \\ };
202202 \\ var a_2: struct_Foo_1 = struct_Foo_1{
203203 \\ .A = @as(c_int, 0),
......@@ -286,7 +286,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
286286 \\source.h:1:9: warning: struct demoted to opaque type - unable to translate type of field foo
287287 \\pub const Foo = opaque {};
288288 \\pub const Bar = extern struct {
289 \\ bar: ?*Foo,
289 \\ bar: ?*Foo = @import("std").mem.zeroes(?*Foo),
290290 \\};
291291 });
292292
......@@ -375,10 +375,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
375375 \\#define B A(0.f)
376376 , &[_][]const u8{
377377 \\pub const struct_Color = extern struct {
378 \\ r: u8,
379 \\ g: u8,
380 \\ b: u8,
381 \\ a: u8,
378 \\ r: u8 = @import("std").mem.zeroes(u8),
379 \\ g: u8 = @import("std").mem.zeroes(u8),
380 \\ b: u8 = @import("std").mem.zeroes(u8),
381 \\ a: u8 = @import("std").mem.zeroes(u8),
382382 \\};
383383 \\pub const Color = struct_Color;
384384 ,
......@@ -389,14 +389,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
389389 \\pub const LIGHTGRAY = @import("std").mem.zeroInit(CLITERAL(Color), .{ @as(c_int, 200), @as(c_int, 200), @as(c_int, 200), @as(c_int, 255) });
390390 ,
391391 \\pub const struct_boom_t = extern struct {
392 \\ i1: c_int,
392 \\ i1: c_int = @import("std").mem.zeroes(c_int),
393393 \\};
394394 \\pub const boom_t = struct_boom_t;
395395 ,
396396 \\pub const FOO = @import("std").mem.zeroInit(boom_t, .{@as(c_int, 1)});
397397 ,
398398 \\pub const MyCStruct = extern struct {
399 \\ x: f32,
399 \\ x: f32 = @import("std").mem.zeroes(f32),
400400 \\};
401401 ,
402402 \\pub inline fn A(_x: anytype) MyCStruct {
......@@ -452,7 +452,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
452452 \\};
453453 , &[_][]const u8{
454454 \\pub const struct_foo = extern struct {
455 \\ bar: c_short align(1),
455 \\ bar: c_short align(1) = @import("std").mem.zeroes(c_short),
456456 \\};
457457 });
458458
......@@ -461,7 +461,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
461461 \\struct bar { int x; int y[0]; };
462462 , &[_][]const u8{
463463 \\pub const struct_foo = extern struct {
464 \\ x: c_int align(4),
464 \\ x: c_int align(4) = @import("std").mem.zeroes(c_int),
465465 \\ pub fn y(self: anytype) @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int) {
466466 \\ const Intermediate = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8);
467467 \\ const ReturnType = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int);
......@@ -469,7 +469,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
469469 \\ }
470470 \\};
471471 \\pub const struct_bar = extern struct {
472 \\ x: c_int align(4),
472 \\ x: c_int align(4) = @import("std").mem.zeroes(c_int),
473473 \\ pub fn y(self: anytype) @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int) {
474474 \\ const Intermediate = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8);
475475 \\ const ReturnType = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int);
......@@ -545,7 +545,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
545545 \\source.h:4:8: warning: struct demoted to opaque type - unable to translate type of field abufused
546546 \\pub const struct_arcan_shmif_page = opaque {};
547547 \\pub const struct_arcan_shmif_cont = extern struct {
548 \\ addr: ?*struct_arcan_shmif_page,
548 \\ addr: ?*struct_arcan_shmif_page = @import("std").mem.zeroes(?*struct_arcan_shmif_page),
549549 \\};
550550 });
551551
......@@ -562,10 +562,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
562562 \\pub const fnptr_ty = ?*const fn () callconv(.C) void;
563563 \\pub const fnptr_attr_ty = ?*const fn () callconv(.C) void;
564564 \\pub const struct_foo = extern struct {
565 \\ foo: ?*const fn () callconv(.C) void,
566 \\ bar: ?*const fn () callconv(.C) void,
567 \\ baz: fnptr_ty,
568 \\ qux: fnptr_attr_ty,
565 \\ foo: ?*const fn () callconv(.C) void = @import("std").mem.zeroes(?*const fn () callconv(.C) void),
566 \\ bar: ?*const fn () callconv(.C) void = @import("std").mem.zeroes(?*const fn () callconv(.C) void),
567 \\ baz: fnptr_ty = @import("std").mem.zeroes(fnptr_ty),
568 \\ qux: fnptr_attr_ty = @import("std").mem.zeroes(fnptr_attr_ty),
569569 \\};
570570 });
571571
......@@ -624,14 +624,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
624624 \\void foo(outer *x) { x->y = x->x; }
625625 , &[_][]const u8{
626626 \\const struct_unnamed_2 = extern struct {
627 \\ y: c_int,
627 \\ y: c_int = @import("std").mem.zeroes(c_int),
628628 \\};
629629 \\const union_unnamed_1 = extern union {
630630 \\ x: u8,
631631 \\ unnamed_0: struct_unnamed_2,
632632 \\};
633633 \\pub const outer = extern struct {
634 \\ unnamed_0: union_unnamed_1,
634 \\ unnamed_0: union_unnamed_1 = @import("std").mem.zeroes(union_unnamed_1),
635635 \\};
636636 \\pub export fn foo(arg_x: [*c]outer) void {
637637 \\ var x = arg_x;
......@@ -669,12 +669,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
669669 \\foo s3 = { 123 };
670670 , &[_][]const u8{
671671 \\pub const foo = extern struct {
672 \\ x: c_int,
672 \\ x: c_int = @import("std").mem.zeroes(c_int),
673673 \\};
674674 \\const struct_unnamed_1 = extern struct {
675 \\ x: f64,
676 \\ y: f64,
677 \\ z: f64,
675 \\ x: f64 = @import("std").mem.zeroes(f64),
676 \\ y: f64 = @import("std").mem.zeroes(f64),
677 \\ z: f64 = @import("std").mem.zeroes(f64),
678678 \\};
679679 \\pub export var s0: struct_unnamed_1 = struct_unnamed_1{
680680 \\ .x = 1.2,
......@@ -682,12 +682,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
682682 \\ .z = 0,
683683 \\};
684684 \\const struct_unnamed_2 = extern struct {
685 \\ sec: c_int,
686 \\ min: c_int,
687 \\ hour: c_int,
688 \\ day: c_int,
689 \\ mon: c_int,
690 \\ year: c_int,
685 \\ sec: c_int = @import("std").mem.zeroes(c_int),
686 \\ min: c_int = @import("std").mem.zeroes(c_int),
687 \\ hour: c_int = @import("std").mem.zeroes(c_int),
688 \\ day: c_int = @import("std").mem.zeroes(c_int),
689 \\ mon: c_int = @import("std").mem.zeroes(c_int),
690 \\ year: c_int = @import("std").mem.zeroes(c_int),
691691 \\};
692692 \\pub export var s1: struct_unnamed_2 = struct_unnamed_2{
693693 \\ .sec = @as(c_int, 30),
......@@ -698,8 +698,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
698698 \\ .year = @as(c_int, 2014),
699699 \\};
700700 \\const struct_unnamed_3 = extern struct {
701 \\ x: c_int,
702 \\ y: c_int,
701 \\ x: c_int = @import("std").mem.zeroes(c_int),
702 \\ y: c_int = @import("std").mem.zeroes(c_int),
703703 \\};
704704 \\pub export var s2: struct_unnamed_3 = struct_unnamed_3{
705705 \\ .x = @as(c_int, 1),
......@@ -730,9 +730,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
730730 \\struct {int x,y,z;} __attribute__((packed)) s0 = {1, 2};
731731 , &[_][]const u8{
732732 \\const struct_unnamed_1 = extern struct {
733 \\ x: c_int align(1),
734 \\ y: c_int align(1),
735 \\ z: c_int align(1),
733 \\ x: c_int align(1) = @import("std").mem.zeroes(c_int),
734 \\ y: c_int align(1) = @import("std").mem.zeroes(c_int),
735 \\ z: c_int align(1) = @import("std").mem.zeroes(c_int),
736736 \\};
737737 \\pub export var s0: struct_unnamed_1 = struct_unnamed_1{
738738 \\ .x = @as(c_int, 1),
......@@ -977,8 +977,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
977977 , &[_][]const u8{
978978 \\pub const lws_callback_function = fn () callconv(.C) void;
979979 \\pub const struct_Foo = extern struct {
980 \\ func: ?*const fn () callconv(.C) void,
981 \\ callback_http: ?*const lws_callback_function,
980 \\ func: ?*const fn () callconv(.C) void = @import("std").mem.zeroes(?*const fn () callconv(.C) void),
981 \\ callback_http: ?*const lws_callback_function = @import("std").mem.zeroes(?*const lws_callback_function),
982982 \\};
983983 });
984984
......@@ -993,7 +993,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
993993 \\pub const struct_Foo = opaque {};
994994 ,
995995 \\pub const struct_Bar = extern struct {
996 \\ foo: ?*struct_Foo,
996 \\ foo: ?*struct_Foo = @import("std").mem.zeroes(?*struct_Foo),
997997 \\};
998998 });
999999
......@@ -1025,13 +1025,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10251025 \\};
10261026 , &[_][]const u8{
10271027 \\pub const struct_Foo = extern struct {
1028 \\ a: [*c]Foo,
1028 \\ a: [*c]Foo = @import("std").mem.zeroes([*c]Foo),
10291029 \\};
10301030 ,
10311031 \\pub const Foo = struct_Foo;
10321032 ,
10331033 \\pub const struct_Bar = extern struct {
1034 \\ a: [*c]Foo,
1034 \\ a: [*c]Foo = @import("std").mem.zeroes([*c]Foo),
10351035 \\};
10361036 ,
10371037 \\pub const Bar = struct_Bar;
......@@ -1044,8 +1044,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10441044 \\};
10451045 , &[_][]const u8{
10461046 \\const struct_Foo = extern struct {
1047 \\ x: c_int,
1048 \\ y: [*c]u8,
1047 \\ x: c_int = @import("std").mem.zeroes(c_int),
1048 \\ y: [*c]u8 = @import("std").mem.zeroes([*c]u8),
10491049 \\};
10501050 ,
10511051 \\pub const Foo = struct_Foo;
......@@ -1057,7 +1057,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10571057 \\};
10581058 , &[_][]const u8{
10591059 \\pub const struct_Foo = extern struct {
1060 \\ derp: ?*const fn ([*c]struct_Foo) callconv(.C) void,
1060 \\ derp: ?*const fn ([*c]struct_Foo) callconv(.C) void = @import("std").mem.zeroes(?*const fn ([*c]struct_Foo) callconv(.C) void),
10611061 \\};
10621062 ,
10631063 \\pub const Foo = struct_Foo;
......@@ -1101,11 +1101,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11011101 \\};
11021102 , &[_][]const u8{
11031103 \\pub const struct_Bar = extern struct {
1104 \\ next: [*c]struct_Foo,
1104 \\ next: [*c]struct_Foo = @import("std").mem.zeroes([*c]struct_Foo),
11051105 \\};
11061106 ,
11071107 \\pub const struct_Foo = extern struct {
1108 \\ next: [*c]struct_Bar,
1108 \\ next: [*c]struct_Bar = @import("std").mem.zeroes([*c]struct_Bar),
11091109 \\};
11101110 });
11111111
......@@ -1121,7 +1121,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11211121 \\};
11221122 , &[_][]const u8{
11231123 \\pub const struct_comptime = extern struct {
1124 \\ @"defer": c_int,
1124 \\ @"defer": c_int = @import("std").mem.zeroes(c_int),
11251125 \\};
11261126 ,
11271127 \\pub const @"comptime" = struct_comptime;
......@@ -1421,8 +1421,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
14211421 // even though the parent struct is
14221422 // this is consistent with GCC docs
14231423 \\const struct_unnamed_1 = extern struct {
1424 \\ a: u8,
1425 \\ b: c_int,
1424 \\ a: u8 = @import("std").mem.zeroes(u8),
1425 \\ b: c_int = @import("std").mem.zeroes(c_int),
14261426 \\};
14271427 ,
14281428 \\pub const union_Foo = extern union {
......@@ -1448,8 +1448,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
14481448 // have an independent packed declaration on
14491449 // the nested type (see GCC docs for details)
14501450 \\const struct_unnamed_1 = extern struct {
1451 \\ a: u8 align(1),
1452 \\ b: c_int align(1),
1451 \\ a: u8 align(1) = @import("std").mem.zeroes(u8),
1452 \\ b: c_int align(1) = @import("std").mem.zeroes(c_int),
14531453 \\};
14541454 ,
14551455 \\pub const union_Foo = extern union {
......@@ -1905,8 +1905,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
19051905 ++ " " ++ default_enum_type ++
19061906 \\;
19071907 \\pub const struct_Baz = extern struct {
1908 \\ l: enum_unnamed_2,
1909 \\ m: d,
1908 \\ l: enum_unnamed_2 = @import("std").mem.zeroes(enum_unnamed_2),
1909 \\ m: d = @import("std").mem.zeroes(d),
19101910 \\};
19111911 \\pub const n: c_int = 0;
19121912 \\pub const o: c_int = 1;
......@@ -2010,7 +2010,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
20102010 \\pub const PFNGLCLEARPROC = ?*const fn (GLbitfield) callconv(.C) void;
20112011 \\pub const OpenGLProc = ?*const fn () callconv(.C) void;
20122012 \\const struct_unnamed_1 = extern struct {
2013 \\ Clear: PFNGLCLEARPROC,
2013 \\ Clear: PFNGLCLEARPROC = @import("std").mem.zeroes(PFNGLCLEARPROC),
20142014 \\};
20152015 \\pub const union_OpenGLProcs = extern union {
20162016 \\ ptr: [1]OpenGLProc,
......@@ -2362,10 +2362,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
23622362 \\};
23632363 , &[_][]const u8{
23642364 \\pub const struct_Bar_1 = extern struct {
2365 \\ b: c_int,
2365 \\ b: c_int = @import("std").mem.zeroes(c_int),
23662366 \\};
23672367 \\pub const struct_Foo = extern struct {
2368 \\ c: struct_Bar_1,
2368 \\ c: struct_Bar_1 = @import("std").mem.zeroes(struct_Bar_1),
23692369 \\};
23702370 });
23712371 }
......@@ -2576,8 +2576,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
25762576 \\void func(struct Foo *a, enum Bar **b);
25772577 , &[_][]const u8{
25782578 \\pub const struct_Foo = extern struct {
2579 \\ x: c_int,
2580 \\ y: c_int,
2579 \\ x: c_int = @import("std").mem.zeroes(c_int),
2580 \\ y: c_int = @import("std").mem.zeroes(c_int),
25812581 \\};
25822582 \\pub const BarA: c_int = 0;
25832583 \\pub const BarB: c_int = 1;
......@@ -2694,7 +2694,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
26942694 \\}
26952695 , &[_][]const u8{
26962696 \\pub const struct_Foo = extern struct {
2697 \\ b: c_int,
2697 \\ b: c_int = @import("std").mem.zeroes(c_int),
26982698 \\};
26992699 \\pub extern var a: struct_Foo;
27002700 \\pub export var b: f32 = 2.0;
......@@ -3604,12 +3604,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
36043604 \\} ONENAMEWITHSTRUCT;
36053605 , &[_][]const u8{
36063606 \\pub const struct_NAMED = extern struct {
3607 \\ name: c_long,
3607 \\ name: c_long = @import("std").mem.zeroes(c_long),
36083608 \\};
36093609 \\pub const NAMED = struct_NAMED;
36103610 \\pub const struct_ONENAMEWITHSTRUCT = extern struct {
3611 \\ unnamed_0: struct_NAMED,
3612 \\ b: c_long,
3611 \\ unnamed_0: struct_NAMED = = @import("std").mem.zeroes(struct_NAMED),
3612 \\ b: c_long = @import("std").mem.zeroes(c_long),
36133613 \\};
36143614 });
36153615 } else {
......@@ -3626,11 +3626,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
36263626 \\} ONENAMEWITHSTRUCT;
36273627 , &[_][]const u8{
36283628 \\pub const struct_NAMED = extern struct {
3629 \\ name: c_long,
3629 \\ name: c_long = @import("std").mem.zeroes(c_long),
36303630 \\};
36313631 \\pub const NAMED = struct_NAMED;
36323632 \\pub const struct_ONENAMEWITHSTRUCT = extern struct {
3633 \\ b: c_long,
3633 \\ b: c_long = @import("std").mem.zeroes(c_long),
36343634 \\};
36353635 });
36363636 }
......@@ -3645,11 +3645,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
36453645 , &[_][]const u8{
36463646 \\const struct_unnamed_1 = extern struct {};
36473647 \\pub const struct_a = extern struct {
3648 \\ unnamed_0: struct_unnamed_1,
3648 \\ unnamed_0: struct_unnamed_1 = @import("std").mem.zeroes(struct_unnamed_1),
36493649 \\};
36503650 \\const struct_unnamed_2 = extern struct {};
36513651 \\pub const struct_b = extern struct {
3652 \\ unnamed_0: struct_unnamed_2,
3652 \\ unnamed_0: struct_unnamed_2 = @import("std").mem.zeroes(struct_unnamed_2),
36533653 \\};
36543654 });
36553655
......@@ -3783,8 +3783,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
37833783 \\pub const struct_inner = opaque {};
37843784 ,
37853785 \\pub const struct_outer = extern struct {
3786 \\ thing: c_int,
3787 \\ sub_struct: struct_inner,
3786 \\ thing: c_int = @import("std").mem.zeroes(c_int),
3787 \\ sub_struct: struct_inner = @import("std").mem.zeroes(struct_inner),
37883788 \\};
37893789 ,
37903790 \\warning: unable to translate function, demoted to extern
......@@ -3812,8 +3812,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
38123812 \\}
38133813 , &[_][]const u8{
38143814 \\pub const struct_FOO = extern struct {
3815 \\ x: c_int,
3816 \\ y: c_int,
3815 \\ x: c_int = @import("std").mem.zeroes(c_int),
3816 \\ y: c_int = @import("std").mem.zeroes(c_int),
38173817 \\};
38183818 \\pub export fn bar() c_int {
38193819 \\ const foo = struct {
......@@ -4143,7 +4143,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
41434143 \\const char *struct_foo = "hello world";
41444144 , &[_][]const u8{
41454145 \\pub const struct_foo_1 = extern struct {
4146 \\ x: c_int,
4146 \\ x: c_int = @import("std").mem.zeroes(c_int),
41474147 \\};
41484148 ,
41494149 \\pub const foo = struct_foo_1;