diff --git a/test/cases/run/compound_assignments_with_implicit_casts.c b/test/cases/run/compound_assignments_with_implicit_casts.c new file mode 100644 index 0000000..863a6c4 --- /dev/null +++ b/test/cases/run/compound_assignments_with_implicit_casts.c @@ -0,0 +1,20 @@ +int main() { + int i = 2; + float f = 3.2f; + + i += 1.7; + if (i != 3) return 1; + i += f; + if (i != 6) return 2; + + + f += 2UL; + if (f <= 5.1999 || f >= 5.2001) return 3; + f += i; + if (f <= 11.1999 || f >= 11.2001) return 4; + + return 0; +} + +// run +// expect=fail diff --git a/test/cases/run/compound_assignments_with_pointer_arithmetic.c b/test/cases/run/compound_assignments_with_pointer_arithmetic.c new file mode 100644 index 0000000..14cef05 --- /dev/null +++ b/test/cases/run/compound_assignments_with_pointer_arithmetic.c @@ -0,0 +1,21 @@ +int main() { + const char *s = "forgreatjustice"; + unsigned int add = 1; + + s += add; + if (*s != 'o') return 1; + + s += 1UL; + if (*s != 'r') return 2; + + const char *s2 = (s += add); + if (*s2 != 'g') return 3; + + s2 -= add; + if (*s2 != 'r') return 4; + + return 0; +} + +// run +// expect=fail diff --git a/test/cases/run/dereference address of.c b/test/cases/run/dereference address of.c new file mode 100644 index 0000000..71bdf22 --- /dev/null +++ b/test/cases/run/dereference address of.c @@ -0,0 +1,10 @@ +#include +int main(void) { + int i = 0; + *&i = 42; + if (i != 42) abort(); + return 0; +} + +// run +// expect=fail diff --git a/test/cases/run/explicit_cast_bool_from_float.c b/test/cases/run/explicit_cast_bool_from_float.c new file mode 100644 index 0000000..47b68cf --- /dev/null +++ b/test/cases/run/explicit_cast_bool_from_float.c @@ -0,0 +1,10 @@ +#include + +int main() { + float f = 2.0f; + bool b = (bool) f; + return 0; +} + +// run +// expect=fail diff --git a/test/cases/run/extern_typedef_variables_in_functions.c b/test/cases/run/extern_typedef_variables_in_functions.c new file mode 100644 index 0000000..7247652 --- /dev/null +++ b/test/cases/run/extern_typedef_variables_in_functions.c @@ -0,0 +1,22 @@ +const int ev = 40; + +static int func(void) +{ + typedef int test_type_t; + extern const test_type_t ev; + // Ensure mangled name is also being used for conditions and loops, see #20828 + if (ev == 0); + while (ev == 0); + do; while (ev == 0); + return ev + 2; +} + +int main() +{ + if (func() != 42) + return 1; + return 0; +} + +// run +// expect=fail diff --git a/test/cases/run/float_from_bool_expr_cast.c b/test/cases/run/float_from_bool_expr_cast.c new file mode 100644 index 0000000..5884523 --- /dev/null +++ b/test/cases/run/float_from_bool_expr_cast.c @@ -0,0 +1,7 @@ +int main() { + float f = (float)(10.0f > 1.0f); + return 0; +} + +// run +// expect=fail diff --git a/test/cases/translate/_Static_assert.c b/test/cases/translate/_Static_assert.c new file mode 100644 index 0000000..1196cee --- /dev/null +++ b/test/cases/translate/_Static_assert.c @@ -0,0 +1,6 @@ +_Static_assert(1 == 1, ""); + +// translate +// target=x86_64-linux +// +// tmp.c:1:1: warning: ignoring _Static_assert declaration diff --git a/test/cases/translate/align() attribute.c b/test/cases/translate/align() attribute.c new file mode 100644 index 0000000..c1d8167 --- /dev/null +++ b/test/cases/translate/align() attribute.c @@ -0,0 +1,17 @@ +__attribute__ ((aligned(128))) +extern char my_array[16]; +__attribute__ ((aligned(128))) +void my_fn(void) { } +void other_fn(void) { + char ARR[16] __attribute__ ((aligned (16))); +} + +// translate +// expect=fail +// +// pub extern var my_array: [16]u8 align(128); +// pub export fn my_fn() align(128) void {} +// pub export fn other_fn() void { +// var ARR: [16]u8 align(16) = undefined; +// _ = &ARR; +// } diff --git a/test/cases/translate/assert_with_strlit.c b/test/cases/translate/assert_with_strlit.c new file mode 100644 index 0000000..0fc4d86 --- /dev/null +++ b/test/cases/translate/assert_with_strlit.c @@ -0,0 +1,8 @@ + +void assert(int x) {} +#define FOO assert(0 && "error message") + +// translate +// expect=fail +// +// pub const FOO = assert((@as(c_int, 0) != 0) and (@intFromPtr("error message") != 0)); diff --git a/test/cases/translate/atomic types.c b/test/cases/translate/atomic types.c new file mode 100644 index 0000000..02b9d32 --- /dev/null +++ b/test/cases/translate/atomic types.c @@ -0,0 +1,7 @@ +typedef _Atomic(int) AtomicInt; + +// translate +// target=x86_64-linux +// +// tmp.c:1:22: warning: unsupported type: '_Atomic(int)' +// pub const AtomicInt = @compileError("unable to resolve typedef child type"); diff --git a/test/cases/translate/circular_struct_definitions.c b/test/cases/translate/circular_struct_definitions.c new file mode 100644 index 0000000..bee0296 --- /dev/null +++ b/test/cases/translate/circular_struct_definitions.c @@ -0,0 +1,20 @@ +struct Bar; + +struct Foo { + struct Bar *next; +}; + +struct Bar { + struct Foo *next; +}; + +// translate +// expect=fail +// +// pub const struct_Bar = extern struct { +// next: [*c]struct_Foo = @import("std").mem.zeroes([*c]struct_Foo), +// }; +// +// pub const struct_Foo = extern struct { +// next: [*c]struct_Bar = @import("std").mem.zeroes([*c]struct_Bar), +// }; diff --git a/test/cases/translate/double_define_struct.c b/test/cases/translate/double_define_struct.c new file mode 100644 index 0000000..5c8aa5c --- /dev/null +++ b/test/cases/translate/double_define_struct.c @@ -0,0 +1,25 @@ +typedef struct Bar Bar; +typedef struct Foo Foo; + +struct Foo { + Foo *a; +}; + +struct Bar { + Foo *a; +}; + +// translate +// expect=fail +// +// pub const struct_Foo = extern struct { +// a: [*c]Foo = @import("std").mem.zeroes([*c]Foo), +// }; +// +// pub const Foo = struct_Foo; +// +// pub const struct_Bar = extern struct { +// a: [*c]Foo = @import("std").mem.zeroes([*c]Foo), +// }; +// +// pub const Bar = struct_Bar; diff --git a/test/cases/translate/empty declaration.c b/test/cases/translate/empty declaration.c new file mode 100644 index 0000000..5f6ac3a --- /dev/null +++ b/test/cases/translate/empty declaration.c @@ -0,0 +1,4 @@ +; + +//translate +// \ No newline at end of file diff --git a/test/cases/translate/empty union initializer list.c b/test/cases/translate/empty union initializer list.c new file mode 100644 index 0000000..7315b25 --- /dev/null +++ b/test/cases/translate/empty union initializer list.c @@ -0,0 +1,20 @@ +union U { + int x; + long y; +}; + +void foo(void) { + union U u = {}; +} +// translate +// target=x86_64-linux +// expect=fail +// +// 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; +// } diff --git a/test/cases/translate/enums msvc.c b/test/cases/translate/enums msvc.c new file mode 100644 index 0000000..ecd52e0 --- /dev/null +++ b/test/cases/translate/enums msvc.c @@ -0,0 +1,16 @@ +enum Foo { + FooA = 2, + FooB = 5, + Foo1, +}; + +// translate +// target=x86_64-windows-msvc +// expect=fail +// +// pub const FooA: c_int = 2; +// pub const FooB: c_int = 5; +// pub const Foo1: c_int = 6; +// pub const enum_Foo = c_int; +// +// pub const Foo = enum_Foo; diff --git a/test/cases/translate/enums.c b/test/cases/translate/enums.c new file mode 100644 index 0000000..b09f7d8 --- /dev/null +++ b/test/cases/translate/enums.c @@ -0,0 +1,15 @@ +enum Foo { + FooA = 2, + FooB = 5, + Foo1, +}; + +// translate +// target=x86_64-linux +// +// pub const FooA: c_int = 2; +// pub const FooB: c_int = 5; +// pub const Foo1: c_int = 6; +// pub const enum_Foo = c_uint; +// +// pub const Foo = enum_Foo; diff --git a/test/cases/translate/field_access_is_grouped_if_necessary.c b/test/cases/translate/field_access_is_grouped_if_necessary.c new file mode 100644 index 0000000..09851ed --- /dev/null +++ b/test/cases/translate/field_access_is_grouped_if_necessary.c @@ -0,0 +1,18 @@ +unsigned long foo(unsigned long x) { + return ((union{unsigned long _x}){x})._x; +} + +// translate +// expect=fail +// +// pub export fn foo(arg_x: c_ulong) c_ulong { +// var x = arg_x; +// _ = &x; +// const union_unnamed_1 = extern union { +// _x: c_ulong, +// }; +// _ = &union_unnamed_1; +// return (union_unnamed_1{ +// ._x = x, +// })._x; +// } diff --git a/test/cases/translate/function prototype with parenthesis.c b/test/cases/translate/function prototype with parenthesis.c new file mode 100644 index 0000000..cdc0e08 --- /dev/null +++ b/test/cases/translate/function prototype with parenthesis.c @@ -0,0 +1,9 @@ +void (f0) (void *L); +void ((f1)) (void *L); +void (((f2))) (void *L); + +// translate +// +// pub extern fn f0(L: ?*anyopaque) void; +// pub extern fn f1(L: ?*anyopaque) void; +// pub extern fn f2(L: ?*anyopaque) void; diff --git a/test/cases/translate/global_struct_whose_default_name_conflicts_with_global_is_mangled.c b/test/cases/translate/global_struct_whose_default_name_conflicts_with_global_is_mangled.c new file mode 100644 index 0000000..8665944 --- /dev/null +++ b/test/cases/translate/global_struct_whose_default_name_conflicts_with_global_is_mangled.c @@ -0,0 +1,15 @@ +struct foo { + int x; +}; +const char *struct_foo = "hello world"; + +// translate +// expect=fail +// +// pub const struct_foo_1 = extern struct { +// x: c_int = @import("std").mem.zeroes(c_int), +// }; +// +// pub const foo = struct_foo_1; +// +// pub export var struct_foo: [*c]const u8 = "hello world"; diff --git a/test/cases/translate/large_packed_struct.c b/test/cases/translate/large_packed_struct.c new file mode 100644 index 0000000..8b4afad --- /dev/null +++ b/test/cases/translate/large_packed_struct.c @@ -0,0 +1,19 @@ +struct __attribute__((packed)) bar { + short a; + float b; + double c; + short x; + float y; + double z; +}; + +// translate +// +// pub const struct_bar = extern struct { +// a: c_short align(1) = @import("std").mem.zeroes(c_short), +// b: f32 align(1) = @import("std").mem.zeroes(f32), +// c: f64 align(1) = @import("std").mem.zeroes(f64), +// x: c_short align(1) = @import("std").mem.zeroes(c_short), +// y: f32 align(1) = @import("std").mem.zeroes(f32), +// z: f64 align(1) = @import("std").mem.zeroes(f64), +// }; diff --git a/test/cases/translate/macro_function_string_concat.c b/test/cases/translate/macro_function_string_concat.c new file mode 100644 index 0000000..7bea44f --- /dev/null +++ b/test/cases/translate/macro_function_string_concat.c @@ -0,0 +1,11 @@ +#define bar() "" +#define FOO bar() "," bar() + +// translate +// target=x86_64-linux +// expect=fail +// +// pub inline fn bar() @TypeOf("") { +// return ""; +// } +// pub const FOO = bar() ++ "," ++ bar(); diff --git a/test/cases/translate/macro_referencing_var.c b/test/cases/translate/macro_referencing_var.c new file mode 100644 index 0000000..e0e0d26 --- /dev/null +++ b/test/cases/translate/macro_referencing_var.c @@ -0,0 +1,21 @@ +extern float foo; +#define FOO_TWICE foo * 2.0f +#define FOO_NEGATIVE -foo + +#define BAR 10.0f +#define BAR_TWICE BAR * 2.0f + +// translate +// expect=fail +// +// pub extern var foo: f32; +// +// pub inline fn FOO_TWICE() @TypeOf(foo * @as(f32, 2.0)) { +// return foo * @as(f32, 2.0); +// } +// +// pub inline fn FOO_NEGATIVE() @TypeOf(-foo) { +// return -foo; +// } +// pub const BAR = @as(f32, 10.0); +// pub const BAR_TWICE = BAR * @as(f32, 2.0); diff --git a/test/cases/translate/noreturn attribute.c b/test/cases/translate/noreturn attribute.c new file mode 100644 index 0000000..84d91d4 --- /dev/null +++ b/test/cases/translate/noreturn attribute.c @@ -0,0 +1,5 @@ +void foo(void) __attribute__((noreturn)); + +// translate +// +// pub extern fn foo() noreturn; diff --git a/test/cases/translate/packed_union_nested_unpacked.c b/test/cases/translate/packed_union_nested_unpacked.c new file mode 100644 index 0000000..3520b44 --- /dev/null +++ b/test/cases/translate/packed_union_nested_unpacked.c @@ -0,0 +1,24 @@ +// NOTE: The nested struct is *not* packed/aligned, +// even though the parent struct is +// this is consistent with GCC docs +union Foo{ + short x; + double y; + struct { + int b; + } z; +} __attribute__((packed)); + +// translate +// +// const struct_unnamed_1 = extern struct { +// b: c_int = @import("std").mem.zeroes(c_int), +// }; +// +// pub const union_Foo = extern union { +// x: c_short align(1), +// y: f64 align(1), +// z: struct_unnamed_1 align(1), +// }; +// +// pub const Foo = union_Foo; diff --git a/test/cases/translate/packed_union_simple.c b/test/cases/translate/packed_union_simple.c new file mode 100644 index 0000000..80a00a9 --- /dev/null +++ b/test/cases/translate/packed_union_simple.c @@ -0,0 +1,13 @@ +union Foo { + short x; + double y; +} __attribute__((packed)); + +// translate +// +// pub const union_Foo = extern union { +// x: c_short align(1), +// y: f64 align(1), +// }; +// +// pub const Foo = union_Foo; diff --git a/test/cases/translate/pointer_to_struct_demoted_opaque_due_to_bit_fields.c b/test/cases/translate/pointer_to_struct_demoted_opaque_due_to_bit_fields.c new file mode 100644 index 0000000..8b32092 --- /dev/null +++ b/test/cases/translate/pointer_to_struct_demoted_opaque_due_to_bit_fields.c @@ -0,0 +1,15 @@ +struct Foo { + unsigned int: 1; +}; +struct Bar { + struct Foo *foo; +}; + +// translate +// expect=fail +// +// pub const struct_Foo = opaque {}; +// +// pub const struct_Bar = extern struct { +// foo: ?*struct_Foo = @import("std").mem.zeroes(?*struct_Foo), +// }; diff --git a/test/cases/translate/qualified_struct_and_enum.c b/test/cases/translate/qualified_struct_and_enum.c new file mode 100644 index 0000000..a2406e7 --- /dev/null +++ b/test/cases/translate/qualified_struct_and_enum.c @@ -0,0 +1,25 @@ +struct Foo { + int x; + int y; +}; +enum Bar { + BarA, + BarB, +}; +void func(struct Foo *a, enum Bar **b); + +// translate +// expect=fail +// target=x86_64-linux +// +// pub const struct_Foo = extern struct { +// x: c_int = @import("std").mem.zeroes(c_int), +// y: c_int = @import("std").mem.zeroes(c_int), +// }; +// pub const BarA: c_int = 0; +// pub const BarB: c_int = 1; +// pub const enum_Bar = c_uint; +// pub extern fn func(a: [*c]struct_Foo, b: [*c][*c]enum_Bar) void; +// +// pub const Foo = struct_Foo; +// pub const Bar = enum_Bar; diff --git a/test/cases/translate/qualified_struct_and_enum_msvc.c b/test/cases/translate/qualified_struct_and_enum_msvc.c new file mode 100644 index 0000000..210ba72 --- /dev/null +++ b/test/cases/translate/qualified_struct_and_enum_msvc.c @@ -0,0 +1,25 @@ +struct Foo { + int x; + int y; +}; +enum Bar { + BarA, + BarB, +}; +void func(struct Foo *a, enum Bar **b); + +// translate +// expect=fail +// target=x86_64-windows-msvc +// +// pub const struct_Foo = extern struct { +// x: c_int = @import("std").mem.zeroes(c_int), +// y: c_int = @import("std").mem.zeroes(c_int), +// }; +// pub const BarA: c_int = 0; +// pub const BarB: c_int = 1; +// pub const enum_Bar = c_int; +// pub extern fn func(a: [*c]struct_Foo, b: [*c][*c]enum_Bar) void; +// +// pub const Foo = struct_Foo; +// pub const Bar = enum_Bar; diff --git a/test/cases/translate/scoped_record.c b/test/cases/translate/scoped_record.c new file mode 100644 index 0000000..aa1ba34 --- /dev/null +++ b/test/cases/translate/scoped_record.c @@ -0,0 +1,49 @@ +void foo() { + struct Foo { + int A; + int B; + int C; + }; + struct Foo a = {0}; + { + struct Foo { + int A; + int B; + int C; + }; + struct Foo a = {0}; + } +} + +// translate +// expect=fail +// +// pub export fn foo() void { +// const struct_Foo = extern struct { +// A: c_int = @import("std").mem.zeroes(c_int), +// B: c_int = @import("std").mem.zeroes(c_int), +// C: c_int = @import("std").mem.zeroes(c_int), +// }; +// _ = &struct_Foo; +// var a: struct_Foo = struct_Foo{ +// .A = @as(c_int, 0), +// .B = 0, +// .C = 0, +// }; +// _ = &a; +// { +// const struct_Foo_1 = extern struct { +// A: c_int = @import("std").mem.zeroes(c_int), +// B: c_int = @import("std").mem.zeroes(c_int), +// C: c_int = @import("std").mem.zeroes(c_int), +// }; +// _ = &struct_Foo_1; +// var a_2: struct_Foo_1 = struct_Foo_1{ +// .A = @as(c_int, 0), +// .B = 0, +// .C = 0, +// }; +// _ = &a_2; +// } +// } + diff --git a/test/cases/translate/simple function prototypes.c b/test/cases/translate/simple function prototypes.c new file mode 100644 index 0000000..fe6a172 --- /dev/null +++ b/test/cases/translate/simple function prototypes.c @@ -0,0 +1,7 @@ +void __attribute__((noreturn)) foo(void); +int bar(void); + +// translate +// +// pub extern fn foo() noreturn; +// pub extern fn bar() c_int; diff --git a/test/cases/translate/simple_struct.c b/test/cases/translate/simple_struct.c new file mode 100644 index 0000000..1dfd422 --- /dev/null +++ b/test/cases/translate/simple_struct.c @@ -0,0 +1,11 @@ +struct Foo { + int x; +}; + +// translate +// +// const struct_Foo = extern struct { +// x: c_int = @import("std").mem.zeroes(c_int), +// }; +// +// pub const Foo = struct_Foo; diff --git a/test/cases/translate/simple_union.c b/test/cases/translate/simple_union.c new file mode 100644 index 0000000..1217fcc --- /dev/null +++ b/test/cases/translate/simple_union.c @@ -0,0 +1,11 @@ +union Foo { + int x; +}; + +// translate +// +// pub const union_Foo = extern union { +// x: c_int, +// }; +// +// pub const Foo = union_Foo; diff --git a/test/cases/translate/static empty struct.c b/test/cases/translate/static empty struct.c new file mode 100644 index 0000000..7b82639 --- /dev/null +++ b/test/cases/translate/static empty struct.c @@ -0,0 +1,17 @@ +struct empty_struct {}; + +static inline void foo() { + static struct empty_struct bar = {}; +} + +// translate +// target=x86_64-linux +// expect=fail +// +// pub const struct_empty_struct = extern struct {}; +// pub fn foo() callconv(.c) void { +// const bar = struct { +// var static: struct_empty_struct = @import("std").mem.zeroes(struct_empty_struct); +// }; +// _ = &bar; +// } diff --git a/test/cases/translate/strlit_as_bool.c b/test/cases/translate/strlit_as_bool.c new file mode 100644 index 0000000..10d7e75 --- /dev/null +++ b/test/cases/translate/strlit_as_bool.c @@ -0,0 +1,8 @@ +void foo() { if(0 && "error message") {} } + +// translate +// expect=fail +// +// pub export fn foo() void { +// if (false and (@intFromPtr("error message") != 0)) {} +// } diff --git a/test/cases/translate/struct prototype used in func.c b/test/cases/translate/struct prototype used in func.c new file mode 100644 index 0000000..65c74dc --- /dev/null +++ b/test/cases/translate/struct prototype used in func.c @@ -0,0 +1,9 @@ +struct Foo; +struct Foo *some_func(struct Foo *foo, int x); + +// translate +// +// pub const struct_Foo = opaque {}; +// pub extern fn some_func(foo: ?*struct_Foo, x: c_int) ?*struct_Foo; +// +// pub const Foo = struct_Foo; diff --git a/test/cases/translate/struct_in_struct_init_to_zero.c b/test/cases/translate/struct_in_struct_init_to_zero.c new file mode 100644 index 0000000..88a1604 --- /dev/null +++ b/test/cases/translate/struct_in_struct_init_to_zero.c @@ -0,0 +1,24 @@ +struct Foo { + int a; + struct Bar { + int a; + } b; +} a = {}; +#define PTR void * + +// translate +// expect=fail +// +// pub const struct_Bar_1 = extern struct { +// a: c_int = @import("std").mem.zeroes(c_int), +// }; +// pub const struct_Foo = extern struct { +// a: c_int = @import("std").mem.zeroes(c_int), +// b: struct_Bar_1 = @import("std").mem.zeroes(struct_Bar_1), +// }; +// pub export var a: struct_Foo = struct_Foo{ +// .a = 0, +// .b = @import("std").mem.zeroes(struct_Bar_1), +// }; +// +// pub const PTR = ?*anyopaque; diff --git a/test/cases/translate/struct_with_aligned_fields.c b/test/cases/translate/struct_with_aligned_fields.c new file mode 100644 index 0000000..bc9f608 --- /dev/null +++ b/test/cases/translate/struct_with_aligned_fields.c @@ -0,0 +1,9 @@ +struct foo { + __attribute__((aligned(4))) short bar; +}; + +// translate +// +// pub const struct_foo = extern struct { +// bar: c_short align(4) = @import("std").mem.zeroes(c_short), +// }; diff --git a/test/cases/translate/struct_with_invalid_field_alignment.c b/test/cases/translate/struct_with_invalid_field_alignment.c new file mode 100644 index 0000000..c246bed --- /dev/null +++ b/test/cases/translate/struct_with_invalid_field_alignment.c @@ -0,0 +1,34 @@ +// The aligned attribute cannot decrease the alignment of a field. The packed attribute is required +// for decreasing the alignment. gcc and clang will compile these structs without error +// (and possibly without warning), but checking the alignment will reveal a different value than +// what was requested. This is consistent with the gcc documentation on type attributes. +// +// This test is currently broken for the clang frontend. See issue #19307. + +struct foo { + __attribute__((aligned(1)))int x; +}; + +struct bar { + __attribute__((aligned(2)))float y; +}; + +struct baz { + __attribute__((aligned(4)))double z; +}; + +// translate +// target=x86_64-linux +// +// pub const struct_foo = extern struct { +// x: c_int = @import("std").mem.zeroes(c_int), +// }; +// +// pub const struct_bar = extern struct { +// y: f32 = @import("std").mem.zeroes(f32), +// }; +// +// pub const struct_baz = extern struct { +// z: f64 = @import("std").mem.zeroes(f64), +// }; +// diff --git a/test/cases/translate/type_referenced_struct.c b/test/cases/translate/type_referenced_struct.c new file mode 100644 index 0000000..5d79d2b --- /dev/null +++ b/test/cases/translate/type_referenced_struct.c @@ -0,0 +1,18 @@ +// When clang uses the -windows-none, triple it behaves as MSVC and +// interprets the inner `struct Bar` as an anonymous structure +struct Foo { + struct Bar{ + int b; + }; + struct Bar c; +}; + +// translate +// target=x86_64-linux-gnu +// +// pub const struct_Bar_1 = extern struct { +// b: c_int = @import("std").mem.zeroes(c_int), +// }; +// pub const struct_Foo = extern struct { +// c: struct_Bar_1 = @import("std").mem.zeroes(struct_Bar_1), +// }; diff --git a/test/cases/translate/union_initializer.c b/test/cases/translate/union_initializer.c new file mode 100644 index 0000000..a23b89b --- /dev/null +++ b/test/cases/translate/union_initializer.c @@ -0,0 +1,22 @@ +union { int x; char c[4]; } + ua = {1}, + ub = {.c={'a','b','b','a'}}; + +// translate +// expect=fail +// +// const union_unnamed_1 = extern union { +// x: c_int, +// c: [4]u8, +// }; +// pub export var ua: union_unnamed_1 = union_unnamed_1{ +// .x = @as(c_int, 1), +// }; +// pub export var ub: union_unnamed_1 = union_unnamed_1{ +// .c = [4]u8{ +// 'a', +// 'b', +// 'b', +// 'a', +// }, +// }; diff --git a/test/cases/translate/union_struct_forward_decl.c b/test/cases/translate/union_struct_forward_decl.c new file mode 100644 index 0000000..a64fe64 --- /dev/null +++ b/test/cases/translate/union_struct_forward_decl.c @@ -0,0 +1,36 @@ +struct A; +union B; +enum C; + +struct A { + short x; + double y; +}; + +union B { + short x; + double y; +}; + +struct Foo { + struct A a; + union B b; +}; + + +// translate +// +// pub const struct_A = extern struct { +// x: c_short = @import("std").mem.zeroes(c_short), +// y: f64 = @import("std").mem.zeroes(f64), +// }; +// +// pub const union_B = extern union { +// x: c_short, +// y: f64, +// }; +// +// pub const struct_Foo = extern struct { +// a: struct_A = @import("std").mem.zeroes(struct_A), +// b: union_B = @import("std").mem.zeroes(union_B), +// }; diff --git a/test/cases/translate/unnamed_fields_have_predictable_names.c b/test/cases/translate/unnamed_fields_have_predictable_names.c new file mode 100644 index 0000000..5f8e463 --- /dev/null +++ b/test/cases/translate/unnamed_fields_have_predictable_names.c @@ -0,0 +1,21 @@ +struct a { + struct { int x; }; +}; +struct b { + struct { int y; }; +}; + +// translate +// +// const struct_unnamed_1 = extern struct { +// x: c_int = @import("std").mem.zeroes(c_int), +// }; +// pub const struct_a = extern struct { +// unnamed_0: struct_unnamed_1 = @import("std").mem.zeroes(struct_unnamed_1), +// }; +// const struct_unnamed_2 = extern struct { +// y: c_int = @import("std").mem.zeroes(c_int), +// }; +// pub const struct_b = extern struct { +// unnamed_0: struct_unnamed_2 = @import("std").mem.zeroes(struct_unnamed_2), +// }; diff --git a/test/cases/translate/void_pointer_subtraction.c b/test/cases/translate/void_pointer_subtraction.c new file mode 100644 index 0000000..7773b77 --- /dev/null +++ b/test/cases/translate/void_pointer_subtraction.c @@ -0,0 +1,16 @@ +#include +ptrdiff_t sub_ptr(void *a, void *b) { + return a - b; +} + +// translate +// expect=fail +// target=x86_64-linux +// +// pub export fn sub_ptr(arg_a: ?*anyopaque, arg_b: ?*anyopaque) ptrdiff_t { +// var a = arg_a; +// _ = &a; +// var b = arg_b; +// _ = &b; +// return @as(c_long, @bitCast(@intFromPtr(a) -% @intFromPtr(b))); +// } diff --git a/test/cases/translate/zero_width_field_alignment.c b/test/cases/translate/zero_width_field_alignment.c new file mode 100644 index 0000000..b8f1633 --- /dev/null +++ b/test/cases/translate/zero_width_field_alignment.c @@ -0,0 +1,17 @@ +struct __attribute__((packed)) foo { + int x; + struct {}; + float y; + union {}; +}; + +// translate +// +// const struct_unnamed_1 = extern struct {}; +// const union_unnamed_2 = extern union {}; +// pub const struct_foo = extern struct { +// x: c_int align(1) = @import("std").mem.zeroes(c_int), +// unnamed_0: struct_unnamed_1 align(1) = @import("std").mem.zeroes(struct_unnamed_1), +// y: f32 align(1) = @import("std").mem.zeroes(f32), +// unnamed_1: union_unnamed_2 align(1) = @import("std").mem.zeroes(union_unnamed_2), +// }; diff --git a/test/cases/translate/zig_keywords_in_c_code.c b/test/cases/translate/zig_keywords_in_c_code.c new file mode 100644 index 0000000..edb1974 --- /dev/null +++ b/test/cases/translate/zig_keywords_in_c_code.c @@ -0,0 +1,11 @@ +struct comptime { + int defer; +}; + +// translate +// +// pub const struct_comptime = extern struct { +// @"defer": c_int = @import("std").mem.zeroes(c_int), +// }; +// +// pub const @"comptime" = struct_comptime;