From a4d2f61639a0cfc4514870c6f196ba5028af16a8 Mon Sep 17 00:00:00 2001 From: rguenth Date: Tue, 9 Feb 2010 16:11:34 +0000 Subject: [PATCH] 2010-02-09 Richard Guenther PR tree-optimization/43008 * tree-ssa-structalias.c (handle_lhs_call): Pass in the fndecl, make HEAP variables initialized from global memory if they are not known builtin functions. (find_func_aliases): Adjust. * gcc.c-torture/execute/pr43008.c: New testcase. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@156628 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.c-torture/execute/pr43008.c | 23 +++++++++++++++++++++++ gcc/tree-ssa-structalias.c | 10 ++++++++-- 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr43008.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 73e2be6..47608b1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,13 @@ 2010-02-09 Richard Guenther + PR tree-optimization/43008 + * tree-ssa-structalias.c (handle_lhs_call): Pass in the fndecl, + make HEAP variables initialized from global memory if they + are not known builtin functions. + (find_func_aliases): Adjust. + +2010-02-09 Richard Guenther + PR tree-optimization/43000 * tree-vrp.c (vrp_int_const_binop): Only handle unsigned arithmetic manually. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bbc21ec..9c162e2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2010-02-09 Richard Guenther + PR tree-optimization/43008 + * gcc.c-torture/execute/pr43008.c: New testcase. + +2010-02-09 Richard Guenther + PR tree-optimization/43000 * gcc.dg/torture/pr43000.c: New testcase. * gcc.dg/torture/pr43002.c: Likewise. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr43008.c b/gcc/testsuite/gcc.c-torture/execute/pr43008.c new file mode 100644 index 0000000..428f4ae --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr43008.c @@ -0,0 +1,23 @@ +int i; +struct X { + int *p; +}; +struct X * __attribute__((malloc)) +my_alloc (void) +{ + struct X *p = __builtin_malloc (sizeof (struct X)); + p->p = &i; + return p; +} +extern void abort (void); +int main() +{ + struct X *p, *q; + p = my_alloc (); + q = my_alloc (); + *(p->p) = 1; + *(q->p) = 0; + if (*(p->p) != 0) + abort (); + return 0; +} diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c index 3db2874..5138e72 100644 --- a/gcc/tree-ssa-structalias.c +++ b/gcc/tree-ssa-structalias.c @@ -3482,7 +3482,7 @@ handle_rhs_call (gimple stmt, VEC(ce_s, heap) **results) the LHS point to global and escaped variables. */ static void -handle_lhs_call (tree lhs, int flags, VEC(ce_s, heap) *rhsc) +handle_lhs_call (tree lhs, int flags, VEC(ce_s, heap) *rhsc, tree fndecl) { VEC(ce_s, heap) *lhsc = NULL; @@ -3496,6 +3496,12 @@ handle_lhs_call (tree lhs, int flags, VEC(ce_s, heap) *rhsc) it escapes. */ DECL_EXTERNAL (vi->decl) = 0; vi->is_global_var = 0; + /* If this is not a real malloc call assume the memory was + initialized and thus may point to global memory. All + builtin functions with the malloc attribute behave in a sane way. */ + if (!fndecl + || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL) + make_constraint_from (vi, nonlocal_id); } else if (VEC_length (ce_s, rhsc) > 0) { @@ -3798,7 +3804,7 @@ find_func_aliases (gimple origt) handle_rhs_call (t, &rhsc); if (gimple_call_lhs (t) && could_have_pointers (gimple_call_lhs (t))) - handle_lhs_call (gimple_call_lhs (t), flags, rhsc); + handle_lhs_call (gimple_call_lhs (t), flags, rhsc, fndecl); VEC_free (ce_s, heap, rhsc); } else -- 2.7.4