public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran] PR55476 - fix bogus "Pointer might outlive the pointer target"
@ 2012-11-27 20:06 Tobias Burnus
  2012-11-27 21:31 ` Janus Weil
  0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2012-11-27 20:06 UTC (permalink / raw)
  To: gcc patches, gfortran

[-- Attachment #1: Type: text/plain, Size: 971 bytes --]

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

[-- Attachment #2: pointer-life-warning-fix.diff --]
[-- Type: text/x-patch, Size: 1745 bytes --]

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Patch, Fortran] PR55476 - fix bogus "Pointer might outlive the pointer target"
  2012-11-27 20:06 [Patch, Fortran] PR55476 - fix bogus "Pointer might outlive the pointer target" Tobias Burnus
@ 2012-11-27 21:31 ` Janus Weil
  0 siblings, 0 replies; 2+ messages in thread
From: Janus Weil @ 2012-11-27 21:31 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc patches, gfortran

2012/11/27 Tobias Burnus <burnus@net-b.de>:
> 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?

Yes, looks good. Thanks for the patch!

Cheers,
Janus

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-11-27 21:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-27 20:06 [Patch, Fortran] PR55476 - fix bogus "Pointer might outlive the pointer target" Tobias Burnus
2012-11-27 21:31 ` Janus Weil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).