From c11384aa75f6c6f78f1ea2c700ebd8a83b16106b Mon Sep 17 00:00:00 2001 From: Janus Weil Date: Mon, 28 Aug 2017 20:46:28 +0200 Subject: [PATCH] re PR fortran/81770 (Bogus warning: Pointer in pointer assignment might outlive the pointer target) 2017-08-28 Janus Weil PR fortran/81770 * expr.c (gfc_check_pointer_assign): Improve the check whether pointer may outlive pointer target. 2017-08-28 Janus Weil PR fortran/81770 * gfortran.dg/warn_target_lifetime_3.f90: Fix a typo. * gfortran.dg/warn_target_lifetime_4.f90: New testcase. From-SVN: r251390 --- gcc/fortran/ChangeLog | 6 ++++ gcc/fortran/expr.c | 3 +- gcc/testsuite/ChangeLog | 6 ++++ .../gfortran.dg/warn_target_lifetime_3.f90 | 2 +- .../gfortran.dg/warn_target_lifetime_4.f90 | 28 +++++++++++++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/warn_target_lifetime_4.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 61f4a20b5fb..56a0ed94b11 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2017-08-28 Janus Weil + + PR fortran/81770 + * expr.c (gfc_check_pointer_assign): Improve the check whether pointer + may outlive pointer target. + 2017-08-27 Thomas Koenig PR fortran/81974 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 64af02cc29b..5a101a8e343 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -3806,7 +3806,8 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue) if (warn_target_lifetime && rvalue->expr_type == EXPR_VARIABLE && !rvalue->symtree->n.sym->attr.save - && !attr.pointer && !rvalue->symtree->n.sym->attr.host_assoc + && !rvalue->symtree->n.sym->attr.pointer && !attr.pointer + && !rvalue->symtree->n.sym->attr.host_assoc && !rvalue->symtree->n.sym->attr.in_common && !rvalue->symtree->n.sym->attr.use_assoc && !rvalue->symtree->n.sym->attr.dummy) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 01b801feba1..cfe90904f6d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2017-08-28 Janus Weil + + PR fortran/81770 + * gfortran.dg/warn_target_lifetime_3.f90: Fix a typo. + * gfortran.dg/warn_target_lifetime_4.f90: New testcase. + 2017-08-28 Steve Ellcey * gfortran.dg/dec_init_1.f90 (dummy): Use ichar in print statement. diff --git a/gcc/testsuite/gfortran.dg/warn_target_lifetime_3.f90 b/gcc/testsuite/gfortran.dg/warn_target_lifetime_3.f90 index 6c8ea5b9458..0ef1e2d19c7 100644 --- a/gcc/testsuite/gfortran.dg/warn_target_lifetime_3.f90 +++ b/gcc/testsuite/gfortran.dg/warn_target_lifetime_3.f90 @@ -3,7 +3,7 @@ ! ! PR fortran/55476 ! -! Contribued by Janus Weil +! Contributed by Janus Weil ! subroutine test integer, pointer :: p diff --git a/gcc/testsuite/gfortran.dg/warn_target_lifetime_4.f90 b/gcc/testsuite/gfortran.dg/warn_target_lifetime_4.f90 new file mode 100644 index 00000000000..d2972a92283 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/warn_target_lifetime_4.f90 @@ -0,0 +1,28 @@ +! { dg-do compile } +! { dg-options "-Wtarget-lifetime" } +! +! PR fortran/81770: [5/6/7 Regression] Bogus warning: Pointer in pointer assignment might outlive the pointer target +! +! Contributed by Janus Weil + +module m + + type t + integer, allocatable :: l + end type + +contains + + subroutine sub(c_in, list) + type(t), target, intent(in) :: c_in + integer, pointer, intent(out) :: list + + type(t), pointer :: container + + container => c_in + + list => container%l + + end subroutine + +end -- 2.30.2