diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4c9a0dae7f5..b64cf992998 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2003-09-03 Mark Mitchell + + PR c++/12053 + * class.c (include_empty_classes): Correct logic for ABI version 1. + 2003-09-03 Richard Henderson * optimize.c (optimize_function): Push/pop ggc context around diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 3cf161b1e30..1bd63cffa6b 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -4586,7 +4586,19 @@ include_empty_classes (record_layout_info rli) if (TREE_CODE (rli_size) == INTEGER_CST && INT_CST_LT_UNSIGNED (rli_size, eoc)) { - rli->bitpos = round_up (rli->bitpos, BITS_PER_UNIT); + if (!abi_version_at_least (2)) + /* In version 1 of the ABI, the size of a class that ends with + a bitfield was not rounded up to a whole multiple of a + byte. Because rli_size_unit_so_far returns only the number + of fully allocated bytes, any extra bits were not included + in the size. */ + rli->bitpos = round_down (rli->bitpos, BITS_PER_UNIT); + else + /* The size should have been rounded to a whole byte. */ + my_friendly_assert (tree_int_cst_equal (rli->bitpos, + round_down (rli->bitpos, + BITS_PER_UNIT)), + 20030903); rli->bitpos = size_binop (PLUS_EXPR, rli->bitpos, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 57b9436a933..a6d708c98fa 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2003-09-03 Mark Mitchell + + PR c++/12053 + * g++.dg/abi/layout4.C: New test. + 2003-09-02 Scott Brumbaugh PR c++/11553 diff --git a/gcc/testsuite/g++.dg/abi/layout4.C b/gcc/testsuite/g++.dg/abi/layout4.C new file mode 100644 index 00000000000..a1d27ee7f43 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/layout4.C @@ -0,0 +1,18 @@ +// { dg-do run { target i?86-*-* } } +// { dg-options "-fabi-version=1" } + +struct C4 +{ + int b:30; + C4(){}; +}; + +struct C1: virtual C4 +{ + int i; +}; + +int main() { + if (sizeof (C1) != 12) + return 1; +}