This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran] PR55476 - fix bogus "Pointer might outlive the pointer target"


The problem is that the symbol gets the host-associated flag as soon as it is host associated even in the host's namespace. Solution: Test additionally whether they have been declared in the same namespace.

(I wonder whether there is a case where the host-association is attr is set and the namespace is different but the pointer won't outlive the target. I tried to create such a test case in the PR â and failed. I think it is not possible BLOCK or a module variable; and as there is only a single level of nesting, I think the attached patch is correct.)

Bootstrapped and regtested on x86-64-gnu-linux.
OK for the trunk?

Tobias

PS: Pending patches on my side - I have no overview about other patches:
- This patch ;-)
- show_locus out-of-bounds fix, http://gcc.gnu.org/ml/fortran/2012-11/msg00084.html
- I/O leakage with iostat=, http://gcc.gnu.org/ml/fortran/2012-11/msg00083.html
- FINAL wrapper, http://gcc.gnu.org/ml/fortran/2012-11/msg00086.html
2012-11-27  Tobias Burnus  <burnus@net-b.de>

	PR fortran/55476
	* expr.c (gfc_check_pointer_assign): Fix check
	pointer-might-outlive-target check for host_assoc.

2012-11-27  Tobias Burnus  <burnus@net-b.de>

	PR fortran/55476
	* gfortran.dg/warn_target_lifetime_3.f90: New.

diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 211f304..15570af 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -3693,7 +3693,9 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue)
       warn = lvalue->symtree->n.sym->attr.dummy
 	     || lvalue->symtree->n.sym->attr.result
 	     || lvalue->symtree->n.sym->attr.function
-	     || lvalue->symtree->n.sym->attr.host_assoc
+	     || (lvalue->symtree->n.sym->attr.host_assoc
+		 && lvalue->symtree->n.sym->ns
+		    != rvalue->symtree->n.sym->ns)
 	     || lvalue->symtree->n.sym->attr.use_assoc
 	     || lvalue->symtree->n.sym->attr.in_common;

diff --git a/gcc/testsuite/gfortran.dg/warn_target_lifetime_3.f90 b/gcc/testsuite/gfortran.dg/warn_target_lifetime_3.f90
new file mode 100644
index 0000000..3ea4f7a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/warn_target_lifetime_3.f90
@@ -0,0 +1,29 @@
+! { dg-do compile }
+! { dg-options "-Wall" }
+!
+! PR fortran/55476
+!
+! Contribued by  Janus Weil
+!
+subroutine test
+  integer, pointer :: p
+  integer, target :: t
+  p => t
+contains
+  subroutine sub()
+    if (p /= 0) return
+  end subroutine
+end subroutine
+
+module m
+  integer, pointer :: p2
+contains
+  subroutine test
+    integer, target :: t2
+    p2 => t2 ! { dg-warning "Pointer at .1. in pointer assignment might outlive the pointer target" }
+  contains
+    subroutine sub()
+      if (p2 /= 0) return
+    end subroutine
+  end subroutine
+end module m

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]