aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2015-02-20 17:17:21 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2015-02-20 17:17:21 +0100
commit54339d1f69b602e5b3148568b4cb15541a7d23c8 (patch)
tree1e190ff2f8a5d2c0a290dd7b107dda39f703bcaf
parentdeaa1ccbec5c806c86d4d7e54334fef6e6abdf0e (diff)
downloadgcc-54339d1f69b602e5b3148568b4cb15541a7d23c8.zip
gcc-54339d1f69b602e5b3148568b4cb15541a7d23c8.tar.gz
gcc-54339d1f69b602e5b3148568b4cb15541a7d23c8.tar.bz2
sibcall-9.c: New test.
* gcc.dg/sibcall-9.c: New test. * gcc.dg/sibcall-10.c: New test. From-SVN: r220872
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/sibcall-10.c83
-rw-r--r--gcc/testsuite/gcc.dg/sibcall-9.c82
3 files changed, 170 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 65310fd..57a740e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2015-02-20 Jakub Jelinek <jakub@redhat.com>
+
+ * gcc.dg/sibcall-9.c: New test.
+ * gcc.dg/sibcall-10.c: New test.
+
2015-02-20 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* gcc.target/aarch64/sisd-shft-neg_1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/sibcall-10.c b/gcc/testsuite/gcc.dg/sibcall-10.c
new file mode 100644
index 0000000..d98b43a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/sibcall-10.c
@@ -0,0 +1,83 @@
+/* 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 { { cris-*-* crisv32-*-* h8300-*-* hppa*64*-*-* m32r-*-* mcore-*-* mn10300-*-* msp430*-*-* nds32*-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa*-*-* } || { arm*-*-* && { ! arm32 } } } } } */
+/* -mlongcall disables sibcall patterns. */
+/* { dg-skip-if "" { powerpc*-*-* } { "-mlongcall" } { "" } } */
+/* { 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). */
+
+extern void abort (void);
+extern void exit (int);
+
+/* Sibcalls are not supported in MIPS16 mode, which has direct calls but
+ not direct jumps. */
+#ifdef __mips
+#define ATTR __attribute__((nomips16))
+#else
+#define ATTR
+#endif
+
+static ATTR void recurser_void1 (void);
+static ATTR void recurser_void2 (void);
+extern void track (void);
+volatile int v;
+
+int n = 0;
+int main ()
+{
+ recurser_void1 ();
+ if (v != 5)
+ abort ();
+ 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 __attribute__((noinline)) ATTR
+recurser_void1 (void)
+{
+ if (n == 0 || n == 7 || n == 8)
+ track ();
+
+ if (n == 10)
+ return;
+ n++;
+ recurser_void2 ();
+}
+
+static void __attribute__((noinline)) ATTR
+recurser_void2 (void)
+{
+ if (n == 0 || n == 7 || n == 8)
+ track ();
+
+ if (n == 10)
+ return;
+ n++;
+ v++;
+ recurser_void1 ();
+}
+
+void *trackpoint;
+
+void __attribute__ ((noinline))
+track ()
+{
+ 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-9.c b/gcc/testsuite/gcc.dg/sibcall-9.c
new file mode 100644
index 0000000..d64e549
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/sibcall-9.c
@@ -0,0 +1,82 @@
+/* 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 { { cris-*-* crisv32-*-* h8300-*-* hppa*64*-*-* m32r-*-* mcore-*-* mn10300-*-* msp430*-*-* nds32*-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa*-*-* } || { arm*-*-* && { ! arm32 } } } } } */
+/* -mlongcall disables sibcall patterns. */
+/* { dg-skip-if "" { powerpc*-*-* } { "-mlongcall" } { "" } } */
+/* { 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). */
+
+extern void abort (void);
+extern void exit (int);
+
+/* Sibcalls are not supported in MIPS16 mode, which has direct calls but
+ not direct jumps. */
+#ifdef __mips
+#define ATTR __attribute__((nomips16))
+#else
+#define ATTR
+#endif
+
+static ATTR void recurser_void1 (int);
+static ATTR void recurser_void2 (int);
+extern void track (int);
+volatile int v;
+
+int main ()
+{
+ recurser_void1 (0);
+ if (v != 5)
+ abort ();
+ 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 __attribute__((noinline)) ATTR
+recurser_void1 (int n)
+{
+ if (n == 0 || n == 7 || n == 8)
+ track (n);
+
+ if (n == 10)
+ return;
+
+ recurser_void2 (n + 1);
+}
+
+static void __attribute__((noinline)) ATTR
+recurser_void2 (int n)
+{
+ if (n == 0 || n == 7 || n == 8)
+ track (n);
+
+ if (n == 10)
+ return;
+
+ v++;
+ recurser_void1 (n + 1);
+}
+
+void *trackpoint;
+
+void __attribute__ ((noinline))
+track (int n)
+{
+ char stackpos[1];
+
+ if (n == 0)
+ trackpoint = stackpos;
+ else if ((n != 7 && n != 8) || trackpoint != stackpos)
+ abort ();
+}