OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [g++.old-deja/] [g++.abi/] [aggregates.C] - Diff between revs 154 and 816

Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
// { dg-do run { target i?86-*-linux* x86_64-*-linux* i?86-*-freebsd* } }
// { dg-do run { target i?86-*-linux* x86_64-*-linux* i?86-*-freebsd* } }
// { dg-require-effective-target ilp32 }
// { dg-require-effective-target ilp32 }
// { dg-options "-malign-double" }
// { dg-options "-malign-double" }
// Origin: Alex Samuel 
// Origin: Alex Samuel 
/* Test the data layout of C aggregates by checking aggregate size and
/* Test the data layout of C aggregates by checking aggregate size and
   alignment and field offsets for compliance with the IA-64 ABI.  */
   alignment and field offsets for compliance with the IA-64 ABI.  */
template
template
inline unsigned
inline unsigned
alignmentof ()
alignmentof ()
{
{
  struct S
  struct S
  {
  {
    char start_;
    char start_;
    T object_;
    T object_;
  };
  };
  return (unsigned) & ((S *) 0)->object_;
  return (unsigned) & ((S *) 0)->object_;
}
}
/* Computes the alignment, in bytes, of TYPE.  */
/* Computes the alignment, in bytes, of TYPE.  */
#define alignof(type) (alignmentof ())
#define alignof(type) (alignmentof ())
/* Computes the offset of FIELD in AGGREGATE.  */
/* Computes the offset of FIELD in AGGREGATE.  */
#define offsetof(aggregate, field) \
#define offsetof(aggregate, field) \
  ((unsigned) (& ((aggregate*) 0)->field))
  ((unsigned) (& ((aggregate*) 0)->field))
/* Structs S1, S2, S3, S4, and union U5 are taken from Intel, "IA-64
/* Structs S1, S2, S3, S4, and union U5 are taken from Intel, "IA-64
   Software Conventions and Runtime Architecture Guide", version of
   Software Conventions and Runtime Architecture Guide", version of
   August 1999.  */
   August 1999.  */
struct S1
struct S1
{
{
  char c;
  char c;
};
};
struct S2
struct S2
{
{
  char c;
  char c;
  char d;
  char d;
  short s;
  short s;
  int n;
  int n;
};
};
struct S3
struct S3
{
{
  char c;
  char c;
  short s;
  short s;
};
};
struct S4
struct S4
{
{
  char c;
  char c;
  double d;
  double d;
  short s;
  short s;
};
};
union U5
union U5
{
{
  char c;
  char c;
  short s;
  short s;
  int j;
  int j;
};
};
int
int
main ()
main ()
{
{
  if (sizeof (struct S1)                !=  1)
  if (sizeof (struct S1)                !=  1)
    return 1;
    return 1;
  if (alignof (struct S1)               !=  1)
  if (alignof (struct S1)               !=  1)
    return 2;
    return 2;
  if (offsetof (struct S1, c)           !=  0)
  if (offsetof (struct S1, c)           !=  0)
    return 3;
    return 3;
  if (sizeof (struct S2)                !=  8)
  if (sizeof (struct S2)                !=  8)
    return 4;
    return 4;
  if (alignof (struct S2)               !=  4)
  if (alignof (struct S2)               !=  4)
    return 5;
    return 5;
  if (offsetof (struct S2, c)           !=  0)
  if (offsetof (struct S2, c)           !=  0)
    return 6;
    return 6;
  if (offsetof (struct S2, d)           !=  1)
  if (offsetof (struct S2, d)           !=  1)
    return 7;
    return 7;
  if (offsetof (struct S2, s)           !=  2)
  if (offsetof (struct S2, s)           !=  2)
    return 8;
    return 8;
  if (offsetof (struct S2, n)           !=  4)
  if (offsetof (struct S2, n)           !=  4)
    return 9;
    return 9;
  if (sizeof (struct S3)                !=  4)
  if (sizeof (struct S3)                !=  4)
    return 10;
    return 10;
  if (alignof (struct S3)               !=  2)
  if (alignof (struct S3)               !=  2)
    return 11;
    return 11;
  if (offsetof (struct S3, c)           !=  0)
  if (offsetof (struct S3, c)           !=  0)
    return 12;
    return 12;
  if (offsetof (struct S3, s)           !=  2)
  if (offsetof (struct S3, s)           !=  2)
    return 13;
    return 13;
  if (sizeof (struct S4)                != 24)
  if (sizeof (struct S4)                != 24)
    return 14;
    return 14;
  if (alignof (struct S4)               !=  8)
  if (alignof (struct S4)               !=  8)
    return 15;
    return 15;
  if (offsetof (struct S4, c)           !=  0)
  if (offsetof (struct S4, c)           !=  0)
    return 16;
    return 16;
  if (offsetof (struct S4, d)           !=  8)
  if (offsetof (struct S4, d)           !=  8)
    return 17;
    return 17;
  if (offsetof (struct S4, s)           != 16)
  if (offsetof (struct S4, s)           != 16)
    return 18;
    return 18;
  if (sizeof (union U5)                 !=  4)
  if (sizeof (union U5)                 !=  4)
    return 19;
    return 19;
  if (alignof (union U5)                !=  4)
  if (alignof (union U5)                !=  4)
    return 20;
    return 20;
  if (offsetof (union U5, c)            !=  0)
  if (offsetof (union U5, c)            !=  0)
    return 21;
    return 21;
  if (offsetof (union U5, s)            !=  0)
  if (offsetof (union U5, s)            !=  0)
    return 22;
    return 22;
  if (offsetof (union U5, j)            !=  0)
  if (offsetof (union U5, j)            !=  0)
    return 23;
    return 23;
  return 0;
  return 0;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.