aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Peter Nilsson <hp@bitrange.com>2002-09-29 18:16:15 +0000
committerHans-Peter Nilsson <hp@gcc.gnu.org>2002-09-29 18:16:15 +0000
commitd7bb749a3d6d5841b64d0420a3aff3a558f88e1e (patch)
tree1f8c3e212ab4d46d935609df3b6bf62207373289
parentd7b52625243b9eb0f9dd5334162b0bc00cd590a0 (diff)
downloadgcc-d7bb749a3d6d5841b64d0420a3aff3a558f88e1e.zip
gcc-d7bb749a3d6d5841b64d0420a3aff3a558f88e1e.tar.gz
gcc-d7bb749a3d6d5841b64d0420a3aff3a558f88e1e.tar.bz2
sibcall-1.c, [...]: New tests.
* gcc.dg/sibcall-1.c, gcc.dg/sibcall-2.c, gcc.dg/sibcall-3.c, gcc.dg/sibcall-4.c: New tests. From-SVN: r57628
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/sibcall-1.c46
-rw-r--r--gcc/testsuite/gcc.dg/sibcall-2.c47
-rw-r--r--gcc/testsuite/gcc.dg/sibcall-3.c65
-rw-r--r--gcc/testsuite/gcc.dg/sibcall-4.c66
5 files changed, 229 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5f04770..46400b6 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2002-09-29 Hans-Peter Nilsson <hp@bitrange.com>
+
+ * gcc.dg/sibcall-1.c, gcc.dg/sibcall-2.c, gcc.dg/sibcall-3.c,
+ gcc.dg/sibcall-4.c: New tests.
+
2002-09-28 Roger Sayle <roger@eyesopen.com>
* gcc.c-torture/execute/20020720-1.x: No longer skip test on
diff --git a/gcc/testsuite/gcc.dg/sibcall-1.c b/gcc/testsuite/gcc.dg/sibcall-1.c
new file mode 100644
index 0000000..f9b1f78
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/sibcall-1.c
@@ -0,0 +1,46 @@
+/* Simple check that sibling calls are performed from a
+ void non-leaf-function taking one int argument calling itself.
+
+ Copyright (C) 2002 Free Software Foundation Inc.
+ Contributed by Hans-Peter Nilsson <hp@bitrange.com> */
+
+/* { dg-do run } */
+/* { dg-options "-O2 -foptimize-sibling-calls" } */
+
+/* The option -foptimize-sibling-calls is the default, but serves as
+ marker. Self-recursion tail calls are optimized for all targets,
+ regardless of presence of sibcall patterns. */
+
+extern void recurser_void (int);
+extern void track (int);
+
+int main ()
+{
+ recurser_void (0);
+ exit (0);
+}
+
+void
+recurser_void (int n)
+{
+ if (n == 0 || n == 7)
+ track (n);
+
+ if (n == 10)
+ return;
+
+ recurser_void (n + 1);
+}
+
+void *trackpoint;
+
+void
+track (int n)
+{
+ char stackpos[1];
+
+ if (n == 0)
+ trackpoint = stackpos;
+ else if (n != 7 || trackpoint != stackpos)
+ abort ();
+}
diff --git a/gcc/testsuite/gcc.dg/sibcall-2.c b/gcc/testsuite/gcc.dg/sibcall-2.c
new file mode 100644
index 0000000..cb2d1d5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/sibcall-2.c
@@ -0,0 +1,47 @@
+/* Simple check that sibling calls are performed from a
+ void non-leaf-function taking no arguments calling itself.
+
+ Copyright (C) 2002 Free Software Foundation Inc.
+ Contributed by Hans-Peter Nilsson <hp@bitrange.com> */
+
+/* { dg-do run } */
+/* { dg-options "-O2 -foptimize-sibling-calls" } */
+
+/* The option -foptimize-sibling-calls is the default, but serves as
+ marker. Self-recursion tail calls are optimized for all targets,
+ regardless of presence of sibcall patterns. */
+
+extern void recurser_void (void);
+extern void track (void);
+
+int n = 0;
+int main ()
+{
+ recurser_void ();
+ exit (0);
+}
+
+void
+recurser_void (void)
+{
+ if (n == 0 || n == 7)
+ track ();
+
+ if (n == 10)
+ return;
+ n++;
+ recurser_void ();
+}
+
+void *trackpoint;
+
+void
+track ()
+{
+ char stackpos[1];
+
+ if (n == 0)
+ trackpoint = stackpos;
+ else if (n != 7 || trackpoint != stackpos)
+ abort ();
+}
diff --git a/gcc/testsuite/gcc.dg/sibcall-3.c b/gcc/testsuite/gcc.dg/sibcall-3.c
new file mode 100644
index 0000000..b494b40
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/sibcall-3.c
@@ -0,0 +1,65 @@
+/* Simple check that sibling calls are performed from a
+ void non-leaf-function taking one int argument calling a function which
+ is about the same as itself.
+
+ Copyright (C) 2002 Free Software Foundation Inc.
+ Contributed by Hans-Peter Nilsson <hp@bitrange.com> */
+
+/* { dg-do run { xfail arc-*-* avr-*-* c4x-*-* cris-*-* h8300-*-* i370-*-* i960-*-* ip2k-*-* m32r-*-* m68hc1?-*-* m681?-*-* m680*-*-* m68k-*-* mcore-*-* mips*-*-* mn10?00-*-* ns32k-*-* s390*-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa-*-* } } */
+/* { dg-options "-O2 -foptimize-sibling-calls" } */
+
+/* The option -foptimize-sibling-calls is the default, but serves as
+ marker. This test is xfailed on targets without sibcall patterns
+ (except targets where the test does not work due to the return address
+ not saved on the regular stack). */
+
+static void recurser_void1 (int);
+static void recurser_void2 (int);
+extern void track (int);
+
+int main ()
+{
+ recurser_void1 (0);
+ exit (0);
+}
+
+/* The functions should get the same stack-frame, and best way to make it
+ reasonably sure is to make them have the same contents (regarding the
+ n tests). */
+
+static void
+recurser_void1 (int n)
+{
+ if (n == 0 || n == 7 || n == 8)
+ track (n);
+
+ if (n == 10)
+ return;
+
+ recurser_void2 (n + 1);
+}
+
+static void
+recurser_void2 (int n)
+{
+ if (n == 0 || n == 7 || n == 8)
+ track (n);
+
+ if (n == 10)
+ return;
+
+ recurser_void1 (n + 1);
+}
+
+void *trackpoint;
+
+void
+track (int n)
+{
+ char stackpos[1];
+
+ if (n == 0)
+ trackpoint = stackpos;
+ else if ((n != 7 && n != 8) || trackpoint != stackpos)
+ abort ();
+}
diff --git a/gcc/testsuite/gcc.dg/sibcall-4.c b/gcc/testsuite/gcc.dg/sibcall-4.c
new file mode 100644
index 0000000..222859d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/sibcall-4.c
@@ -0,0 +1,66 @@
+/* Simple check that sibling calls are performed from a
+ void non-leaf-function taking no arguments calling a function which
+ is about the same as itself.
+
+ Copyright (C) 2002 Free Software Foundation Inc.
+ Contributed by Hans-Peter Nilsson <hp@bitrange.com> */
+
+/* { dg-do run { xfail arc-*-* avr-*-* c4x-*-* cris-*-* h8300-*-* i370-*-* i960-*-* ip2k-*-* m32r-*-* m68hc1?-*-* m681?-*-* m680*-*-* m68k-*-* mcore-*-* mips*-*-* mn10?00-*-* ns32k-*-* s390*-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa-*-* } } */
+/* { dg-options "-O2 -foptimize-sibling-calls" } */
+
+/* The option -foptimize-sibling-calls is the default, but serves as
+ marker. This test is xfailed on targets without sibcall patterns
+ (except targets where the test does not work due to the return address
+ not saved on the regular stack). */
+
+static void recurser_void1 (void);
+static void recurser_void2 (void);
+extern void track (void);
+
+int n = 0;
+int main ()
+{
+ recurser_void1 ();
+ exit (0);
+}
+
+/* The functions should get the same stack-frame, and best way to make it
+ reasonably sure is to make them have the same contents (regarding the
+ n tests). */
+
+static void
+recurser_void1 (void)
+{
+ if (n == 0 || n == 7 || n == 8)
+ track ();
+
+ if (n == 10)
+ return;
+ n++;
+ recurser_void2 ();
+}
+
+static void
+recurser_void2 (void)
+{
+ if (n == 0 || n == 7 || n == 8)
+ track ();
+
+ if (n == 10)
+ return;
+ n++;
+ recurser_void1 ();
+}
+
+void *trackpoint;
+
+void
+track ()
+{
+ char stackpos[1];
+
+ if (n == 0)
+ trackpoint = stackpos;
+ else if ((n != 7 && n != 8) || trackpoint != stackpos)
+ abort ();
+}