From 8bb76364adb500f539b7bbd329b83e4602bf839b Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 16 Sep 2009 16:12:18 +0000 Subject: [PATCH] PR fortran/41212 * tree.h (struct tree_decl_common): Add decl_restricted_flag, shorten decl_common_unused. (DECL_RESTRICTED_P): New accessor. * tree-ssa-alias.c (ptr_deref_may_alias_decl_p): Use it to disambiguate marked decls and restrict pointers. fortran/ * trans.h (struct lang_type): Remove nontarget_type member. * trans.c (gfc_add_modify): Don't access it. * trans-decl.c (gfc_finish_var_decl): Don't allocate and set it, instead set DECL_RESTRICTED_P on affected decls. testsuite/ * gfortran.dg/pr41212.f90: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@151761 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 9 +++++++ gcc/fortran/ChangeLog | 8 +++++++ gcc/fortran/trans-decl.c | 22 ++--------------- gcc/fortran/trans.c | 7 ------ gcc/fortran/trans.h | 1 - gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gfortran.dg/pr41212.f90 | 34 +++++++++++++++++++++++++++ gcc/tree-ssa-alias.c | 8 +++++++ gcc/tree.h | 13 +++++++++- 9 files changed, 78 insertions(+), 29 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr41212.f90 diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 706f3e26de94..eaff6d9e7522 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2009-09-16 Michael Matz + + PR fortran/41212 + * tree.h (struct tree_decl_common): Add decl_restricted_flag, + shorten decl_common_unused. + (DECL_RESTRICTED_P): New accessor. + * tree-ssa-alias.c (ptr_deref_may_alias_decl_p): Use it + to disambiguate marked decls and restrict pointers. + 2009-09-16 Richard Henderson PR middle-end/41360 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index b8586c2c0bc2..9c9744b140e3 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,11 @@ +2009-09-16 Michael Matz + + PR fortran/41212 + * trans.h (struct lang_type): Remove nontarget_type member. + * trans.c (gfc_add_modify): Don't access it. + * trans-decl.c (gfc_finish_var_decl): Don't allocate and set it, + instead set DECL_RESTRICTED_P on affected decls. + 2009-09-14 Richard Henderson * f95-lang.c (gfc_init_builtin_functions): Update call to diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 6a4c3e45cc98..4e72a23bd5c9 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -581,26 +581,8 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym) if (!sym->attr.target && !sym->attr.pointer - && !sym->attr.proc_pointer - /* For now, don't bother with aggregate types. We would need - to adjust DECL_CONTEXT of all field decls. */ - && !AGGREGATE_TYPE_P (TREE_TYPE (decl))) - { - tree type = TREE_TYPE (decl); - if (!TYPE_LANG_SPECIFIC (type)) - TYPE_LANG_SPECIFIC (type) = (struct lang_type *) - ggc_alloc_cleared (sizeof (struct lang_type)); - if (!TYPE_LANG_SPECIFIC (type)->nontarget_type) - { - alias_set_type set = new_alias_set (); - type = build_distinct_type_copy (type); - TYPE_ALIAS_SET (type) = set; - TYPE_LANG_SPECIFIC (type)->nontarget_type = type; - } - else - type = TYPE_LANG_SPECIFIC (type)->nontarget_type; - TREE_TYPE (decl) = type; - } + && !sym->attr.proc_pointer) + DECL_RESTRICTED_P (decl) = 1; } diff --git a/gcc/fortran/trans.c b/gcc/fortran/trans.c index f4a215aeeaf2..136987a74885 100644 --- a/gcc/fortran/trans.c +++ b/gcc/fortran/trans.c @@ -162,13 +162,6 @@ gfc_add_modify (stmtblock_t * pblock, tree lhs, tree rhs) tree t1, t2; t1 = TREE_TYPE (rhs); t2 = TREE_TYPE (lhs); - /* ??? This is actually backwards, we should test the "base" type - from which the nontarget_type was copied, but we don't have this - backlink. This will do for now, it's for checking anyway. */ - if (TYPE_LANG_SPECIFIC (t1)) - t1 = TYPE_LANG_SPECIFIC (t1)->nontarget_type; - if (TYPE_LANG_SPECIFIC (t2)) - t2 = TYPE_LANG_SPECIFIC (t2)->nontarget_type; /* Make sure that the types of the rhs and the lhs are the same for scalar assignments. We should probably have something similar for aggregates, but right now removing that check just diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h index 643f28b37f4f..4469023499de 100644 --- a/gcc/fortran/trans.h +++ b/gcc/fortran/trans.h @@ -629,7 +629,6 @@ struct GTY(()) lang_type { tree dataptr_type; tree span; tree base_decl[2]; - tree nontarget_type; }; struct GTY(()) lang_decl { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e02dbf90d18a..5730da14617d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-09-16 Michael Matz + + PR fortran/41212 + * gfortran.dg/pr41212.f90: New test. + 2009-09-16 Eric Botcazou * gnat.dg/alignment9.adb: New test. diff --git a/gcc/testsuite/gfortran.dg/pr41212.f90 b/gcc/testsuite/gfortran.dg/pr41212.f90 new file mode 100644 index 000000000000..4bdae6dad282 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr41212.f90 @@ -0,0 +1,34 @@ +! { dg-do run } +! { dg-options "-O2" } +program m + double precision :: y,z + call b(1.0d0,y,z) + if (ABS (z - 1.213) > 0.1) call abort +contains + subroutine b( x, y, z) + implicit none + double precision :: x,y,z + integer :: i, k + double precision :: h, r + + y = 1.0d0 + z = 0.0d0 + + h = 0 + DO k = 1,10 + h = h + 1.0d0/k + + r = 1 + DO i = 1,k + r = (x/(2*i) ) * r + END DO + + y = y + (-1)**k * r + z = z + (-1)**(k+1) * h * r + + IF ( ABS(2*k/x*r) < 1d-6 ) EXIT + END DO + + z = 2*y + end subroutine b +end program m diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index 9522b28c5484..e619190386c2 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -208,6 +208,14 @@ ptr_deref_may_alias_decl_p (tree ptr, tree decl) if (!pi) return true; + /* If the decl can be used as a restrict tag and we have a restrict + pointer and that pointers points-to set doesn't contain this decl + then they can't alias. */ + if (DECL_RESTRICTED_P (decl) + && TYPE_RESTRICT (TREE_TYPE (ptr)) + && pi->pt.vars_contains_restrict) + return bitmap_bit_p (pi->pt.vars, DECL_UID (decl)); + return pt_solution_includes (&pi->pt, decl); } diff --git a/gcc/tree.h b/gcc/tree.h index 70650489dd9c..09ce8fa125c0 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -1306,6 +1306,15 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int, (TREE_CHECK3 (NODE, VAR_DECL, PARM_DECL, \ RESULT_DECL)->decl_common.decl_by_reference_flag) +/* In a RESULT_DECL, PARM_DECL and VAR_DECL, means that this decl + can be used as restricted tag to disambiguate against other restrict + pointers. Used by fortran to capture something like non-addressability + (which it isn't really because the middle-end does take addresses of + such variables). */ +#define DECL_RESTRICTED_P(NODE) \ + (TREE_CHECK3 (NODE, VAR_DECL, PARM_DECL, \ + RESULT_DECL)->decl_common.decl_restricted_flag) + /* In a CALL_EXPR, means that the call is the jump from a thunk to the thunked-to function. */ #define CALL_FROM_THUNK_P(NODE) (CALL_EXPR_CHECK (NODE)->base.protected_flag) @@ -2646,8 +2655,10 @@ struct GTY(()) tree_decl_common { unsigned gimple_reg_flag : 1; /* In VAR_DECL, PARM_DECL and RESULT_DECL, this is DECL_BY_REFERENCE. */ unsigned decl_by_reference_flag : 1; + /* In VAR_DECL, PARM_DECL and RESULT_DECL, this is DECL_RESTRICTED_P. */ + unsigned decl_restricted_flag : 1; /* Padding so that 'off_align' can be on a 32-bit boundary. */ - unsigned decl_common_unused : 4; + unsigned decl_common_unused : 3; /* DECL_OFFSET_ALIGN, used only for FIELD_DECLs. */ unsigned int off_align : 8; -- 2.47.2