Skip to content

Commit

Permalink
add some already processed test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexu committed Nov 12, 2024
1 parent b031141 commit 2c226a9
Show file tree
Hide file tree
Showing 45 changed files with 748 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/cases/run/compound_assignments_with_implicit_casts.c
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions test/cases/run/compound_assignments_with_pointer_arithmetic.c
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions test/cases/run/dereference address of.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdlib.h>
int main(void) {
int i = 0;
*&i = 42;
if (i != 42) abort();
return 0;
}

// run
// expect=fail
10 changes: 10 additions & 0 deletions test/cases/run/explicit_cast_bool_from_float.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdbool.h>

int main() {
float f = 2.0f;
bool b = (bool) f;
return 0;
}

// run
// expect=fail
22 changes: 22 additions & 0 deletions test/cases/run/extern_typedef_variables_in_functions.c
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions test/cases/run/float_from_bool_expr_cast.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int main() {
float f = (float)(10.0f > 1.0f);
return 0;
}

// run
// expect=fail
6 changes: 6 additions & 0 deletions test/cases/translate/_Static_assert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_Static_assert(1 == 1, "");

// translate
// target=x86_64-linux
//
// tmp.c:1:1: warning: ignoring _Static_assert declaration
17 changes: 17 additions & 0 deletions test/cases/translate/align() attribute.c
Original file line number Diff line number Diff line change
@@ -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;
// }
8 changes: 8 additions & 0 deletions test/cases/translate/assert_with_strlit.c
Original file line number Diff line number Diff line change
@@ -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));
7 changes: 7 additions & 0 deletions test/cases/translate/atomic types.c
Original file line number Diff line number Diff line change
@@ -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");
20 changes: 20 additions & 0 deletions test/cases/translate/circular_struct_definitions.c
Original file line number Diff line number Diff line change
@@ -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),
// };
25 changes: 25 additions & 0 deletions test/cases/translate/double_define_struct.c
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 4 additions & 0 deletions test/cases/translate/empty declaration.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
;

//translate
//
20 changes: 20 additions & 0 deletions test/cases/translate/empty union initializer list.c
Original file line number Diff line number Diff line change
@@ -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;
// }
16 changes: 16 additions & 0 deletions test/cases/translate/enums msvc.c
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 15 additions & 0 deletions test/cases/translate/enums.c
Original file line number Diff line number Diff line change
@@ -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;
18 changes: 18 additions & 0 deletions test/cases/translate/field_access_is_grouped_if_necessary.c
Original file line number Diff line number Diff line change
@@ -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;
// }
9 changes: 9 additions & 0 deletions test/cases/translate/function prototype with parenthesis.c
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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";
19 changes: 19 additions & 0 deletions test/cases/translate/large_packed_struct.c
Original file line number Diff line number Diff line change
@@ -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),
// };
11 changes: 11 additions & 0 deletions test/cases/translate/macro_function_string_concat.c
Original file line number Diff line number Diff line change
@@ -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();
21 changes: 21 additions & 0 deletions test/cases/translate/macro_referencing_var.c
Original file line number Diff line number Diff line change
@@ -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);
5 changes: 5 additions & 0 deletions test/cases/translate/noreturn attribute.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
void foo(void) __attribute__((noreturn));

// translate
//
// pub extern fn foo() noreturn;
24 changes: 24 additions & 0 deletions test/cases/translate/packed_union_nested_unpacked.c
Original file line number Diff line number Diff line change
@@ -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;
13 changes: 13 additions & 0 deletions test/cases/translate/packed_union_simple.c
Original file line number Diff line number Diff line change
@@ -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;
Loading

0 comments on commit 2c226a9

Please sign in to comment.