This fixes another case of unequal addresses of volatile fields.

Boostrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2013-10-21  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/58794
        * fold-const.c (operand_equal_p): Compare FIELD_DECL operand
        of COMPONENT_REFs with OEP_CONSTANT_ADDRESS_OF left in place.

        * c-c++-common/torture/pr58794-1.c: New testcase.
        * c-c++-common/torture/pr58794-2.c: Likewise.

Index: gcc/fold-const.c
===================================================================
*** gcc/fold-const.c    (revision 203886)
--- gcc/fold-const.c    (working copy)
*************** operand_equal_p (const_tree arg0, const_
*** 2715,2724 ****
        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))
            return 0;
          flags &= ~OEP_CONSTANT_ADDRESS_OF;
!         return OP_SAME (1) && OP_SAME_WITH_NULL (2);
  
        case BIT_FIELD_REF:
          if (!OP_SAME (0))
--- 2715,2725 ----
        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)
!             || !OP_SAME (1))
            return 0;
          flags &= ~OEP_CONSTANT_ADDRESS_OF;
!         return OP_SAME_WITH_NULL (2);
  
        case BIT_FIELD_REF:
          if (!OP_SAME (0))
Index: gcc/testsuite/c-c++-common/torture/pr58794-1.c
===================================================================
*** gcc/testsuite/c-c++-common/torture/pr58794-1.c      (revision 0)
--- gcc/testsuite/c-c++-common/torture/pr58794-1.c      (working copy)
***************
*** 0 ****
--- 1,29 ----
+ /* { dg-do compile } */
+ 
+ struct S0
+ {
+   int f;
+ };
+ 
+ struct S1
+ {
+   struct S0 f1;
+   volatile int f2;
+ };
+ 
+ struct S2
+ {
+   struct S1 g;
+ } a, b; 
+ 
+ static int *c[1][2] = {{0, (int *)&a.g.f2}};
+ static int d; 
+ 
+ int
+ main ()
+ {
+   for (d = 0; d < 1; d++)
+     for (b.g.f1.f = 0; b.g.f1.f < 1; b.g.f1.f++)
+       *c[b.g.f1.f][d + 1] = 0;
+   return 0;
+ }
Index: gcc/testsuite/c-c++-common/torture/pr58794-2.c
===================================================================
*** gcc/testsuite/c-c++-common/torture/pr58794-2.c      (revision 0)
--- gcc/testsuite/c-c++-common/torture/pr58794-2.c      (working copy)
***************
*** 0 ****
--- 1,21 ----
+ /* { dg-do compile } */
+ 
+ struct S 
+ {
+   volatile int f;
+ } a;
+ 
+ unsigned int b;
+ 
+ static int *c[1][2] = {{0, (int *)&a.f}};
+ static unsigned int d;
+ 
+ int 
+ main ()
+ {
+   for (; d < 1; d++)
+     for (; b < 1; b++)
+       *c[b][d + 1] = 0;
+ 
+   return 0;
+ }

Reply via email to