diff options
author | Paul Thomas <pault@gcc.gnu.org> | 2023-06-21 17:01:57 +0100 |
---|---|---|
committer | Paul Thomas <pault@gcc.gnu.org> | 2023-06-21 17:01:57 +0100 |
commit | caf0892eea67349d9a1e44590c3440768136fe2b (patch) | |
tree | 94d32781ab5a52199427ae95ecbe1fe0a63c5515 /gcc/testsuite | |
parent | b9401c3a323c59705eca177bf72c13c0d2f462b6 (diff) | |
download | gcc-caf0892eea67349d9a1e44590c3440768136fe2b.zip gcc-caf0892eea67349d9a1e44590c3440768136fe2b.tar.gz gcc-caf0892eea67349d9a1e44590c3440768136fe2b.tar.bz2 |
Fortran: Seg fault passing string to type cptr dummy [PR108961].
2023-06-21 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/108961
* trans-expr.cc (gfc_conv_procedure_call): The hidden string
length must not be passed to a formal arg of type(cptr).
gcc/testsuite/
PR fortran/108961
* gfortran.dg/pr108961.f90: New test.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/gfortran.dg/pr108961.f90 | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/gcc/testsuite/gfortran.dg/pr108961.f90 b/gcc/testsuite/gfortran.dg/pr108961.f90 new file mode 100644 index 0000000..3e6c9df --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr108961.f90 @@ -0,0 +1,26 @@ +! { dg-do run } +! +! Contributed by Jeffrey Hill <jeffrey.p.hill@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 |