aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-05-29 12:04:50 +0300
committerVeikka Tuominen <git@vexu.eu>2022-05-29 12:04:50 +0300
commitee651c3cd358f40f60db0bbcd82ffde99aed9b88 (patch)
tree5d5830d5b3ce6c13041aacb7e073763551cb4852 /test
parent22cb6938891c73d64b749a2516c8eaf79aa25b03 (diff)
downloadzig-ee651c3cd358f40f60db0bbcd82ffde99aed9b88.tar.gz
zig-ee651c3cd358f40f60db0bbcd82ffde99aed9b88.zip
Revert "reserve correct space for bitfields"
This reverts commit 22cb6938891c73d64b749a2516c8eaf79aa25b03.
Diffstat (limited to 'test')
-rw-r--r--test/translate_c.zig48
1 files changed, 32 insertions, 16 deletions
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",