[backport gcc-4.9/trunk r199240 ] gcc/ 2013-05-23 Richard Biener PR middle-end/57381 * fold-const.c (operand_equal_p): Compare FIELD_DECLs with OEP_CONSTANT_ADDRESS_OF retained. gcc/testsuite/ 2013-05-23 Richard Biener PR middle-end/57381 * gcc.dg/torture/pr57381.c: New testcase. --- gcc-4.8.0/gcc/fold-const.c.~1~ 2013-02-26 11:00:31.000000000 +0100 +++ gcc-4.8.0/gcc/fold-const.c 2013-05-25 12:13:16.855220798 +0200 @@ -2600,10 +2600,10 @@ operand_equal_p (const_tree arg0, const_ case COMPONENT_REF: /* Handle operand 2 the same as for ARRAY_REF. Operand 0 may be NULL when we're called to compare MEM_EXPRs. */ - if (!OP_SAME_WITH_NULL (0)) + if (!OP_SAME_WITH_NULL (0) || !OP_SAME (1)) return 0; flags &= ~OEP_CONSTANT_ADDRESS_OF; - return OP_SAME (1) && OP_SAME_WITH_NULL (2); + return OP_SAME_WITH_NULL (2); case BIT_FIELD_REF: if (!OP_SAME (0)) --- gcc-4.8.0/gcc/testsuite/gcc.dg/torture/pr57381.c.~1~ 1970-01-01 01:00:00.000000000 +0100 +++ gcc-4.8.0/gcc/testsuite/gcc.dg/torture/pr57381.c 2013-05-25 12:13:16.855220798 +0200 @@ -0,0 +1,24 @@ +/* { dg-do compile } */ + +struct S0 { int f0, f1, f2; }; + +struct S1 { + int f0; + volatile struct S0 f2; +}; + +static struct S1 s = {0x47BED265,{0x06D4EB3E,5,0U}}; + +int foo(struct S0 p) +{ + for (s.f2.f2 = 0; (s.f2.f2 <= 12); s.f2.f2++) + { + volatile int *l_61[5][2][2] = {{{&s.f2.f0,&s.f2.f0},{&s.f2.f0,&s.f2.f0}},{{&s.f2.f0,&s.f2.f0},{&s.f2.f0,&s.f2.f0}},{{&s.f2.f0,(void*)0},{&s.f2.f0,&s.f2.f0}},{{&s.f2.f0,&s.f2.f0},{&s.f2.f0,&s.f2.f0}},{{&s.f2.f0,&s.f2.f0},{(void*)0,&s.f2.f0}}}; + + volatile int **l_68 = &l_61[0][0][1]; + volatile int *l_76 = &s.f2.f0; + (*l_68) = l_61[0][0][0]; + if ((*l_76 = (p.f2 % 5))) ; + } + return p.f0; +}