re PR middle-end/27948 (MS -bitfield struct layout test fails)
authorEric Christopher <echristo@apple.com>
Mon, 12 Jun 2006 06:53:33 +0000 (06:53 +0000)
committerEric Christopher <echristo@gcc.gnu.org>
Mon, 12 Jun 2006 06:53:33 +0000 (06:53 +0000)
2006-06-11  Eric Christopher  <echristo@apple.com>

        PR middle-end/27948
        * stor-layout.c (place_field): Remove check for
        remaining_in_alignment when aligning at the end of a run.

2006-06-11  Eric Christopher  <echristo@apple.com>

PR middle-end/27948
        * gcc.dg/bf-ms-layout.c: Run on darwin.
        * gcc.dg/bf-no-ms-layout: Ditto.
        * gcc.dg/attr-ms_struct-2.c: New.
        * gcc.dg/bf-ms-layout-2.c: Ditto.

From-SVN: r114562

gcc/ChangeLog
gcc/stor-layout.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/attr-ms_struct-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/bf-ms-layout-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/bf-ms-layout.c
gcc/testsuite/gcc.dg/bf-no-ms-layout.c

index 6c5fa70..c95edb3 100644 (file)
@@ -1,5 +1,11 @@
 2006-06-11  Eric Christopher  <echristo@apple.com>
 
+       PR middle-end/27948
+       * stor-layout.c (place_field): Remove check for
+       remaining_in_alignment when aligning at the end of a run.
+
+2006-06-11  Eric Christopher  <echristo@apple.com>
+
        PR 27542
        * doc/extend.texi (Structure-Packing Pragmas): Document ms_struct
        pragma.
index bf67099..47bc6a0 100644 (file)
@@ -1070,8 +1070,7 @@ place_field (record_layout_info rli, tree field)
                 Note: since the beginning of the field was aligned then
                 of course the end will be too.  No round needed.  */
 
-             if (!integer_zerop (DECL_SIZE (rli->prev_field))
-                 && rli->remaining_in_alignment)
+             if (!integer_zerop (DECL_SIZE (rli->prev_field)))
                {
                  rli->bitpos
                    = size_binop (PLUS_EXPR, rli->bitpos,
@@ -1085,7 +1084,7 @@ place_field (record_layout_info rli, tree field)
              /* Cause a new bitfield to be captured, either this time (if
                 currently a bitfield) or next time we see one.  */
              if (!DECL_BIT_FIELD_TYPE(field)
-                || integer_zerop (DECL_SIZE (field)))
+                 || integer_zerop (DECL_SIZE (field)))
                rli->prev_field = NULL;
            }
 
@@ -1105,9 +1104,9 @@ place_field (record_layout_info rli, tree field)
         there wasn't.  */
 
       if (!DECL_BIT_FIELD_TYPE (field)
-         || ( prev_saved != NULL
-              ? !simple_cst_equal (TYPE_SIZE (type),
-                                   TYPE_SIZE (TREE_TYPE (prev_saved)))
+         || (prev_saved != NULL
+             ? !simple_cst_equal (TYPE_SIZE (type),
+                                  TYPE_SIZE (TREE_TYPE (prev_saved)))
              : !integer_zerop (DECL_SIZE (field)) ))
        {
          /* Never smaller than a byte for compatibility.  */
index e2c222f..a4fbcd4 100644 (file)
@@ -1,3 +1,11 @@
+2006-06-11  Eric Christopher  <echristo@apple.com>
+
+       PR middle-end/27948
+       * gcc.dg/bf-ms-layout.c: Run on darwin.
+       * gcc.dg/bf-no-ms-layout: Ditto.
+       * gcc.dg/attr-ms_struct-2.c: New.
+       * gcc.dg/bf-ms-layout-2.c: Ditto.
+
 2006-06-11  Kaz Kojima  <kkojima@gcc.gnu.org>
 
        * gcc.dg/attr-ms_struct-packed1.c: New.
        * gcc/testsuite/gfortran.dg/substr_2.f: New test.
 
 2006-06-08  Asher Langton  <langton2@llnl.gov>
-       
+
        PR fortran/27786
        * cray_pointers_2.f90: Add -fbounds-check compile flag.
-       
+
 2006-06-08  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        PR target/27421
 
 2006-06-05  Dorit Nuzman  <dorit@il.ibm.com>
             Victor Kaplansky  <victork@il.ibm.com>
-           
+
        PR tree-optimizations/26360
        * gcc.dg/vect/vect.exp: Compile tests prefixed with "no-tree-dce"
        with -fno-tree-dce.
 
        PR c++/27807
        * g++.dg/ext/complit7.C: New test.
-       
+
        PR c++/27806
        * g++.dg/parse/ptrmem5.C: New test.
 
diff --git a/gcc/testsuite/gcc.dg/attr-ms_struct-2.c b/gcc/testsuite/gcc.dg/attr-ms_struct-2.c
new file mode 100644 (file)
index 0000000..0e8f41e
--- /dev/null
@@ -0,0 +1,35 @@
+/* Test for MS structure sizes.  */
+/* { dg-do run { target *-*-interix* *-*-mingw* *-*-cygwin* i?86-*-darwin* } }
+/* { dg-options "-std=gnu99" } */
+
+extern void abort ();
+
+#define ATTR __attribute__((__ms_struct__))
+
+struct _struct_0
+{
+  long  member_0   : 25 ;
+  short  member_1   : 6 ;
+  char  member_2   : 2 ;
+  unsigned  short  member_3   : 1 ;
+  unsigned  char  member_4   : 7 ;
+  short  member_5   : 16 ;
+  long  : 0 ;
+  char  member_7  ;
+
+} ATTR;
+typedef struct _struct_0 struct_0;
+
+#define size_struct_0 20
+
+struct_0 test_struct_0 = { 18557917, 17, 3, 0, 80, 6487, 93 };
+
+int
+main (void)
+{
+
+  if (size_struct_0 != sizeof (struct_0))
+    abort ();
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/bf-ms-layout-2.c b/gcc/testsuite/gcc.dg/bf-ms-layout-2.c
new file mode 100644 (file)
index 0000000..0bd472b
--- /dev/null
@@ -0,0 +1,236 @@
+/* bf-ms-layout.c */
+
+/* Test for MS bitfield layout */
+/* Adapted from Donn Terry <donnte@microsoft.com> testcase
+   posted to GCC-patches
+   http://gcc.gnu.org/ml/gcc-patches/2000-08/msg00577.html */
+
+/* { dg-do run { target *-*-interix* *-*-mingw* *-*-cygwin* i?86-*-darwin* } } */
+/* { dg-options "-D_TEST_MS_LAYOUT" } */
+/* This test uses the attribute instead of the command line option.  */
+
+#include <stddef.h>
+#include <string.h>
+
+extern void abort();
+
+#pragma pack(8)
+
+#ifdef __GNUC__
+#define ATTR __attribute__ ((ms_struct))
+#endif
+
+struct one {
+  int d;
+  unsigned char a;
+  unsigned short b:7;
+  char c;
+} ATTR;
+
+struct two {
+  int d;
+  unsigned char a;
+  unsigned int b:7;
+  char c;
+} ATTR;
+
+struct three {
+  short d;
+  unsigned short a:3;
+  unsigned short b:9;
+  unsigned char c:7;
+} ATTR;
+
+
+/* Bitfields of size 0 have some truly odd behaviors. */
+
+struct four {
+  unsigned short a:3;
+  unsigned short b:9;
+  unsigned int :0;  /* forces struct alignment to int */
+  unsigned char c:7;
+} ATTR;
+
+struct five {
+  char a;
+  int :0;        /* ignored; prior field is not a bitfield. */
+  char b;
+  char c;
+} ATTR;
+
+struct six {
+  char a :8;
+  int :0;      /* not ignored; prior field IS a bitfield, causes
+                  struct alignment as well. */
+  char b;
+  char c;
+} ATTR;
+
+struct seven {
+  char a:8;
+  char :0;
+  int  :0;     /* Ignored; prior field is zero size bitfield. */
+  char b;
+  char c;
+} ATTR;
+
+struct eight { /* ms size 4 */
+  short b:3;
+  char  c;
+} ATTR;
+
+#ifdef _MSC_VER
+#define LONGLONG __int64
+#else
+#define LONGLONG long long
+#endif
+
+union nine {   /* ms size 8 */
+  LONGLONG a:3;
+  char  c;
+} ATTR;
+
+struct ten {   /* ms size 16 */
+  LONGLONG a:3;
+  LONGLONG b:3;
+  char  c;
+} ATTR;
+
+
+#define val(s,f) (s.f)
+
+#define check_struct(_X) \
+{ \
+  if (sizeof (struct _X) != exp_sizeof_##_X )  \
+    abort();                                   \
+  memcpy(&test_##_X, filler, sizeof(test_##_X));\
+  if (val(test_##_X,c) != exp_##_X##_c)        \
+     abort();                                  \
+}
+
+#define check_union(_X) \
+{ \
+  if (sizeof (union _X) != exp_sizeof_##_X )   \
+    abort();                                    \
+  memcpy(&test_##_X, filler, sizeof(test_##_X));\
+  if (val(test_##_X,c) != exp_##_X##_c)        \
+     abort();                                  \
+}
+
+#define check_struct_size(_X) \
+{ \
+  if (sizeof (struct _X) != exp_sizeof_##_X )  \
+    abort();                                    \
+}
+
+#define check_struct_off(_X) \
+{ \
+  memcpy(&test_##_X, filler, sizeof(test_##_X));\
+  if (val(test_##_X,c) != exp_##_X##_c)        \
+    abort();                                    \
+}
+
+#define check_union_size(_X) \
+{ \
+  if (sizeof (union _X) != exp_sizeof_##_X )   \
+    abort();                                    \
+}
+
+#define check_union_off(_X) \
+{ \
+  memcpy(&test_##_X, filler, sizeof(test_##_X));\
+  if (val(test_##_X,c) != exp_##_X##_c)        \
+    abort();                                    \
+}
+
+int main(){
+
+  unsigned char filler[16];
+  struct one test_one;
+  struct two test_two;
+  struct three test_three;
+  struct four test_four;
+  struct five test_five;
+  struct six test_six;
+  struct seven test_seven;
+  struct eight test_eight;
+  union nine test_nine;
+  struct ten test_ten;
+
+#if defined (_TEST_MS_LAYOUT) || defined (_MSC_VER)
+  size_t exp_sizeof_one = 12;
+  size_t exp_sizeof_two = 16;
+  size_t exp_sizeof_three =6;
+  size_t exp_sizeof_four = 8;
+  size_t exp_sizeof_five = 3;
+  size_t exp_sizeof_six = 8;
+  size_t exp_sizeof_seven = 3;
+  size_t exp_sizeof_eight = 4;
+  size_t exp_sizeof_nine = 8;
+  size_t exp_sizeof_ten = 16;
+
+  unsigned char exp_one_c = 8;
+  unsigned char exp_two_c  = 12;
+  unsigned char exp_three_c = 4;
+  unsigned char exp_four_c = 4;
+  char exp_five_c = 2;
+  char exp_six_c = 5;
+  char exp_seven_c = 2;
+  char exp_eight_c = 2;
+  char exp_nine_c = 0;
+  char exp_ten_c = 8;
+
+#else /* testing -mno-ms-bitfields */
+
+  size_t exp_sizeof_one = 8;
+  size_t exp_sizeof_two = 8;
+  size_t exp_sizeof_three = 6;
+  size_t exp_sizeof_four = 6;
+  size_t exp_sizeof_five = 6;
+  size_t exp_sizeof_six = 6;
+  size_t exp_sizeof_seven = 6;
+  size_t exp_sizeof_eight = 2;
+  size_t exp_sizeof_nine = 8;
+  size_t exp_sizeof_ten = 8;
+
+  unsigned short exp_one_c = 6;
+  unsigned int exp_two_c  = 6;
+  unsigned char exp_three_c = 64;
+  unsigned char exp_four_c = 4;
+  char exp_five_c = 5;
+  char exp_six_c = 5;
+  char exp_seven_c = 5;
+  char exp_eight_c = 1;
+  char exp_nine_c = 0;
+  char exp_ten_c = 1;
+
+#endif
+
+  unsigned char i;
+  for ( i = 0; i < 16; i++ )
+    filler[i] = i;
+
+  check_struct_off (one);
+  check_struct_off (two);
+  check_struct_off (three);
+  check_struct_off (four);
+  check_struct_off (five);
+  check_struct_off (six);
+  check_struct_off (seven);
+  check_struct_off (eight);
+  check_union_off (nine);
+  check_struct_off (ten);
+
+  check_struct_size (one);
+  check_struct_size (two);
+  check_struct_size (three);
+  check_struct_size (four);
+  check_struct_size (five);
+  check_struct_size (six);
+  check_struct_size (seven);
+  check_struct_size (eight);
+  check_union_size (nine);
+  check_struct_size (ten);
+
+  return 0;
+};
index c72f975..3acd1e4 100644 (file)
@@ -3,9 +3,9 @@
 /* Test for MS bitfield layout */
 /* Adapted from Donn Terry <donnte@microsoft.com> testcase
    posted to GCC-patches
-   http://gcc.gnu.org/ml/gcc-patches/2000-08/msg00577.html */ 
+   http://gcc.gnu.org/ml/gcc-patches/2000-08/msg00577.html */
 
-/* { dg-do run { target *-*-interix* *-*-mingw* *-*-cygwin* } } */
+/* { dg-do run { target *-*-interix* *-*-mingw* *-*-cygwin* i?86-*-darwin* } } */
 /* { dg-options "-mms-bitfields -D_TEST_MS_LAYOUT" } */
 
 #include <stddef.h>
@@ -19,22 +19,22 @@ struct one {
   int d;
   unsigned char a;
   unsigned short b:7;
-  char c;      
-};
+  char c;
+} ;
 
 struct two {
   int d;
   unsigned char a;
   unsigned int b:7;
-  char c;              
-};
+  char c;
+} ;
 
 struct three {
   short d;
   unsigned short a:3;
   unsigned short b:9;
   unsigned char c:7;
-};
+} ;
 
 
 /* Bitfields of size 0 have some truly odd behaviors. */
@@ -44,16 +44,16 @@ struct four {
   unsigned short b:9;
   unsigned int :0;  /* forces struct alignment to int */
   unsigned char c:7;
-};
+} ;
 
 struct five {
-  char a;              
+  char a;
   int :0;        /* ignored; prior field is not a bitfield. */
   char b;
   char c;
-};
+} ;
 
-struct six { 
+struct six {
   char a :8;
   int :0;      /* not ignored; prior field IS a bitfield, causes
                   struct alignment as well. */
@@ -67,12 +67,12 @@ struct seven {
   int  :0;     /* Ignored; prior field is zero size bitfield. */
   char b;
   char c;
-};
+} ;
 
 struct eight { /* ms size 4 */
-  short b:3;  
+  short b:3;
   char  c;
-};
+} ;
 
 #ifdef _MSC_VER
 #define LONGLONG __int64
@@ -83,13 +83,13 @@ struct eight { /* ms size 4 */
 union nine {   /* ms size 8 */
   LONGLONG a:3;
   char  c;
-};
+} ;
 
 struct ten {   /* ms size 16 */
   LONGLONG a:3;
   LONGLONG b:3;
   char  c;
-};
+} ;
 
 
 #define val(s,f) (s.f)
@@ -151,7 +151,7 @@ int main(){
   struct eight test_eight;
   union nine test_nine;
   struct ten test_ten;
+
 #if defined (_TEST_MS_LAYOUT) || defined (_MSC_VER)
   size_t exp_sizeof_one = 12;
   size_t exp_sizeof_two = 16;
@@ -180,7 +180,7 @@ int main(){
   size_t exp_sizeof_one = 8;
   size_t exp_sizeof_two = 8;
   size_t exp_sizeof_three = 6;
-  size_t exp_sizeof_four = 6;  
+  size_t exp_sizeof_four = 6;
   size_t exp_sizeof_five = 6;
   size_t exp_sizeof_six = 6;
   size_t exp_sizeof_seven = 6;
@@ -201,12 +201,12 @@ int main(){
 
 #endif
 
-  unsigned char i; 
+  unsigned char i;
   for ( i = 0; i < 16; i++ )
     filler[i] = i;
 
   check_struct_off (one);
-  check_struct_off (two);  
+  check_struct_off (two);
   check_struct_off (three);
   check_struct_off (four);
   check_struct_off (five);
@@ -217,7 +217,7 @@ int main(){
   check_struct_off (ten);
 
   check_struct_size (one);
-  check_struct_size (two);  
+  check_struct_size (two);
   check_struct_size (three);
   check_struct_size (four);
   check_struct_size (five);
@@ -229,4 +229,3 @@ int main(){
 
   return 0;
 };
-
index 430b927..7e55321 100644 (file)
@@ -3,9 +3,9 @@
 /* Test for gcc bitfield layout, with -mno-ms-bitfields */
 /* Adapted from Donn Terry <donnte@microsoft.com> testcase
    posted to GCC-patches
-   http://gcc.gnu.org/ml/gcc-patches/2000-08/msg00577.html */ 
+   http://gcc.gnu.org/ml/gcc-patches/2000-08/msg00577.html */
 
-/* { dg-do run { target *-*-interix* *-*-mingw* *-*-cygwin* } } */
+/* { dg-do run { target *-*-interix* *-*-mingw* *-*-cygwin* i?86-*-darwin } } */
 /* { dg-options "-mno-ms-bitfields" } */
 
 #include <stddef.h>
@@ -19,14 +19,14 @@ struct one {
   int d;
   unsigned char a;
   unsigned short b:7;
-  char c;      
+  char c;
 };
 
 struct two {
   int d;
   unsigned char a;
   unsigned int b:7;
-  char c;              
+  char c;
 };
 
 struct three {
@@ -47,13 +47,13 @@ struct four {
 };
 
 struct five {
-  char a;              
+  char a;
   int :0;        /* ignored; prior field is not a bitfield. */
   char b;
   char c;
 };
 
-struct six { 
+struct six {
   char a :8;
   int :0;      /* not ignored; prior field IS a bitfield, causes
                   struct alignment as well. */
@@ -70,7 +70,7 @@ struct seven {
 };
 
 struct eight { /* ms size 4 */
-  short b:3;  
+  short b:3;
   char  c;
 };
 
@@ -151,7 +151,7 @@ int main(){
   struct eight test_eight;
   union nine test_nine;
   struct ten test_ten;
+
 #if defined (_TEST_MS_LAYOUT) || defined (_MSC_VER)
   size_t exp_sizeof_one = 12;
   size_t exp_sizeof_two = 16;
@@ -180,7 +180,7 @@ int main(){
   size_t exp_sizeof_one = 8;
   size_t exp_sizeof_two = 8;
   size_t exp_sizeof_three = 6;
-  size_t exp_sizeof_four = 6;  
+  size_t exp_sizeof_four = 6;
   size_t exp_sizeof_five = 6;
   size_t exp_sizeof_six = 6;
   size_t exp_sizeof_seven = 6;
@@ -201,12 +201,12 @@ int main(){
 
 #endif
 
-  unsigned char i; 
+  unsigned char i;
   for ( i = 0; i < 16; i++ )
     filler[i] = i;
 
   check_struct_off (one);
-  check_struct_off (two);  
+  check_struct_off (two);
   check_struct_off (three);
   check_struct_off (four);
   check_struct_off (five);
@@ -217,7 +217,7 @@ int main(){
   check_struct_off (ten);
 
   check_struct_size (one);
-  check_struct_size (two);  
+  check_struct_size (two);
   check_struct_size (three);
   check_struct_size (four);
   check_struct_size (five);
@@ -229,4 +229,3 @@ int main(){
 
   return 0;
 };
-