struct-by-value-22_main.c: New test.
authorJakub Jelinek <jakub@redhat.com>
Wed, 30 Jun 2004 11:44:50 +0000 (13:44 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 30 Jun 2004 11:44:50 +0000 (13:44 +0200)
* gcc.dg/compat/struct-by-value-22_main.c: New test.
* gcc.dg/compat/struct-by-value-22_x.c: New.
* gcc.dg/compat/struct-by-value-22_y.c: New.

From-SVN: r83903

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/compat/struct-by-value-22_main.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/compat/struct-by-value-22_x.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/compat/struct-by-value-22_y.c [new file with mode: 0644]

index 57520be..b37a200 100644 (file)
@@ -1,5 +1,9 @@
 2004-06-30  Jakub Jelinek  <jakub@redhat.com>
 
+       * gcc.dg/compat/struct-by-value-22_main.c: New test.
+       * gcc.dg/compat/struct-by-value-22_x.c: New.
+       * gcc.dg/compat/struct-by-value-22_y.c: New.
+
        * gcc.c-torture/execute/20040629-1.c: New test.
 
 2004-06-29  Jakub Jelinek  <jakub@redhat.com>
diff --git a/gcc/testsuite/gcc.dg/compat/struct-by-value-22_main.c b/gcc/testsuite/gcc.dg/compat/struct-by-value-22_main.c
new file mode 100644 (file)
index 0000000..7f005ef
--- /dev/null
@@ -0,0 +1,16 @@
+/* Test variable sized function argument passing.
+   GCC 3.2 and earlier is incompatible with GCC 3.3+ on x86-64,
+   the latter passes variable sized arguments by reference while
+   the former doesn't.
+   See http://gcc.gnu.org/ml/gcc-patches/2003-01/msg01830.html */
+
+extern void struct_by_value_22_x (void);
+extern void exit (int);
+int fails;
+
+int
+main ()
+{
+  struct_by_value_22_x ();
+  exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/compat/struct-by-value-22_x.c b/gcc/testsuite/gcc.dg/compat/struct-by-value-22_x.c
new file mode 100644 (file)
index 0000000..fa71a9e
--- /dev/null
@@ -0,0 +1,79 @@
+#ifndef T
+#include "compat-common.h"
+#include "mixed-struct-defs.h"
+#include "mixed-struct-init.h"
+
+#define T(NAME, FIELDS, TYPE, FIELDINIT, FIELDTEST)                    \
+extern void testva##NAME (int n, ...);                                 \
+                                                                       \
+void                                                                   \
+testit##NAME (int n)                                                   \
+{                                                                      \
+  struct S { FIELDS TYPE a[n]; } s;                                    \
+  int i;                                                               \
+  FIELDINIT;                                                           \
+  for (i = 0; i < n; ++i)                                              \
+    s.a[i] = 12 + n - i;                                               \
+  testva##NAME (n, s, n, s);                                           \
+}
+
+#include "struct-by-value-22_x.c"
+
+#undef T
+
+void
+struct_by_value_22_x ()
+{
+  int n;
+DEBUG_INIT
+
+#define T(NAME, FIELDS, TYPE, FIELDINIT, FIELDTEST) testit##NAME (n);
+
+  for (n = 0; n < 16; ++n)
+    {
+#include "struct-by-value-22_x.c"
+      DEBUG_NL;
+    }
+  for (; n < 110; n += 13)
+    {
+#include "struct-by-value-22_x.c"
+      DEBUG_NL;
+    }
+
+DEBUG_FINI
+
+if (fails != 0)
+  abort ();
+}
+
+#else
+
+#define S(NAME, FIELDS, FIELDINIT, FIELDTEST)                          \
+  T(c##NAME, FIELDS, char, FIELDINIT, FIELDTEST)                       \
+  T(s##NAME, FIELDS, short, FIELDINIT, FIELDTEST)                      \
+  T(u##NAME, FIELDS, unsigned, FIELDINIT, FIELDTEST)                   \
+  T(d##NAME, FIELDS, double, FIELDINIT, FIELDTEST)
+S(E, , do {} while (0), DEBUG_DOT)
+S(n, int n;, s.n = n, if (s.n != n) DEBUG_CHECK)
+#define U(TYPE)                                                                \
+S(TYPE, TYPE s;, init##TYPE (&s.s, n), check##TYPE (s.s, n))
+U(Scd)
+U(Scdc)
+U(Sd)
+U(Sdi)
+U(Scsds)
+U(Scsdsc)
+U(Scsdis)
+U(Scsdisc)
+U(Ssds)
+U(Ssdsc)
+U(Scssdss)
+U(Scssdssc)
+U(Sfi)
+U(Sfii)
+U(Sfifi)
+U(Sfiifii)
+#undef S
+#undef U
+
+#endif
diff --git a/gcc/testsuite/gcc.dg/compat/struct-by-value-22_y.c b/gcc/testsuite/gcc.dg/compat/struct-by-value-22_y.c
new file mode 100644 (file)
index 0000000..079e40e
--- /dev/null
@@ -0,0 +1,39 @@
+#include <stdarg.h>
+#include "compat-common.h"
+#include "mixed-struct-defs.h"
+#include "mixed-struct-check.h"
+
+#ifdef SKIP_VA
+const int test_va = 0;
+#else
+const int test_va = 1;
+#endif
+
+#define T(NAME, FIELDS, TYPE, FIELDINIT, FIELDTEST)                    \
+void                                                                   \
+testva##NAME (int n, ...)                                              \
+{                                                                      \
+  va_list ap;                                                          \
+  if (test_va)                                                         \
+    {                                                                  \
+      struct S { FIELDS TYPE a[n]; } s;                                        \
+      int fail = 0, i, j;                                              \
+                                                                       \
+      va_start (ap, n);                                                        \
+      for (j = 0; j < 2; ++j)                                          \
+        {                                                              \
+         s = va_arg (ap, struct S);                                    \
+         for (i = 0; i < n; ++i)                                       \
+           if (s.a[i] != 12 + n - i)                                   \
+             ++fail;                                                   \
+         if (fail)                                                     \
+           { DEBUG_FAIL; }                                             \
+         if (!j && va_arg (ap, int) != n)                              \
+           { DEBUG_FAIL; }                                             \
+         FIELDTEST;                                                    \
+       }                                                               \
+      va_end (ap);                                                     \
+    }                                                                  \
+}
+
+#include "struct-by-value-22_x.c"