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;
+ }