From e24fa9dac1d7f5d1a628f04a1952a38eff8d2d23 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Thu, 16 Nov 2000 19:45:23 +0000 Subject: [PATCH] Add a couple of new test cases for nested function support. From-SVN: r37504 --- gcc/testsuite/ChangeLog | 5 ++ .../gcc.c-torture/execute/nestfunc-2.c | 49 +++++++++++++++ .../gcc.c-torture/execute/nestfunc-3.c | 60 +++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 gcc/testsuite/gcc.c-torture/execute/nestfunc-2.c create mode 100644 gcc/testsuite/gcc.c-torture/execute/nestfunc-3.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 716c5fdd24c..d0c3dbf8adb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2000-11-16 Nick Clifton + + * gcc.c-torture/execute/nestfunc-2.c: New test. + * gcc.c-torture/execute/nestfunc-3.c: New test. + 2000-11-11 Bernd Schmidt * gcc.c-torture/compile/20001116-1.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/execute/nestfunc-2.c b/gcc/testsuite/gcc.c-torture/execute/nestfunc-2.c new file mode 100644 index 00000000000..030875560dc --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/nestfunc-2.c @@ -0,0 +1,49 @@ +extern int foo (int, int, int (*) (int, int, int, int, int, int, int)); + +int z; + +int +main (void) +{ +#ifndef NO_TRAMPOLINES + int sum = 0; + int i; + + int nested (int a, int b, int c, int d, int e, int f, int g) + { + z = c + d + e + f + g; + + if (a > 2 * b) + return a - b; + else + return b - a; + } + + for (i = 0; i < 10; ++i) + { + int j; + + for (j = 0; j < 10; ++j) + { + int k; + + for (k = 0; k < 10; ++k) + sum += foo (i, j > k ? j - k : k - j, nested); + } + } + + if (sum != 2300) + abort (); + + if (z != 0x1b) + abort (); +#endif + + exit (0); +} + +int +foo (int a, int b, int (* fp) (int, int, int, int, int, int, int)) +{ + return fp (a, b, a, b, a, b, a); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/nestfunc-3.c b/gcc/testsuite/gcc.c-torture/execute/nestfunc-3.c new file mode 100644 index 00000000000..653a5dafd79 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/nestfunc-3.c @@ -0,0 +1,60 @@ + +extern long foo (long, long, long (*) (long, long)); +extern long use (long (*) (long, long), long, long); + +int +main (void) +{ +#ifndef NO_TRAMPOLINES + long sum = 0; + long i; + + long nested_0 (long a, long b) + { + if (a > 2 * b) + return a - b; + else + return b - a; + } + + long nested_1 (long a, long b) + { + return use (nested_0, b, a) + sum; + } + + long nested_2 (long a, long b) + { + return nested_1 (b, a); + } + + for (i = 0; i < 10; ++i) + { + long j; + + for (j = 0; j < 10; ++j) + { + long k; + + for (k = 0; k < 10; ++k) + sum += foo (i, j > k ? j - k : k - j, nested_2); + } + } + + if (sum != 0xbecfcbf5) + abort (); +#endif + + exit (0); +} + +long +use (long (* func)(long, long), long a, long b) +{ + return func (b, a); +} + +long +foo (long a, long b, long (* func) (long, long)) +{ + return func (a, b); +} -- 2.30.2