From: Roger Sayle Date: Sun, 26 Sep 2004 14:58:34 +0000 (+0000) Subject: re PR middle-end/17112 (Copying of packed bitfields is wrong) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=897f610ba4492354c4bab4d61f476dc8d27c9124;p=gcc.git re PR middle-end/17112 (Copying of packed bitfields is wrong) PR middle-end/17112 * stor-layout.c (compute_record_mode): For records with a single field, only use the field's mode if its size matches what we'd have choosen for the record ourselves. This forces the use of BLKmode for packed records that don't completely fill a mode. * gcc.dg/pr17112-1.c: New test case. Co-Authored-By: Giovanni Bajo From-SVN: r88130 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index af865b18477..75ba5a7163f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2004-09-26 Roger Sayle + Giovanni Bajo + + PR middle-end/17112 + * stor-layout.c (compute_record_mode): For records with a single + field, only use the field's mode if its size matches what we'd + have choosen for the record ourselves. This forces the use of + BLKmode for packed records that don't completely fill a mode. + 2004-09-26 Roger Sayle PR middle-end/17151 diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index ccbca424bbf..4ac93404a8e 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -1296,12 +1296,14 @@ compute_record_mode (tree type) #endif /* MEMBER_TYPE_FORCES_BLK */ } - /* If we only have one real field; use its mode. This only applies to - RECORD_TYPE. This does not apply to unions. */ - if (TREE_CODE (type) == RECORD_TYPE && mode != VOIDmode) + TYPE_MODE (type) = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1); + + /* If we only have one real field; use its mode if that mode's size + matches the type's size. This only applies to RECORD_TYPE. This + does not apply to unions. */ + if (TREE_CODE (type) == RECORD_TYPE && mode != VOIDmode + && GET_MODE_SIZE (mode) == GET_MODE_SIZE (TYPE_MODE (type))) TYPE_MODE (type) = mode; - else - TYPE_MODE (type) = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1); /* If structure's known alignment is less than what the scalar mode would need, and it matters, then stick with BLKmode. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 32c3d51a555..f6ac25c0f07 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-09-26 Roger Sayle + + PR middle-end/17112 + * gcc.dg/pr17112-1.c: New test case. + 2004-09-26 Joseph S. Myers PR c/11459 diff --git a/gcc/testsuite/gcc.dg/pr17112-1.c b/gcc/testsuite/gcc.dg/pr17112-1.c new file mode 100644 index 00000000000..7c8b7aa0432 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr17112-1.c @@ -0,0 +1,32 @@ +/* PR middle-end/17112 */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +extern void abort(void); + +typedef struct { + int int24:24 __attribute__ ((packed)); +} myint24; + +myint24 x[3] = { + 0x123456, + 0x789abc, + 0xdef012 +}; + +myint24 y[3]; // starts out as zeros + +void foo() +{ + y[1] = x[1]; +} + +int main() +{ + foo(); + + if (y[0].int24 != 0 || y[2].int24 != 0) + abort(); + return 0; +} +