From 3f5819fa1e6f4a6aa4af8cc48749e8a9a2202c67 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Mon, 5 Feb 2007 12:11:38 +0000 Subject: [PATCH] improve and fix some test apps --- ir/be/test/CallingTest.c | 4 ++-- ir/be/test/RegallocBug.c | 4 +++- ir/be/test/bad.c | 9 ++++++--- ir/be/test/biggest_prime.c | 1 + ir/be/test/cmp.c | 2 ++ ir/be/test/const.c | 2 +- ir/be/test/convtest.c | 1 + ir/be/test/fehler8.c | 1 + ir/be/test/fib_iter.c | 2 +- ir/be/test/optest.c | 5 +++-- ir/be/test/queens-handoptimized.c | 14 +++++++------- ir/be/test/simple.c | 4 +++- ir/be/test/slow_memperm.c | 17 +++++++++++++++++ ir/be/test/tailrec.c | 2 ++ ir/be/test/use_uninit_ptr.c | 10 ++++++---- ir/be/test/vararray.c | 6 ++++++ ir/be/test/wrong_cmp.c | 10 ++++++++-- 17 files changed, 70 insertions(+), 24 deletions(-) create mode 100644 ir/be/test/slow_memperm.c diff --git a/ir/be/test/CallingTest.c b/ir/be/test/CallingTest.c index f595396eb..85e2422e2 100644 --- a/ir/be/test/CallingTest.c +++ b/ir/be/test/CallingTest.c @@ -2,12 +2,12 @@ int int_func(void) { - return 0; + return 42; } float float_func(void) { - return 0.0f; + return 13.5f; } int main(int argc, char *argv[]) diff --git a/ir/be/test/RegallocBug.c b/ir/be/test/RegallocBug.c index 9456a56cc..a531fdcaa 100644 --- a/ir/be/test/RegallocBug.c +++ b/ir/be/test/RegallocBug.c @@ -1,4 +1,5 @@ #include +#include struct Arr2Object { int a[10]; @@ -36,10 +37,11 @@ static void pass_array_test(struct ArrObject *a, int a_len) int main(int argc, char *argv[]) { int i, j, bi; struct ArrObject ao[10]; - struct ArrObject aob; struct Arr2Object a2o[2]; struct Arr2Object a2; + (void) argc; + (void) argv; for(i = 0; i < length(ao); i++) ctorArrObject(&ao[i], i); diff --git a/ir/be/test/bad.c b/ir/be/test/bad.c index 0c9a2931b..8ef4dfb50 100644 --- a/ir/be/test/bad.c +++ b/ir/be/test/bad.c @@ -1,3 +1,6 @@ +#include +#include + unsigned int f1 (int diff) { @@ -22,7 +25,7 @@ f4 (unsigned long long diff) return ((unsigned long long) ((signed long long) diff < 0 ? -diff : diff)); } -main () +int main () { int i; for (i = 0; i <= 10; i++) @@ -41,8 +44,8 @@ main () abort (); } */ - if (f2 (-i) != i) { - printf("f2(%d)\n", -i); + if ((int) f2 (-i) != i) { + printf("f2(%d) -> %d\n", -i, f2(-i)); abort (); } /* diff --git a/ir/be/test/biggest_prime.c b/ir/be/test/biggest_prime.c index 50e2ad4e6..0f564f82b 100644 --- a/ir/be/test/biggest_prime.c +++ b/ir/be/test/biggest_prime.c @@ -1,4 +1,5 @@ int m = 754974721, N, t[1 << 22], a, *p, i, e = 1 << 22, j, s, b, c, U; + f (d) { for (s = 1 << 23; s; s /= 2, d = d * 1L * d % m) diff --git a/ir/be/test/cmp.c b/ir/be/test/cmp.c index a7d398a58..909758224 100644 --- a/ir/be/test/cmp.c +++ b/ir/be/test/cmp.c @@ -1,3 +1,5 @@ +#include + int cmp1(int a, int b) { return a < b; diff --git a/ir/be/test/const.c b/ir/be/test/const.c index 8d0f12ee4..0bfce4995 100644 --- a/ir/be/test/const.c +++ b/ir/be/test/const.c @@ -1,6 +1,6 @@ #include int main() { - printf("%d", 0x1e00000); + printf("%d\n", 0x1e00000); return 0; } diff --git a/ir/be/test/convtest.c b/ir/be/test/convtest.c index 3ee6e232e..1e030502d 100644 --- a/ir/be/test/convtest.c +++ b/ir/be/test/convtest.c @@ -12,6 +12,7 @@ int convtest_func(char c, short s, int i, float f, double d) { short is = s + i; short fs = s + f; short ds = s + d; + int ti = i + s; int fi = i + f; int di = i + d; float df = d + f; diff --git a/ir/be/test/fehler8.c b/ir/be/test/fehler8.c index 74f27a87f..24e6ac760 100644 --- a/ir/be/test/fehler8.c +++ b/ir/be/test/fehler8.c @@ -1,3 +1,4 @@ +#include int main(void) { diff --git a/ir/be/test/fib_iter.c b/ir/be/test/fib_iter.c index da7434b34..7c600f027 100644 --- a/ir/be/test/fib_iter.c +++ b/ir/be/test/fib_iter.c @@ -1,5 +1,5 @@ unsigned long fib_iter(int n) { - unsigned long a = 1, b = 1, c, i; + unsigned long a = 1, b = 1, c = 0, i; if (n < 2) return 1; diff --git a/ir/be/test/optest.c b/ir/be/test/optest.c index f4d2497be..4998bf3b5 100644 --- a/ir/be/test/optest.c +++ b/ir/be/test/optest.c @@ -8,6 +8,7 @@ typedef int myint; #define test16_2 11 #define test32_1 0x001200AB #define test32_2 0x00341500 +#define test32_s 7 @@ -97,8 +98,8 @@ int main(int argc, char *argv[]) { res32[ 1] = test_sub (test32_1, test32_2); res32[ 2] = test_mul (test32_1, test32_2); res32[ 3] = test_div (test32_1, test32_2); - res32[ 4] = test_shl (test32_1, test32_2); - res32[ 5] = test_shr (test32_1, test32_2); + res32[ 4] = test_shl (test32_1, test32_s); + res32[ 5] = test_shr (test32_1, test32_s); res32[ 6] = test_div (test32_1, test32_2); res32[ 7] = test_cmp (test32_1, test32_2); res32[ 8] = test_addi (test32_1); diff --git a/ir/be/test/queens-handoptimized.c b/ir/be/test/queens-handoptimized.c index 14b83a1e8..fe7b4ed4f 100644 --- a/ir/be/test/queens-handoptimized.c +++ b/ir/be/test/queens-handoptimized.c @@ -55,19 +55,19 @@ int solve (int n) { // return the number of solutions to the n-queens problem int c = 0; int res = 0; - int *row; + int *row; row = malloc(sizeof(*row) * n); row[0] = -1; while (c >= 0) { - int rc = row[c]; + int rc = row[c]; do { - rc++; + rc++; } while ((rc < n) && (!place_ok(c, row, rc))); if (rc < n) { // successfully placed at (c,row[c]) - row[c] = rc; + row[c] = rc; if (c == n-1) res = res+1; @@ -75,11 +75,11 @@ int solve (int n) { c = c+1; row[c] = -1; } - continue; + continue; } - row[c] = rc; - c = c-1; + row[c] = rc; + c = c-1; } free(row); diff --git a/ir/be/test/simple.c b/ir/be/test/simple.c index 8414e9c0c..41a0f6344 100644 --- a/ir/be/test/simple.c +++ b/ir/be/test/simple.c @@ -1,8 +1,10 @@ +#if 0 double simple(double a, double b) { return a*b+1; } +#endif int main(void) { - printf("%lf\n", simple(5.25, 8.436)); + //printf("%lf\n", simple(5.25, 8.436)); return 0; } diff --git a/ir/be/test/slow_memperm.c b/ir/be/test/slow_memperm.c new file mode 100644 index 000000000..1c441818c --- /dev/null +++ b/ir/be/test/slow_memperm.c @@ -0,0 +1,17 @@ +#include + +unsigned m = 7; + +int main(void) { + + unsigned a; + unsigned c = 0; + + for (a=0; a<=m; a++) { + c = a; + } + + printf("%d %d\n", a, c); + + return 0; +} diff --git a/ir/be/test/tailrec.c b/ir/be/test/tailrec.c index 751be003e..9e21795f4 100644 --- a/ir/be/test/tailrec.c +++ b/ir/be/test/tailrec.c @@ -1,3 +1,5 @@ +#include + static unsigned _fak(unsigned a, unsigned b) { if (a == 0) diff --git a/ir/be/test/use_uninit_ptr.c b/ir/be/test/use_uninit_ptr.c index dc26272e2..07c9796ce 100644 --- a/ir/be/test/use_uninit_ptr.c +++ b/ir/be/test/use_uninit_ptr.c @@ -1,10 +1,12 @@ -void foo(char *a1) { +#include + +void foo(void) { + char *f1; + + printf("%d\n", *f1); return; } int main(void) { - char *f1; - - foo(f1); return 0; } diff --git a/ir/be/test/vararray.c b/ir/be/test/vararray.c index c6dc8f109..6a74c0d32 100644 --- a/ir/be/test/vararray.c +++ b/ir/be/test/vararray.c @@ -1,3 +1,5 @@ +#include + int test(int data[], int len) { int arr[len]; int i; @@ -5,6 +7,10 @@ int test(int data[], int len) { for (i = 0; i < len; ++i) { arr[i] = data[i]; } + + for(i = 0; i < len; ++i) { + printf("%d\n", arr[i]); + } } int _data[] = {3, 2, 1}; diff --git a/ir/be/test/wrong_cmp.c b/ir/be/test/wrong_cmp.c index 58766ddb1..5666a4ad4 100644 --- a/ir/be/test/wrong_cmp.c +++ b/ir/be/test/wrong_cmp.c @@ -1,3 +1,5 @@ +#include + #define MASK 0x00000020 int ctrl_space_write () @@ -5,12 +7,16 @@ int ctrl_space_write () unsigned int reg_offset = 160; if ((reg_offset & MASK) == MASK) - {} + { + return 1; + } return (0); } int main (void) { - return ctrl_space_write(); + int res = ctrl_space_write(); + printf("Result: %d (should be 1)\n", res); + return res == 1 ? 0 : 1; } -- 2.20.1