Dear All, This patch is verging on obvious. The PR was originally, incorrectly blocking PR87477 and the testcase has remained in my 'associate' directory. I thought that it is time to get shot of it!
Is there a better way to detect a type(c_ptr) formal argument? Subject to advice on the question, OK for trunk? Paul
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 45a984b6bdb..0823efd5abc 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -7353,6 +7353,8 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, need the length. */ if (parmse.string_length != NULL_TREE && !sym->attr.is_bind_c + && !(fsym && fsym->ts.type == BT_DERIVED + && !strcmp (fsym->ts.u.derived->name, "c_ptr")) && !(fsym && UNLIMITED_POLY (fsym))) vec_safe_push (stringargs, parmse.string_length);
Change.Logs
Description: Binary data
! { dg-do run } ! ! Contributed by Jeffrey Hill <jeffrey.p.h...@nasa.gov> ! module associate_ptr use iso_c_binding contains subroutine c_f_strpointer(cptr, ptr2) type(c_ptr), target, intent(in) :: cptr character(kind=c_char,len=4), pointer :: ptr1 character(kind=c_char,len=:), pointer, intent(out) :: ptr2 call c_f_pointer(cptr, ptr1) if (ptr1 .ne. 'abcd') stop 1 ptr2 => ptr1 ! Failed here end subroutine end module program test_associate_ptr use associate_ptr character(kind=c_char, len=1), target :: char_array(7) character(kind=c_char,len=:), pointer :: ptr2 char_array = ['a', 'b', 'c', 'd', c_null_char, 'e', 'f'] ! The first argument was providing a constant hidden string length => segfault call c_f_strpointer(c_loc(char_array), ptr2) if (ptr2 .ne. 'abcd') stop 2 end program