mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
Use mem.zeroes for empty union initializer list
This commit is contained in:
parent
fc48bbdf90
commit
d7a27bf803
@ -2505,6 +2505,11 @@ fn transInitListExprRecord(
|
||||
var field_inits = std.ArrayList(ast.Payload.ContainerInit.Initializer).init(c.gpa);
|
||||
defer field_inits.deinit();
|
||||
|
||||
if (init_count == 0) {
|
||||
const source_loc = @as(*const clang.Expr, @ptrCast(expr)).getBeginLoc();
|
||||
return transZeroInitExpr(c, scope, source_loc, ty);
|
||||
}
|
||||
|
||||
var init_i: c_uint = 0;
|
||||
var it = record_def.field_begin();
|
||||
const end_it = record_def.field_end();
|
||||
|
||||
20
test/cases/translate_c/empty union initializer list.c
Normal file
20
test/cases/translate_c/empty union initializer list.c
Normal file
@ -0,0 +1,20 @@
|
||||
union U {
|
||||
int x;
|
||||
long y;
|
||||
};
|
||||
|
||||
void foo(void) {
|
||||
union U u = {};
|
||||
}
|
||||
// translate-c
|
||||
// target=x86_64-linux
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub const union_U = extern union {
|
||||
// x: c_int,
|
||||
// y: c_long,
|
||||
// };
|
||||
// pub export fn foo() void {
|
||||
// var u: union_U = @import("std").mem.zeroes(union_U);
|
||||
// _ = &u;
|
||||
// }
|
||||
@ -11,7 +11,7 @@ static inline void foo() {
|
||||
// pub const struct_empty_struct = extern struct {};
|
||||
// pub fn foo() callconv(.C) void {
|
||||
// const bar = struct {
|
||||
// var static: struct_empty_struct = struct_empty_struct{};
|
||||
// var static: struct_empty_struct = @import("std").mem.zeroes(struct_empty_struct);
|
||||
// };
|
||||
// _ = &bar;
|
||||
// }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user