From 1d943da0cf9154e7ce78ce867cdbb91531c5d78e Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Tue, 25 Jul 2023 14:58:33 -0700 Subject: initial dietc commit --- tests/array_of_structs.c | 23 +++++++++++++++++++++++ tests/coreutils.c | 16 ++++++++++++++++ tests/debug.c | 7 +++++++ tests/extern_array.c | 6 ++++++ tests/fgets.c | 6 ++++++ tests/ldbl.c | 9 +++++++++ tests/local_array.c | 4 ++++ tests/local_const_array.c | 4 ++++ tests/no_includes.c | 15 +++++++++++++++ tests/ptr_arith.c | 4 ++++ tests/struct_return.c | 16 ++++++++++++++++ tests/super_simple.c | 5 +++++ tests/test.c | 21 +++++++++++++++++++++ tests/union_init.c | 10 ++++++++++ tests/unnamed_fields.c | 13 +++++++++++++ tests/unsized_extern_array.c | 4 ++++ tests/va_start.c | 21 +++++++++++++++++++++ 17 files changed, 184 insertions(+) create mode 100644 tests/array_of_structs.c create mode 100644 tests/coreutils.c create mode 100644 tests/debug.c create mode 100644 tests/extern_array.c create mode 100644 tests/fgets.c create mode 100644 tests/ldbl.c create mode 100644 tests/local_array.c create mode 100644 tests/local_const_array.c create mode 100644 tests/no_includes.c create mode 100644 tests/ptr_arith.c create mode 100644 tests/struct_return.c create mode 100644 tests/super_simple.c create mode 100644 tests/test.c create mode 100644 tests/union_init.c create mode 100644 tests/unnamed_fields.c create mode 100644 tests/unsized_extern_array.c create mode 100644 tests/va_start.c (limited to 'tests') diff --git a/tests/array_of_structs.c b/tests/array_of_structs.c new file mode 100644 index 0000000..0ab53b9 --- /dev/null +++ b/tests/array_of_structs.c @@ -0,0 +1,23 @@ +struct option { + char *name; + int has_arg; + int *flag; + int val; +}; + +static struct option const options[] = { + {"whatisup", 1, 0, 0}, + {"helloworld", 2, 0, 0}, + {"version", 3, 0, 0}, + {"help", 4, 0, 0}, + {"etc", 5, 0, 0}, + {0, 0, 0, 0}, +}; + +void puts(char *x); + +int main() { + for (struct option *opt = options; opt->name; opt++) { + puts(opt->name); + } +} diff --git a/tests/coreutils.c b/tests/coreutils.c new file mode 100644 index 0000000..60b9176 --- /dev/null +++ b/tests/coreutils.c @@ -0,0 +1,16 @@ + /* Check that off_t can represent 2**63 - 1 correctly. + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) + +int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +int +main (void) +{ + + ; + return 0; +} diff --git a/tests/debug.c b/tests/debug.c new file mode 100644 index 0000000..95ad579 --- /dev/null +++ b/tests/debug.c @@ -0,0 +1,7 @@ +void __open_too_many_args(void); +void __open_missing_mode(void); + +int open () { + __open_too_many_args (); + return 0; +} diff --git a/tests/extern_array.c b/tests/extern_array.c new file mode 100644 index 0000000..c24500f --- /dev/null +++ b/tests/extern_array.c @@ -0,0 +1,6 @@ +extern const int foo[]; +extern void baz(void *); + +void bar() { + baz((void*)foo); +} diff --git a/tests/fgets.c b/tests/fgets.c new file mode 100644 index 0000000..914eecc --- /dev/null +++ b/tests/fgets.c @@ -0,0 +1,6 @@ +#include + +void foo(FILE *s) { + char *x; + fgets(x, 0, s); +} diff --git a/tests/ldbl.c b/tests/ldbl.c new file mode 100644 index 0000000..f3d8cae --- /dev/null +++ b/tests/ldbl.c @@ -0,0 +1,9 @@ +// #include +int main (void) { + typedef int check[sizeof (long double) == sizeof (double) + // && LDBL_MANT_DIG == DBL_MANT_DIG + // && LDBL_MAX_EXP == DBL_MAX_EXP + // && LDBL_MIN_EXP == DBL_MIN_EXP + ? 1 : -1]; + return 0; +} diff --git a/tests/local_array.c b/tests/local_array.c new file mode 100644 index 0000000..3d07d04 --- /dev/null +++ b/tests/local_array.c @@ -0,0 +1,4 @@ +int lookup_arr(int i) { + int arr[3]; + return arr[i]; +} diff --git a/tests/local_const_array.c b/tests/local_const_array.c new file mode 100644 index 0000000..38de887 --- /dev/null +++ b/tests/local_const_array.c @@ -0,0 +1,4 @@ +int lookup_arr(int i) { + int arr[1] = {1}; + return arr[i]; +} diff --git a/tests/no_includes.c b/tests/no_includes.c new file mode 100644 index 0000000..89796d0 --- /dev/null +++ b/tests/no_includes.c @@ -0,0 +1,15 @@ +typedef struct ___dietc_va_list { char ___dietc_va_list[24]; } va_list; + +void foo(int x, int y) { + x = y; + va_list z; + va_list a; + z = a; +} + +int main() { + int x = 5; + int y = 7; + x = y; + return x; +} diff --git a/tests/ptr_arith.c b/tests/ptr_arith.c new file mode 100644 index 0000000..1f0d0aa --- /dev/null +++ b/tests/ptr_arith.c @@ -0,0 +1,4 @@ +int main(void) { + int *x; + x[5] = 1; +} diff --git a/tests/struct_return.c b/tests/struct_return.c new file mode 100644 index 0000000..3d98574 --- /dev/null +++ b/tests/struct_return.c @@ -0,0 +1,16 @@ +struct foo { + int xyz1; + int xyz2; + int xyz3; + int xyz4; + int xyz5; + int xyz6; + int xyz7; + int xyz8; +}; + +extern struct foo baz(int bar); + +struct foo baz(int bar) { + return (struct foo){1}; +} diff --git a/tests/super_simple.c b/tests/super_simple.c new file mode 100644 index 0000000..8f1a336 --- /dev/null +++ b/tests/super_simple.c @@ -0,0 +1,5 @@ +int main(void) { + int x = 1; + int y = 2; + return y; +} diff --git a/tests/test.c b/tests/test.c new file mode 100644 index 0000000..2e23b8b --- /dev/null +++ b/tests/test.c @@ -0,0 +1,21 @@ +#include + +struct foo { + long bar; + char baz; +}; + +struct foo bar = {1,2}; + +struct foo *barptr[2] = {&bar, &bar}; +struct foo **barptrptr[2] = {&barptr[0], &barptr[1]}; + +int main(void) { + int x = 5; + if (x) + x++; + long y = 6; + y++; + printf("Hello, World!\n"); + return 0; +} diff --git a/tests/union_init.c b/tests/union_init.c new file mode 100644 index 0000000..80cee1d --- /dev/null +++ b/tests/union_init.c @@ -0,0 +1,10 @@ +union foo { + int x; + long y; +}; + +int foo() { + static union foo initval; + union foo v = initval; + return 0; +} diff --git a/tests/unnamed_fields.c b/tests/unnamed_fields.c new file mode 100644 index 0000000..d259d44 --- /dev/null +++ b/tests/unnamed_fields.c @@ -0,0 +1,13 @@ +struct xyz { + int z; + struct { + int x; + int y; + }; +}; + +int main() { + struct xyz abc; + abc.x = 5; + return abc.x; +} diff --git a/tests/unsized_extern_array.c b/tests/unsized_extern_array.c new file mode 100644 index 0000000..112a590 --- /dev/null +++ b/tests/unsized_extern_array.c @@ -0,0 +1,4 @@ +extern const unsigned int arr[]; +int lookup_arr(int i) { + return arr[i]; +} diff --git a/tests/va_start.c b/tests/va_start.c new file mode 100644 index 0000000..8644950 --- /dev/null +++ b/tests/va_start.c @@ -0,0 +1,21 @@ +// https://en.cppreference.com/w/cpp/utility/variadic/va_start + +#include +#include + +int add_nums(int count, ...) +{ + int result = 0; + va_list args; + va_start(args, count); + for (int i = 0; i < count; ++i) { + result += va_arg(args, int); + } + va_end(args); + return result; +} + +int main() +{ + printf("%d\n", add_nums(4, 25, 25, 50, 50)); +} -- cgit v1.2.3