This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix PR44555




Sent from my iPhone

On Jun 16, 2010, at 4:40 AM, Richard Guenther <rguenther@suse.de> wrote:


This fixes PR44555 where the C frontend thinks that &a->b evaluates to non-NULL even when b is at offset zero.

How is that wrong? a->b is a deferencing of a even inside an address expression. According to the c (and the c++) standard.





 The
patch simply removes that premature optimization from the
frontend and leaves it to fold where it is properly
implemented (also with the correct targetm.binds_local_p
checks, as opposed to the bogus decl_with_nonnull_addr_p
in c-common.c).

Bootstrap & regtest in progress, ok if that succeeds?

Thanks,
Richard.

2010-06-16 Richard Guenther <rguenther@suse.de>

   PR c/44555
   * c-common.c (c_common_truthvalue_conversion): Remove
   premature and wrong optimization concering ADDR_EXPRs.

* gcc.c-torture/execute/pr44555.c: New testcase.

Index: gcc/c-family/c-common.c
===================================================================
*** gcc/c-family/c-common.c    (revision 160826)
--- gcc/c-family/c-common.c    (working copy)
*************** c_common_truthvalue_conversion (location
*** 3825,3847 ****
             inner);
         return truthvalue_true_node;
       }
!
!    /* If we still have a decl, it is possible for its address to
!       be NULL, so we cannot optimize.  */
!    if (DECL_P (inner))
!      {
!        gcc_assert (DECL_WEAK (inner));
!        break;
!      }
!
!    if (TREE_SIDE_EFFECTS (inner))
!      {
!        expr = build2 (COMPOUND_EXPR, truthvalue_type_node,
!               inner, truthvalue_true_node);
!        goto ret;
!      }
!    else
!      return truthvalue_true_node;
       }

     case COMPLEX_EXPR:
--- 3825,3831 ----
             inner);
         return truthvalue_true_node;
       }
!    break;
       }

     case COMPLEX_EXPR:
Index: gcc/testsuite/gcc.c-torture/execute/pr44555.c
===================================================================
*** gcc/testsuite/gcc.c-torture/execute/pr44555.c    (revision 0)
--- gcc/testsuite/gcc.c-torture/execute/pr44555.c    (revision 0)
***************
*** 0 ****
--- 1,16 ----
+ struct a {
+     char b[100];
+ };
+ int foo(struct a *a)
+ {
+   if (&a->b)
+     return 1;
+   return 0;
+ }
+ extern void abort (void);
+ int main()
+ {
+   if (foo((struct a *)0) != 0)
+     abort ();
+   return 0;
+ }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]