This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR43879
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 30 Apr 2010 10:21:05 +0200 (CEST)
- Subject: [PATCH] Fix PR43879
This fixes some IPA-PTA miscompiles because we were not treating
global initializers properly (ouch). Now we get them correct
(but very non-precise for now).
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
Richard.
2010-04-29 Richard Guenther <rguenther@suse.de>
PR tree-optimization/43879
* tree-ssa-structalias.c (get_constraint_for_1): Properly
handle non-zero initializers.
* gcc.dg/torture/pr43879_1.c: New testcase.
Index: gcc/tree-ssa-structalias.c
===================================================================
*** gcc/tree-ssa-structalias.c (revision 158900)
--- gcc/tree-ssa-structalias.c (working copy)
*************** get_constraint_for_1 (tree t, VEC (ce_s,
*** 3285,3292 ****
&& ((TREE_CODE (t) == INTEGER_CST
&& integer_zerop (t))
/* The only valid CONSTRUCTORs in gimple with pointer typed
! elements are zero-initializer. */
! || TREE_CODE (t) == CONSTRUCTOR))
{
temp.var = nothing_id;
temp.type = ADDRESSOF;
--- 3285,3294 ----
&& ((TREE_CODE (t) == INTEGER_CST
&& integer_zerop (t))
/* The only valid CONSTRUCTORs in gimple with pointer typed
! elements are zero-initializer. But in IPA mode we also
! process global initializers, so verify at least. */
! || (TREE_CODE (t) == CONSTRUCTOR
! && CONSTRUCTOR_NELTS (t) == 0)))
{
temp.var = nothing_id;
temp.type = ADDRESSOF;
Index: gcc/testsuite/gcc.dg/torture/pr43879_1.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr43879_1.c (revision 0)
--- gcc/testsuite/gcc.dg/torture/pr43879_1.c (revision 0)
***************
*** 0 ****
--- 1,27 ----
+ /* { dg-do run } */
+ /* { dg-options "-fipa-pta" } */
+ /* { dg-additional-sources "pr43879_2.c" } */
+
+ void bar(int c)
+ {
+ static int x = 1;
+ if (c != x) __builtin_abort();
+ x--;
+ }
+
+ void baz(int *i)
+ {
+ (*i)--;
+ }
+
+ struct TBL {
+ int (*p)(int *i);
+ };
+ extern struct TBL tbl;
+
+ int main()
+ {
+ int c = 1;
+ return tbl.p(&c);
+ }
+
Index: gcc/testsuite/gcc.dg/torture/pr43879_2.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr43879_2.c (revision 0)
--- gcc/testsuite/gcc.dg/torture/pr43879_2.c (revision 0)
***************
*** 0 ****
--- 1,17 ----
+ struct TBL {
+ int (*p)(int *i);
+ };
+
+ extern void bar(int i);
+ extern void baz(int *i);
+
+ static int foo(int *i)
+ {
+ bar(*i);
+ baz(i);
+ bar(*i);
+ return *i;
+ }
+
+ struct TBL tbl = { foo };
+