From 8d231ff273dc0d9d4937be8cd0c5ee53a000cf7a Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Sun, 5 Jun 2011 23:11:46 +0200 Subject: [PATCH] re PR fortran/49255 (-fcheck=pointer diagnoses too much: Passing NULL pointer to OPTIONAL argument) 2011-06-05 Tobias Burnus PR fortran/49255 * trans-expr.c (gfc_conv_procedure_call): Fix -fcheck=pointer for F2008. 2011-06-05 Tobias Burnus PR fortran/49255 * gfortran.dg/pointer_check_9.f90: New. * gfortran.dg/pointer_check_10.f90: New. From-SVN: r174663 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/trans-expr.c | 6 ++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gfortran.dg/pointer_check_10.f90 | 16 ++++++++++++++++ gcc/testsuite/gfortran.dg/pointer_check_9.f90 | 15 +++++++++++++++ 5 files changed, 49 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pointer_check_10.f90 create mode 100644 gcc/testsuite/gfortran.dg/pointer_check_9.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 34acfed9e95..af16e578341 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2011-06-05 Tobias Burnus + + PR fortran/49255 + * trans-expr.c (gfc_conv_procedure_call): Fix -fcheck=pointer + for F2008. + 2011-06-05 Andreas Schmidt Thomas Koenig diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index bfe966f3f95..da4af1ae28d 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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7fdb2ae2a1d..99732725421 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2011-06-05 Tobias Burnus + + PR fortran/49255 + * trans-expr.c (gfc_conv_procedure_call): Fix -fcheck=pointer + for F2008. + 2011-06-05 Nicola Pero PR testsuite/49287 diff --git a/gcc/testsuite/gfortran.dg/pointer_check_10.f90 b/gcc/testsuite/gfortran.dg/pointer_check_10.f90 new file mode 100644 index 00000000000..642f0a08b21 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pointer_check_10.f90 @@ -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 diff --git a/gcc/testsuite/gfortran.dg/pointer_check_9.f90 b/gcc/testsuite/gfortran.dg/pointer_check_9.f90 new file mode 100644 index 00000000000..d42ba64d78b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pointer_check_9.f90 @@ -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 -- 2.30.2