Hi, the original testcase for PR 45644 did not fail on gcc 4.5 but the bug is there as the testcase of PR 51759 shows. Therefore I've backported the patch to the 4.5 branch. The only change is the use of gcc_assert instead of gcc_checking_assert since we didn't have that in 4.5 times.
Bootstrapped and tested on x86_64-linux, unless someone objects, I will commit it to the branch and the new test to both the 4.6 branch and the trunk on Monday. Thanks, Martin 2012-01-06 Martin Jambor <mjam...@suse.cz> PR tree-optimization/51759 Backport from mainline 2010-09-15 Martin Jambor <mjam...@suse.cz> PR middle-end/45644 * tree-sra.c (create_access): Check for bit-fields directly. * testsuite/gcc.dg/ipa/pr45644.c: New test. * testsuite/g++.dg/ipa/pr51759.C: Likewise. Index: testsuite/gcc.dg/ipa/pr45644.c =================================================================== --- testsuite/gcc.dg/ipa/pr45644.c (revision 0) +++ testsuite/gcc.dg/ipa/pr45644.c (revision 0) @@ -0,0 +1,35 @@ +/* Verify that we do not IPA-SRA bitfields. */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +extern void abort (void); + +struct S +{ + int j : 8; + int i : 24; + int l; +}; + +static int __attribute__((noinline)) foo (struct S *s) +{ + int z = s->i; + if (z != 777) + abort (); + return 0; +} + +int __attribute__((noinline)) bar (struct S *s) +{ + return foo (s); +} + +int main (int argc, char *argv[]) +{ + struct S s; + s.j = 5; + s.i = 777; + s.l = -1; + + return bar (&s); +} Index: testsuite/g++.dg/ipa/pr51759.C =================================================================== --- testsuite/g++.dg/ipa/pr51759.C (revision 0) +++ testsuite/g++.dg/ipa/pr51759.C (revision 0) @@ -0,0 +1,26 @@ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +extern "C" void abort (void); +struct S +{ + void __attribute__((noinline)) set(unsigned val) + { + data = val; + if (data != val) + abort (); + } + int pad0; + unsigned pad1 : 8; + unsigned data : 24; + int pad2; +}; +int main() +{ + S s; + s.pad2 = -1; + s.set(0); + if (s.pad2 != -1) + abort (); +} + Index: tree-sra.c =================================================================== --- tree-sra.c (revision 182905) +++ tree-sra.c (working copy) @@ -771,12 +771,13 @@ create_access (tree expr, gimple stmt, b disqualify_candidate (base, "Encountered a variable sized access."); return NULL; } - if ((offset % BITS_PER_UNIT) != 0 || (size % BITS_PER_UNIT) != 0) + if (TREE_CODE (expr) == COMPONENT_REF + && DECL_BIT_FIELD (TREE_OPERAND (expr, 1))) { - disqualify_candidate (base, - "Encountered an acces not aligned to a byte."); + disqualify_candidate (base, "Encountered a bit-field access."); return NULL; } + gcc_assert ((offset % BITS_PER_UNIT) == 0); if (ptr) mark_parm_dereference (base, offset + size, stmt);