re PR fortran/81770 (Bogus warning: Pointer in pointer assignment might outlive the...
authorJanus Weil <janus@gcc.gnu.org>
Mon, 28 Aug 2017 18:46:28 +0000 (20:46 +0200)
committerJanus Weil <janus@gcc.gnu.org>
Mon, 28 Aug 2017 18:46:28 +0000 (20:46 +0200)
2017-08-28  Janus Weil  <janus@gcc.gnu.org>

PR fortran/81770
* expr.c (gfc_check_pointer_assign): Improve the check whether pointer
may outlive pointer target.

2017-08-28  Janus Weil  <janus@gcc.gnu.org>

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
gcc/fortran/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/warn_target_lifetime_3.f90
gcc/testsuite/gfortran.dg/warn_target_lifetime_4.f90 [new file with mode: 0644]

index 61f4a20b5fb930726c877b35ba1b7b4a5b23cdbd..56a0ed94b1122e3e96b8f9a2c5b7ca846c7193c1 100644 (file)
@@ -1,3 +1,9 @@
+2017-08-28  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/81770
+       * expr.c (gfc_check_pointer_assign): Improve the check whether pointer
+       may outlive pointer target.
+
 2017-08-27  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/81974
index 64af02cc29b9e1b630468a7d4e12cf2b8a0c350b..5a101a8e3431802075b9b530dd78cb2c0bfe87e7 100644 (file)
@@ -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)
index 01b801feba1250b5e641fe471f6d754f26cc1b20..cfe90904f6d649e00b3c521243bb3cdc65ec16ae 100644 (file)
@@ -1,3 +1,9 @@
+2017-08-28  Janus Weil  <janus@gcc.gnu.org>
+
+       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  <sellcey@cavium.com>
 
        * gfortran.dg/dec_init_1.f90 (dummy): Use ichar in print statement.
index 6c8ea5b945834126a88b46704b2f3729ad6c1869..0ef1e2d19c7db754c8fcf446c90632951133de0c 100644 (file)
@@ -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 (file)
index 0000000..d2972a9
--- /dev/null
@@ -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 <janus@gcc.gnu.org>
+
+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