This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR c++/42217


Hello,

remove_zero_width_bit_fields fails to remove zero-width unnamed bit fields
from a given struct. It thinks the size of the bit field is stored in the
DECL_INITIAL property of the bit field, but that size is eventually stored
in the DECL_SIZE property by check_bitfield_decl.

The patch below adjusts remove_zero_width_bit_fields accordingly.

Tested against trunk on x86_64-unknown-linux-gnu.

        Dodji

commit bbbaa69c68ce3dbcf843645b22f4d930017f90a7
Author: Dodji Seketeli <dodji@redhat.com>
Date:   Mon Nov 30 22:10:31 2009 +0100

    Fix PR c++/42217
    
    gcc/cp/ChangeLog
    	PR c++/42217
    	* class.c (remove_zero_width_bit_fields): The width of the bit field is
    	in DECL_SIZE, not in DECL_INITIAL.
    
    gcc/testsuite/ChangeLog
    	PR c++/42217
    	* g++.dg/other/bitfield4.C: New test.

diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 38eb73f..07c0314 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -4254,7 +4254,12 @@ remove_zero_width_bit_fields (tree t)
     {
       if (TREE_CODE (*fieldsp) == FIELD_DECL
 	  && DECL_C_BIT_FIELD (*fieldsp)
-	  && DECL_INITIAL (*fieldsp))
+          /* We should not be confused by the fact that grokbitfield
+	     temporarily sets the width of the bit field into
+	     DECL_INITIAL (*fieldsp).
+	     check_bitfield_decl eventually sets DECL_SIZE (*fieldsp)
+	     to that width.  */
+	  && integer_zerop (DECL_SIZE (*fieldsp)))
 	*fieldsp = TREE_CHAIN (*fieldsp);
       else
 	fieldsp = &TREE_CHAIN (*fieldsp);
diff --git a/gcc/testsuite/g++.dg/other/bitfield4.C b/gcc/testsuite/g++.dg/other/bitfield4.C
new file mode 100644
index 0000000..d140f82
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/bitfield4.C
@@ -0,0 +1,10 @@
+// Contributed by Dodji Seketeli <dodji@redhat.com>
+// Origin PR c++/42217
+// { dg-do compile }
+
+struct A
+{
+ int : 0;
+};
+A a = A();
+


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]