align.C: New test.
authorAlex Samuel <samuel@codesourcery.com>
Fri, 3 Dec 1999 16:45:53 +0000 (16:45 +0000)
committerAlex Samuel <samuel@gcc.gnu.org>
Fri, 3 Dec 1999 16:45:53 +0000 (16:45 +0000)
* g++.old-deja/g++.abi/align.C: New test.
* g++.old-deja/g++.abi/aggregates.C: Likewise.
* g++.old-deja/g++.abi/bitfields.C: Likewise.

From-SVN: r30769

gcc/testsuite/ChangeLog
gcc/testsuite/g++.old-deja/g++.abi/aggregates.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.abi/align.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.abi/bitfields.C [new file with mode: 0644]

index bc4325b..cc47296 100644 (file)
@@ -1,3 +1,9 @@
+1999-12-02  Alex Samuel  <samuel@codesourcery.com>
+
+       * g++.old-deja/g++.abi/align.C: New test.
+       * g++.old-deja/g++.abi/aggregates.C: Likewise.
+       * g++.old-deja/g++.abi/bitfields.C: Likewise.
+
 1999-12-01  Richard Henderson  <rth@cygnus.com>
 
        * gcc.c-torture/execute/991201-1.c: New.
diff --git a/gcc/testsuite/g++.old-deja/g++.abi/aggregates.C b/gcc/testsuite/g++.old-deja/g++.abi/aggregates.C
new file mode 100644 (file)
index 0000000..37f5385
--- /dev/null
@@ -0,0 +1,125 @@
+// Skip if not target: i?86-*-linux*
+// Special g++ Options: -malign-double
+// Origin: Alex Samuel <samuel@codesourcery.com>
+
+/* Test the data layout of C aggregates by checking aggregate size and
+   alignment and field offsets for compliance with the IA-64 ABI.  */
+
+template<typename T>
+inline unsigned
+alignmentof ()
+{
+  struct S
+  {
+    char start_;
+    T object_;
+  };
+
+  return (unsigned) & ((S *) 0)->object_;
+}
+
+/* Computes the alignment, in bytes, of TYPE.  */
+
+#define alignof(type) (alignmentof<type> ())
+
+/* Computes the offset of FIELD in AGGREGATE.  */
+
+#define offsetof(aggregate, field) \
+  ((unsigned) (& ((aggregate*) 0)->field))
+
+
+/* Structs S1, S2, S3, S4, and union U5 are taken from Intel, "IA-64
+   Software Conventions and Runtime Architecture Guide", version of
+   August 1999.  */
+
+struct S1
+{
+  char c;
+};
+
+struct S2
+{
+  char c;
+  char d;
+  short s;
+  int n;
+};
+
+struct S3
+{
+  char c;
+  short s;
+};
+
+struct S4
+{
+  char c;
+  double d;
+  short s;
+};
+
+union U5
+{
+  char c;
+  short s;
+  int j;
+};
+
+
+
+int
+main ()
+{
+  if (sizeof (struct S1)               !=  1)
+    return 1;
+  if (alignof (struct S1)              !=  1)
+    return 2;
+  if (offsetof (struct S1, c)          !=  0)
+    return 3;
+  
+  if (sizeof (struct S2)               !=  8)
+    return 4;
+  if (alignof (struct S2)              !=  4)
+    return 5;
+  if (offsetof (struct S2, c)          !=  0)
+    return 6;
+  if (offsetof (struct S2, d)          !=  1)
+    return 7;
+  if (offsetof (struct S2, s)          !=  2)
+    return 8;
+  if (offsetof (struct S2, n)          !=  4)
+    return 9;
+  
+  if (sizeof (struct S3)               !=  4)
+    return 10;
+  if (alignof (struct S3)              !=  2)
+    return 11;
+  if (offsetof (struct S3, c)          !=  0)
+    return 12;
+  if (offsetof (struct S3, s)          !=  2)
+    return 13;
+  
+  if (sizeof (struct S4)               != 24)
+    return 14;
+  if (alignof (struct S4)              !=  8)
+    return 15;
+  if (offsetof (struct S4, c)          !=  0)
+    return 16;
+  if (offsetof (struct S4, d)          !=  8)
+    return 17;
+  if (offsetof (struct S4, s)          != 16)
+    return 18;
+  
+  if (sizeof (union U5)                        !=  4)
+    return 19;
+  if (alignof (union U5)               !=  4)
+    return 20;
+  if (offsetof (union U5, c)           !=  0)
+    return 21;
+  if (offsetof (union U5, s)           !=  0)
+    return 22;
+  if (offsetof (union U5, j)           !=  0)
+    return 23;
+  
+  return 0;
+}
diff --git a/gcc/testsuite/g++.old-deja/g++.abi/align.C b/gcc/testsuite/g++.old-deja/g++.abi/align.C
new file mode 100644 (file)
index 0000000..d35ea39
--- /dev/null
@@ -0,0 +1,122 @@
+// Skip if not target: i?86-*-linux*
+// Special g++ Options: -malign-double
+// Origin: Alex Samuel <samuel@codesourcery.com>
+
+/* Test the size and alignment of fundamental C types for compliance
+   with the IA-64 ABI.  */
+
+template<typename T>
+inline unsigned
+alignmentof ()
+{
+  struct S
+  {
+    char start_;
+    T object_;
+  };
+
+  return (unsigned) & ((S *) 0)->object_;
+}
+
+/* Computes the alignment, in bytes, of TYPE.  */
+
+#define alignof(type) (alignmentof<type> ())
+
+int
+main ()
+{
+  if (sizeof  (char)                    !=  1)
+    return 1;
+  if (alignof (char)                    !=  1)
+    return 2;
+  if (sizeof  (signed char)             !=  1)
+    return 3;
+  if (alignof (signed char)             !=  1)
+    return 4;
+  if (sizeof  (unsigned char)           !=  1)
+    return 5;  
+  if (alignof (unsigned char)           !=  1)
+    return 6;
+  if (sizeof  (short)                   !=  2)
+    return 7;
+  if (alignof (short)                   !=  2)
+    return 8;
+  if (sizeof  (signed short)            !=  2)
+    return 9
+  if (alignof (signed short)            !=  2)
+    return 10;
+  if (sizeof  (unsigned short)          !=  2)
+    return 11;
+  if (alignof (unsigned short)          !=  2)
+    return 12;
+  if (sizeof  (int)                     !=  4)
+    return 13;
+  if (alignof (int)                     !=  4)
+    return 14;
+  if (sizeof  (signed int)              !=  4)
+    return 15;
+  if (alignof (signed int)              !=  4)
+    return 16;
+  if (sizeof  (unsigned int)            !=  4)
+    return 17;
+  if (alignof (unsigned int)            !=  4)
+    return 18;
+  if (sizeof  (enum { a })              !=  4)
+    return 19;
+  if (alignof (enum { a })              !=  4)
+    return 20;
+#ifdef HAVE_IA64_TYPES
+  if (sizeof  (__int64)                 !=  8)
+    return 21;
+  if (alignof (__int64)                 !=  8)
+    return 22;
+  if (sizeof  (signed __int64)          !=  8)
+    return 23;
+  if (alignof (signed ___int64)         !=  8)
+    return 24;
+  if (sizeof  (unsigned __int64)        !=  8)
+    return 25;
+  if (alignof (unsigned __int64)        !=  8)
+    return 26;
+  if (sizeof  (__int128)                != 16)
+    return 27;
+  if (alignof (__int128)                != 16)
+    return 28;
+  if (sizeof  (signed __int128)         != 16)
+    return 29;
+  if (alignof (signed ___int128)        != 16)
+    return 30;
+  if (sizeof  (unsigned __int128)       != 16)
+    return 31;
+  if (alignof (unsigned ___int128)      != 16)
+    return 32;
+#endif  /* HAVE_IA64_TYPES  */
+  if (sizeof  (void *)                  !=  4)
+    return 33;
+  if (alignof (pointer)                 !=  4)
+    return 34;
+  if (sizeof  (void (*) ())             !=  4)
+    return 35;
+  if (alignof (void (*) ())             !=  4)
+    return 36;
+  if (sizeof  (float)                   !=  4)
+    return 37;
+  if (alignof (float)                   !=  4)
+    return 38;
+  if (sizeof  (double)                  !=  8)
+    return 39;
+  if (alignof (double)                  !=  8)
+    return 40;
+#ifdef HAVE_IA64_TYPES
+  if (sizeof  (__float80)               != 16)
+    return 41;
+  if (alignof (__float80)               != 16)
+    return 42;
+  if (sizeof  (__float128)              != 16)
+    return 43;
+  if (alignof (__float128)              != 16)
+    return 44;
+#endif  /* HAVE_IA64_TYPES  */
+
+  return 0;
+}
diff --git a/gcc/testsuite/g++.old-deja/g++.abi/bitfields.C b/gcc/testsuite/g++.old-deja/g++.abi/bitfields.C
new file mode 100644 (file)
index 0000000..75b6571
--- /dev/null
@@ -0,0 +1,159 @@
+// Skip if not target: i?86-*-linux*
+// Special g++ Options: -malign-double
+// Origin: Alex Samuel <samuel@codesourcery.com>
+
+/* Test the layout of bitfields in C aggretagtes for compliance with
+   the IA-64 ABI.  */
+
+#include <cstring>
+
+template<typename T>
+inline unsigned
+alignmentof ()
+{
+  struct S
+  {
+    char start_;
+    T object_;
+  };
+
+  return (unsigned) & ((S *) 0)->object_;
+}
+
+/* Computes the alignment, in bytes, of TYPE.  */
+
+#define alignof(type) (alignmentof<type> ())
+
+/* Returns true iff all the bits in the range 
+   START_BIT <= bit < START_BIT + NUM_BITS, and only those bits, are
+   set in the region of memory starting at BUF of LENGTH bytes.  */
+
+bool
+check_bits (char *buf,
+           unsigned length,
+           unsigned start_bit,
+           unsigned num_bits)
+{
+  for (unsigned bit = 0; bit < 8 * length; ++bit) {
+    bool is_set = (buf[bit / 8] & (1 << (bit % 8))) != 0;
+    if (start_bit <= bit && bit < start_bit + num_bits) {
+      if (! is_set)
+       return false;
+    }
+    else {
+      if (is_set)
+       return false;
+    }
+  }
+  return true;
+}
+
+/* Creates a variable of type AGGREGATE, sets FIELD to -1, and
+   verifies that NUM_BITS bits starting at START_BIT, and no other
+   bits, are set.  If the check fails, returns with value RVAL.  */
+
+#define CHECK_FIELD(AGGREGATE, FIELD, START_BIT, NUM_BITS, RVAL)          \
+  do {                                                                    \
+    AGGREGATE a__;                                                        \
+    memset (& a__, 0, sizeof (a__));                                      \
+    a__.FIELD = -1;                                                       \
+    if (! check_bits ((char *) & a__, sizeof (a__), START_BIT, NUM_BITS)) \
+      return RVAL;                                                        \
+  } while (0);
+
+
+
+/* Structs S1, S2, S3, S4, and union U5 are taken from Intel, "IA-64
+   Software Conventions and Runtime Architecture Guide", version of
+   August 1999.  */
+
+struct S1
+{
+  int       j : 5;
+  int       k : 6;
+  int       m : 7;
+};
+
+#ifdef HAVE_IA64_TYPES
+struct S2
+{
+  short     s : 9;
+  __int64   j : 9;
+  char      c    ;
+  short     t : 9;
+  short     u : 9;
+  char      d    ;
+};
+#endif  /* HAVE_IA64_TYPES  */
+
+struct S3
+{
+  char      c    ;
+  short     s : 8;
+};
+
+union U4
+{
+  char      c    ;
+  short     s : 8;
+};
+
+struct S5
+{
+  char      c    ;
+  int         : 0;
+  char      d    ;
+  short       : 9;
+  char      e    ;
+  char        : 0;
+};
+
+
+int
+main ()
+{
+  if (sizeof (struct S1)               !=  4)
+    return 1;
+  if (alignof (struct S1)              !=  4)
+    return 2;
+  CHECK_FIELD (S1, j,  0,  5,  3);
+  CHECK_FIELD (S1, k,  5,  6,  4);
+  CHECK_FIELD (S1, m, 11,  7,  5);
+
+#ifdef HAVE_IA64_TYPES
+  if (sizeof (struct S2)               != 16)
+    return 6;
+  if (alignof (struct S2)              !=  8)
+    return 7;
+  CHECK_FIELD (S2, s,  0,  9,  8);
+  CHECK_FIELD (S2, j,  9,  9,  9);
+  CHECK_FIELD (S2, c, 24,  8, 10);
+  CHECK_FIELD (S2, t, 32,  9, 11);
+  CHECK_FIELD (S2, u, 48,  9, 12);
+  CHECK_FIELD (S2, d, 64,  8, 13);
+#endif  /* HAVE_IA64_TYPES  */
+
+  if (sizeof (struct S3)               !=  2)
+    return 14;
+  if (sizeof (struct S3)               !=  2)
+    return 15;
+  CHECK_FIELD (S3, c,  0,  8, 16);
+  CHECK_FIELD (S3, s,  8,  8, 17);
+
+  if (sizeof (union U4)                !=  2)
+    return 18;
+  if (alignof (union U4)               !=  2)
+    return 19;
+  CHECK_FIELD (U4, c,  0,  8, 20);
+  CHECK_FIELD (U4, s,  0,  8, 21);
+
+  if (sizeof (struct S5)               !=  9)
+    return 22;
+  if (alignof (struct S5)              !=  1)
+    return 23;
+  CHECK_FIELD (S5, c,  0,  8, 24);
+  CHECK_FIELD (S5, d, 32,  8, 25);
+  CHECK_FIELD (S5, e, 64,  8, 26);
+
+  return 0;
+}