Patchwork [Fortran] Fix -fcheck=pointer for F2008's NULL ptr to optional arguments

login
register
mail settings
Submitter Tobias Burnus
Date June 1, 2011, 7:21 p.m.
Message ID <4DE6913A.5050809@net-b.de>
Download mbox | patch
Permalink /patch/98246/
State New
Headers show

Comments

Tobias Burnus - June 1, 2011, 7:21 p.m.
The NULL pointer check (-fcheck=pointer) was wrong for Fortran 2008: It 
is now allowed to pass a null pointer (or not associated allocatables) 
to optional arguments to denote absent arguments.

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

Tobias
Tobias Burnus - June 5, 2011, 7:57 p.m.
*ping*

On 1 June 2011, Tobias Burnus wrote:
> The NULL pointer check (-fcheck=pointer) was wrong for Fortran 2008: 
> It is now allowed to pass a null pointer (or not associated 
> allocatables) to optional arguments to denote absent arguments.
>
> Build and regtested on x86-64-linux.
> OK for the trunk?
>
> Tobias
Thomas Koenig - June 5, 2011, 8:40 p.m.
Hi Tobias,

> The NULL pointer check (-fcheck=pointer) was wrong for Fortran 2008: It
> is now allowed to pass a null pointer (or not associated allocatables)
> to optional arguments to denote absent arguments.
>
> Build and regtested on x86-64-linux.
> OK for the trunk?

OK.  Thanks for the patch!

	Thomas

Patch

2011-06-01  Tobias Burnus  <burnus@net-b.de>

	PR fortran/49255
	* trans-expr.c (gfc_conv_procedure_call): Fix -fcheck=pointer
	for F2008.

2011-06-01  Tobias Burnus  <burnus@net-b.de>

	PR fortran/49255
	* gfortran.dg/pointer_check_9.f90: New.
	* gfortran.dg/pointer_check_10.f90: New.

diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index bfe966f..da4af1a 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -3269,6 +3269,12 @@  gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
 	  else
 	    goto end_pointer_check;
 
+	  /*  In Fortran 2008 it's allowed to pass a NULL pointer/nonallocated
+	      allocatable to an optional dummy, cf. 12.5.2.12.  */
+	  if (fsym != NULL && fsym->attr.optional && !attr.proc_pointer
+	      && (gfc_option.allow_std & GFC_STD_F2008) != 0)
+	    goto end_pointer_check;
+
           if (attr.optional)
 	    {
               /* If the actual argument is an optional pointer/allocatable and
--- /dev/null	2011-05-31 07:23:47.047892583 +0200
+++ gcc/gcc/testsuite/gfortran.dg/pointer_check_9.f90	2011-06-01 20:18:52.000000000 +0200
@@ -0,0 +1,15 @@ 
+! { dg-do run }
+! { dg-options "-fcheck=all -std=f2008 -fall-intrinsics" }
+!
+! PR fortran/49255
+!
+! Valid F2008, invalid F95/F2003.
+!
+integer,pointer :: ptr => null()
+call foo (ptr)
+contains
+  subroutine foo (x)
+    integer, optional :: x
+    if (present (x)) call abort ()
+  end subroutine foo
+end
--- /dev/null	2011-05-31 07:23:47.047892583 +0200
+++ gcc/gcc/testsuite/gfortran.dg/pointer_check_10.f90	2011-06-01 20:19:05.000000000 +0200
@@ -0,0 +1,16 @@ 
+! { dg-do run }
+! { dg-options "-fcheck=all -std=f2003 -fall-intrinsics" }
+! { dg-shouldfail "Pointer actual argument 'ptr' is not associated" }
+!
+! PR fortran/49255
+!
+! Valid F2008, invalid F95/F2003.
+!
+integer,pointer :: ptr => null()
+call foo (ptr)
+contains
+  subroutine foo (x)
+    integer, optional :: x
+    if (present (x)) call abort ()
+  end subroutine foo
+end