From a2b471e494bf3942e35336227a846e332232d88c Mon Sep 17 00:00:00 2001 From: Seth Johnson Date: Sun, 25 Mar 2018 11:30:24 +0000 Subject: [PATCH] re PR fortran/84924 (Erroneous error in C_F_POINTER) 2018-03-25 Seth Johnson Dominique d'Humieres PR fortran/84924 * check.c (gfc_check_c_f_pointer): Allow scalar noninteroperable scalar derived type with -std=f2003 and -std=f2008. 2018-03-25 Seth Johnson Dominique d'Humieres PR fortran/84924 * gfortran.dg/scalar_pointer_1.f90: New test. Co-Authored-By: Dominique d'Humieres From-SVN: r258843 --- gcc/fortran/ChangeLog | 7 ++++ gcc/fortran/check.c | 2 +- gcc/testsuite/ChangeLog | 6 ++++ .../gfortran.dg/scalar_pointer_1.f90 | 36 +++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/scalar_pointer_1.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index f21f7c77469..4d93c55fe50 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2018-03-25 Seth Johnson + Dominique d'Humieres + + PR fortran/84924 + * check.c (gfc_check_c_f_pointer): Allow scalar noninteroperable + scalar derived type with -std=f2003 and -std=f2008. + 2018-03-24 Jerry DeLisle Dominique d'Humieres diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c index 23b1964c39b..83bd004eaac 100644 --- a/gcc/fortran/check.c +++ b/gcc/fortran/check.c @@ -4749,7 +4749,7 @@ gfc_check_c_f_pointer (gfc_expr *cptr, gfc_expr *fptr, gfc_expr *shape) return false; } - if (!is_c_interoperable (fptr, &msg, false, true)) + if (fptr->rank > 0 && !is_c_interoperable (fptr, &msg, false, true)) return gfc_notify_std (GFC_STD_F2008_TS, "Noninteroperable array FPTR " "at %L to C_F_POINTER: %s", &fptr->where, msg); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 004c44c6bc0..8b462a5e9eb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-03-25 Seth Johnson + Dominique d'Humieres + + PR fortran/84924 + * gfortran.dg/scalar_pointer_1.f90: New test. + 2018-03-25 Tom de Vries * gcc.dg/tree-ssa/vrp104.c: Make scan-tree-dump-times pattern more diff --git a/gcc/testsuite/gfortran.dg/scalar_pointer_1.f90 b/gcc/testsuite/gfortran.dg/scalar_pointer_1.f90 new file mode 100644 index 00000000000..d421f388458 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/scalar_pointer_1.f90 @@ -0,0 +1,36 @@ +! { dg-do compile } +! { dg-options "-std=f2003" } +! PR fortran/84924 +! Testcase contributed by Seth Johnson +! +module ftest + use ISO_C_BINDING + implicit none + + type :: Cls + end type + + type :: ClsHandle + class(Cls), pointer :: ptr + end type +contains + subroutine to_ptr(c, p) + use ISO_C_BINDING + class(Cls), intent(in), target :: c + type(C_PTR), intent(out) :: p + type(ClsHandle), pointer :: handle + allocate(handle) + handle%ptr => c + p = c_loc(handle) + end subroutine + + subroutine from_ptr(p, c) + use ISO_C_BINDING + type(C_PTR), intent(in) :: p + class(Cls), intent(out), pointer :: c + type(ClsHandle), pointer :: handle + call c_f_pointer(cptr=p, fptr=handle) + c => handle%ptr + deallocate(handle) + end subroutine +end module -- 2.30.2