From ee651c3cd358f40f60db0bbcd82ffde99aed9b88 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Sun, 29 May 2022 12:04:50 +0300 Subject: Revert "reserve correct space for bitfields" This reverts commit 22cb6938891c73d64b749a2516c8eaf79aa25b03. --- test/translate_c.zig | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) (limited to 'test') diff --git a/test/translate_c.zig b/test/translate_c.zig index 14b5783fef..c49aa55baa 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -915,6 +915,21 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\}; }); + cases.add("pointer to struct demoted to opaque due to bit fields", + \\struct Foo { + \\ unsigned int: 1; + \\}; + \\struct Bar { + \\ struct Foo *foo; + \\}; + , &[_][]const u8{ + \\pub const struct_Foo = opaque {}; + , + \\pub const struct_Bar = extern struct { + \\ foo: ?*struct_Foo, + \\}; + }); + cases.add("macro with left shift", \\#define REDISMODULE_READ (1<<0) , &[_][]const u8{ @@ -3562,33 +3577,34 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} }); - cases.add("function that dereferences bitfield works", + cases.add("Demote function that initializes opaque struct", \\struct my_struct { - \\ unsigned a: 1; - \\ unsigned b: 28; + \\ unsigned a: 15; + \\ unsigned: 2; + \\ unsigned b: 15; \\}; - \\void deref(struct my_struct *s) { - \\ *s; + \\void initialize(void) { + \\ struct my_struct S = {.a = 1, .b = 2}; \\} , &[_][]const u8{ - \\pub const struct_my_struct = extern struct { - \\ bitfield0: c_uint, + \\warning: cannot initialize opaque type , - \\pub export fn deref(arg_s: ?*struct_my_struct) void { - \\ var s = arg_s; - \\ _ = s.*; - \\} + \\warning: unable to translate function, demoted to extern + \\pub extern fn initialize() void; }); - cases.add("bitfield don't cover requedted space", - \\struct inner { + cases.add("Demote function that dereferences opaque type", + \\struct my_struct { \\ unsigned a: 1; - \\ char after; \\}; + \\void deref(struct my_struct *s) { + \\ *s; + \\} , &[_][]const u8{ - \\less bits used than field size. + \\warning: cannot dereference opaque type , - \\pub const struct_inner = opaque {}; + \\warning: unable to translate function, demoted to extern + \\pub extern fn deref(arg_s: ?*struct_my_struct) void; }); cases.add("Function prototype declared within function", -- cgit v1.2.3