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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [testsuite/] [gcc.target/] [x86_64/] [abi/] [test_bitfields.c] - Diff between revs 149 and 154

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

Rev 149 Rev 154
/* This is a small test to see if bitfields are working.  It is only a
/* This is a small test to see if bitfields are working.  It is only a
   few structs and a union and a test to see if they have the correct
   few structs and a union and a test to see if they have the correct
   size, if values can be read and written and a couple of argument
   size, if values can be read and written and a couple of argument
   passing tests.  No alignment testing is done.  */
   passing tests.  No alignment testing is done.  */
 
 
#include "defines.h"
#include "defines.h"
#include "macros.h"
#include "macros.h"
 
 
 
 
/* These five bitfields are taken from the System V ABI, Intel 386
/* These five bitfields are taken from the System V ABI, Intel 386
   architecture supplement.  */
   architecture supplement.  */
 
 
/* Word aligned, sizeof is 4.  */
/* Word aligned, sizeof is 4.  */
struct RightToLeft
struct RightToLeft
{
{
  int j:5;
  int j:5;
  int k:6;
  int k:6;
  int m:7;
  int m:7;
};
};
 
 
/* Word aligned, sizeof is 12.  */
/* Word aligned, sizeof is 12.  */
struct BoundaryAlignment
struct BoundaryAlignment
{
{
  short s:9;
  short s:9;
  int   j:9;
  int   j:9;
  char  c;
  char  c;
  short t:9;
  short t:9;
  short u:9;
  short u:9;
  char  d;
  char  d;
};
};
 
 
/* Halfword aligned, sizeof is 2.  */
/* Halfword aligned, sizeof is 2.  */
struct StorageUnitSharing
struct StorageUnitSharing
{
{
  char  c;
  char  c;
  short s:8;
  short s:8;
};
};
 
 
/* Halfword aligned, sizeof is 2.  */
/* Halfword aligned, sizeof is 2.  */
union Allocation
union Allocation
{
{
  char  c;
  char  c;
  short s:8;
  short s:8;
};
};
 
 
/* Byte aligned, sizeof is 9.  */
/* Byte aligned, sizeof is 9.  */
struct Unnamed
struct Unnamed
{
{
  char  c;
  char  c;
  int    :0;
  int    :0;
  char  d;
  char  d;
  short  :9;
  short  :9;
  char  e;
  char  e;
  char   :0;
  char   :0;
};
};
 
 
/* Extra struct testing bitfields in larger types.
/* Extra struct testing bitfields in larger types.
   Doubleword aligned, sizeof is 8.  */
   Doubleword aligned, sizeof is 8.  */
struct LargerTypes
struct LargerTypes
{
{
  long long l:33;
  long long l:33;
  int       i:31;
  int       i:31;
};
};
 
 
 
 
void
void
passing1 (struct RightToLeft str, int j, int k, int m)
passing1 (struct RightToLeft str, int j, int k, int m)
{
{
  assert (str.j == j);
  assert (str.j == j);
  assert (str.k == k);
  assert (str.k == k);
  assert (str.m == m);
  assert (str.m == m);
}
}
 
 
void
void
passing2 (struct BoundaryAlignment str, short s, int j, char c, short t,
passing2 (struct BoundaryAlignment str, short s, int j, char c, short t,
          short u, char d)
          short u, char d)
{
{
  assert (str.s == s);
  assert (str.s == s);
  assert (str.j == j);
  assert (str.j == j);
  assert (str.c == c);
  assert (str.c == c);
  assert (str.t == t);
  assert (str.t == t);
  assert (str.u == u);
  assert (str.u == u);
  assert (str.d == d);
  assert (str.d == d);
}
}
 
 
void
void
passing3 (struct StorageUnitSharing str, char c, short s)
passing3 (struct StorageUnitSharing str, char c, short s)
{
{
  assert (str.c == c);
  assert (str.c == c);
  assert (str.s == s);
  assert (str.s == s);
}
}
 
 
void
void
passing4 (struct Unnamed str, char c, char d, char e)
passing4 (struct Unnamed str, char c, char d, char e)
{
{
  assert (str.c == c);
  assert (str.c == c);
  assert (str.d == d);
  assert (str.d == d);
  assert (str.e == e);
  assert (str.e == e);
}
}
 
 
void
void
passing5 (struct LargerTypes str, long long l, int i)
passing5 (struct LargerTypes str, long long l, int i)
{
{
  assert (str.l == l);
  assert (str.l == l);
  assert (str.i == i);
  assert (str.i == i);
}
}
 
 
 
 
void
void
passingU (union Allocation u, char c)
passingU (union Allocation u, char c)
{
{
  assert (u.c == c);
  assert (u.c == c);
  assert (u.s == c);
  assert (u.s == c);
}
}
 
 
 
 
int
int
main (void)
main (void)
{
{
  struct RightToLeft str1;
  struct RightToLeft str1;
  struct BoundaryAlignment str2;
  struct BoundaryAlignment str2;
  struct StorageUnitSharing str3;
  struct StorageUnitSharing str3;
  struct Unnamed str4;
  struct Unnamed str4;
  struct LargerTypes str5;
  struct LargerTypes str5;
  union Allocation u;
  union Allocation u;
 
 
  /* Check sizeof's.  */
  /* Check sizeof's.  */
  check_size(str1, 4);
  check_size(str1, 4);
  check_size(str2, 12);
  check_size(str2, 12);
  check_size(str3, 2);
  check_size(str3, 2);
  check_size(str4, 9);
  check_size(str4, 9);
  check_size(str5, 8);
  check_size(str5, 8);
  check_size(u, 2);
  check_size(u, 2);
 
 
  /* Check alignof's.  */
  /* Check alignof's.  */
  check_align_lv(str1, 4);
  check_align_lv(str1, 4);
  check_align_lv(str2, 4);
  check_align_lv(str2, 4);
  check_align_lv(str3, 2);
  check_align_lv(str3, 2);
  check_align_lv(str4, 1);
  check_align_lv(str4, 1);
  check_align_lv(str5, 8);
  check_align_lv(str5, 8);
  check_align_lv(u, 2);
  check_align_lv(u, 2);
 
 
  /* Check passing.  */
  /* Check passing.  */
  str1.j = str2.s = str3.c = str4.c = str5.l = 4;
  str1.j = str2.s = str3.c = str4.c = str5.l = 4;
  str1.k = str2.j = str3.s = str4.d = str5.i = 5;
  str1.k = str2.j = str3.s = str4.d = str5.i = 5;
  str1.m = str2.c = str4.e = 6;
  str1.m = str2.c = str4.e = 6;
  str2.t = 7;
  str2.t = 7;
  str2.u = 8;
  str2.u = 8;
  str2.d = 9;
  str2.d = 9;
  passing1 (str1, 4, 5, 6);
  passing1 (str1, 4, 5, 6);
  passing2 (str2, 4, 5, 6, 7, 8, 9);
  passing2 (str2, 4, 5, 6, 7, 8, 9);
  passing3 (str3, 4, 5);
  passing3 (str3, 4, 5);
  passing4 (str4, 4, 5, 6);
  passing4 (str4, 4, 5, 6);
  passing5 (str5, 4, 5);
  passing5 (str5, 4, 5);
 
 
  u.c = 5;
  u.c = 5;
  passingU (u, 5);
  passingU (u, 5);
  u.s = 6;
  u.s = 6;
  passingU (u, 6);
  passingU (u, 6);
 
 
  return 0;
  return 0;
}
}
 
 

powered by: WebSVN 2.1.0

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